MPMC Unit 2
MPMC Unit 2
8086 PROGRAMMING
The first step in the development process is to write an assembly language program. The
assembly language program can be written with an ordinary text editor such as word star, edit
and so on. The assembly language program text is an input to the assembler.
The assembler translates assembly language statements to their binary equivalents, usually
known as object code. Time required to translate assembly code to object code is called
Assemble Time. During assembling process assembler checks for syntax errors and displays
them before giving object code module.
The object code module contains the information about where the program or module to be
loaded in memory. If the object code module is to be linked with other separately assembled
modules then it contains additional linkage information. At link time, separately assembled
modules are combined into one single load module, by the linker.
The linker also adds any required initialization or finalization code to allow the operating system
to start the program running and to return control to the operating system after the program has
completed.
Most linkers allow assembly language modules to be linked with object code modules compiled
from high-level languages as well. This allows the programmer to insert a time-critical assembly
language routines, library modules into a program.
At load time, the program loader copies the program into the computer’s main memory, and at
execution time, program execution begins
These instructions are used to transfer the data from the source operand to the destination operand.
Following are the list of instructions under this group −
MOV − Used to copy the byte or word from the provided source to the provided destination.
PPUSH − Used to put a word at the top of the stack.
POP − Used to get a word from the top of the stack to the provided location.
PUSHA − Used to put all the registers into the stack.
POPA − Used to get words from the stack to all registers.
XCHG − Used to exchange the data from two locations.
XLAT − Used to translate a byte in AL using a table in the memory.
Instructions for input and output port transfer
IN − Used to read a byte or word from the provided port to the accumulator.
OUT − Used to send out a byte or word from the accumulator to the provided port.
LEA − Used to load the address of operand into the provided register.
LDS − Used to load DS register and other provided register from the memory
LES − Used to load ES register and other provided register from the memory.
LAHF − Used to load AH with the low byte of the flag register.
SAHF − Used to store AH register to low byte of the flag register.
PUSHF − Used to copy the flag register at the top of the stack.
POPF − Used to copy a word at the top of the stack to the flag register.
Arithmetic Instructions
These instructions are used to perform arithmetic operations like addition, subtraction, multiplication,
division, etc.
Following is the list of instructions under this group −
DIV − Used to divide the unsigned word by byte or unsigned double word by word.
IDIV − Used to divide the signed word by byte or signed double word by word.
AAD − Used to adjust ASCII codes after division.
CBW − Used to fill the upper byte of the word with the copies of sign bit of the lower byte.
CWD − Used to fill the upper word of the double word with the sign bit of the lower word.
These instructions are used to perform operations where data bits are involved, i.e. operations like
logical, shift, etc.
Following is the list of instructions under this group −
SHL/SAL − Used to shift bits of a byte/word towards left and put zero(S) in LSBs.
SHR − Used to shift bits of a byte/word towards the right and put zero(S) in MSBs.
SAR − Used to shift bits of a byte/word towards the right and copy the old MSB into the new
MSB.
ROL − Used to rotate bits of byte/word towards the left, i.e. MSB to LSB and to Carry Flag
[CF].
ROR − Used to rotate bits of byte/word towards the right, i.e. LSB to MSB and to Carry Flag
[CF].
RCR − Used to rotate bits of byte/word towards the right, i.e. LSB to CF and CF to MSB.
RCL − Used to rotate bits of byte/word towards the left, i.e. MSB to CF and CF to LSB.
String Instructions
String is a group of bytes/words and their memory is always allocated in a sequential order.
Following is the list of instructions under this group −
REP − Used to repeat the given instruction till CX ≠ 0.
REPE/REPZ − Used to repeat the given instruction until CX = 0 or zero flag ZF = 1.
REPNE/REPNZ − Used to repeat the given instruction until CX = 0 or zero flag ZF = 1.
MOVS/MOVSB/MOVSW − Used to move the byte/word from one string to another.
COMS/COMPSB/COMPSW − Used to compare two string bytes/words.
INS/INSB/INSW − Used as an input string/byte/word from the I/O port to the provided memory
location.
OUTS/OUTSB/OUTSW − Used as an output string/byte/word from the provided memory
location to the I/O port.
SCAS/SCASB/SCASW − Used to scan a string and compare its byte with a byte in AL or string
word with a word in AX.
LODS/LODSB/LODSW − Used to store the string byte into AL or string word into AX.
These instructions are used to transfer/branch the instructions during an execution. It includes the
following instructions −
Instructions to transfer the instruction during an execution without any condition −
CALL − Used to call a procedure and save their return address to the stack.
RET − Used to return from the procedure to the main program.
JMP − Used to jump to the provided address to proceed to the next instruction.
Instructions to transfer the instruction during an execution with some conditions −
JA/JNBE − Used to jump if above/not below/equal instruction satisfies.
JAE/JNB − Used to jump if above/not below instruction satisfies.
JBE/JNA − Used to jump if below/equal/ not above instruction satisfies.
JC − Used to jump if carry flag CF = 1
JE/JZ − Used to jump if equal/zero flag ZF = 1
JG/JNLE − Used to jump if greater/not less than/equal instruction satisfies.
JGE/JNL − Used to jump if greater than/equal/not less than instruction satisfies.
JL/JNGE − Used to jump if less than/not greater than/equal instruction satisfies.
JLE/JNG − Used to jump if less than/equal/if not greater than instruction satisfies.
JNC − Used to jump if no carry flag (CF = 0)
JNE/JNZ − Used to jump if not equal/zero flag ZF = 0
JNO − Used to jump if no overflow flag OF = 0
JNP/JPO − Used to jump if not parity/parity odd PF = 0
JNS − Used to jump if not sign SF = 0
JO − Used to jump if overflow flag OF = 1
JP/JPE − Used to jump if parity/parity even PF = 1
JS − Used to jump if sign flag SF = 1
These instructions are used to control the processor action by setting/resetting the flag values.
Following are the instructions under this group −
STC − Used to set carry flag CF to 1
CLC − Used to clear/reset carry flag CF to 0
CMC − Used to put complement at the state of carry flag CF.
STD − Used to set the direction flag DF to 1
CLD − Used to clear/reset the direction flag DF to 0
STI − Used to set the interrupt enable flag to 1, i.e., enable INTR input.
CLI − Used to clear the interrupt enable flag to 0, i.e., disable INTR input.
These instructions are used to execute the given instructions for number of times. Following is the list of
instructions under this group −
LOOP − Used to loop a group of instructions until the condition satisfies, i.e., CX = 0
LOOPE/LOOPZ − Used to loop a group of instructions till it satisfies ZF = 1 & CX = 0
LOOPNE/LOOPNZ − Used to loop a group of instructions till it satisfies ZF = 0 & CX = 0
JCXZ − Used to jump to the provided address if CX = 0
Interrupt Instructions
These instructions are used to call the interrupt during program execution.
INT − Used to interrupt the program during execution and calling service specified.
INTO − Used to interrupt the program during execution if OF = 1
IRET − Used to return from interrupt service to the main program
The addressing mode in which the data operand is a part of the instruction itself is known
as immediate addressing mode.
Example
MOV CX, 4929 H, ADD AX, 2387 H, MOV AL, FFH
Register addressing mode
It means that the register is the source of an operand for an instruction.
Example
MOV CX, AX ; copies the contents of the 16-bit AX register into
; the 16-bit CX register),
ADD BX, AX
The addressing mode in which the effective address of the memory location is written
directly in the instruction.
Example
MOV AX, [1592H], MOV AL, [0300H]
This addressing mode allows data to be addressed at any memory location through an
offset address held in any of the following registers: BP, BX, DI & SI.
Example
MOV AX, [BX] ; Suppose the register BX contains 4895H, then the contents
; 4895H are moved to AX
ADD CX, {BX}
In this addressing mode, the offset address of the operand is given by the sum of contents
of the BX/BP registers and 8-bit/16-bit displacement.
Example
MOV DX, [BX+04], ADD CL, [BX+08]
Indexed addressing mode
In this addressing mode, the operands offset address is found by adding the contents of
SI or DI register and 8-bit/16-bit displacements.
Example
MOV BX, [SI+16], ADD AL, [DI+16]
In this addressing mode, the offset address of the operand is computed by summing the
base register to the contents of an Index register.
Example
ADD CX, [AX+SI], MOV AX, [AX+DI]
In this addressing mode, the operands offset is computed by adding the base register
contents. An Index registers contents and 8 or 16-bit displacement.
Example –
Algorithm –
1. Assign value 500 in SI and 600 in DI
2. Move the contents of [SI] in BL and increment SI by 1
3. Move the contents of [SI] and [SI + 1] in AX
4. Use DIV instruction to divide AX by BL
5. Move the contents of AX in [DI].
6. Halt the program.
Stack operation Stack Segment Stack Pointer (SP), Base Pointer (BP)
Program –
1. Editor
- An editor is a program which allows you to create a file containing the assembly language
statements for your program.
Example: PC-Write, Wordstar.
- As you type in your program, the editor stores the ASCII codes for the letters and numbers in
successive RAM locations.
- When you have typed in all your program, you then save the file on the hard disk. This file is
called source file and the extension is .asm.
2. Assembler
- An assembler program is used to translate the assembly language mnemonics for instructions to
corresponding binary codes. When you run the assembler, it reads the source file of your
program from the disk where you have saved it after editing.
- On the first pass through the source program, the assembler determines the displacement of
named data items, the offset of labels, etc. and puts this information in a symbol table.
- On the second pass through the source program, the assembler produces the binary code for
each instruction and inserts the offsets, etc. that it calculated during the first pass.
- The assembler generates 2 files on the floppy disk or hard disk. The first file is called object file
(.obj).
- The second file generated by assembler is called the assembler list file and is given extension
(.lst).
3. Linker
- A linker is a program used to join several object files into one large object file.
- The linker produces a link file which contains the binary codes for all the combined modules.
The linker also produces a link map file which contains the address information about the linked
files (.exe).
4. Locator
- A locator is a program used to assign the specific address of where the segments of object code
are to be loaded into memory.
- A locator program called EXE2BIN comes with the IBM PC Disk Operating System (DOS).
EXE2BIN converts a .exe file to a .bin file which has physical addresses.
5. Debugger
- A debugger is a program which allows you to load your object code program into system
memory, execute the program and troubleshoot or debug it.
- The debugger allows you to look at the contents of registers and memory locations after your
program runs.
- It allows you to change the contents of registers and memory locations and re-run the program.
- Some debuggers allow you to stop execution after each instruction so that you can check or
alter after each register contents.
- A debugger also allows you to set a breakpoint at any point in your program. If you insert a
breakpoint at any point in your program, the debugger will run the program up to the instruction
where you put the breakpoint and then stop the execution.
6. Emulator
- It is used to test and debug the hardware and software of an external system, such as the
prototype of a microprocessor based instrument. Part of the hardware of an emulator is a
multiwire cable which connects the host system to the system being developed.