Professional Documents
Culture Documents
1498952227-Mpi Unit 2
1498952227-Mpi Unit 2
UNIT 2
MSB 1 0 1 0 0 1 0 1 LSB
0 1 0 0 1 0 1 1
MSB 1 0 1 0 0 1 0 1 LSB
1 1 0 1 0 0 1 0
Rotate 1
CF
1 New carry 0 1 0 1 1 0 0 1
Rotate 2
CF
New carry
0 1 0 1 1 0 0 1 1
1 0 1 0 1 1 0 0 1
New carry CF
1 1 0 1 0 1 1 0 0
1 1 0 1 0 1 1 0 0
0 1 0 1 1 0 0 0
1 0 1 0 1 1 0 0 0
0 1 0 1 0 1 1 0
MSB 1
1 0 1 0 0 0 1 1
1 1 0 1 0 0 0 1
Sign bit
CMPS/CMPSB/CMPSW
● This instruction can be used to compare a byte / word in one string with a
byte / word in another string.
● SI is used to hold the offset of the byte or word in the source string, and DI is
used to hold the offset of the byte or word in the destination string.
● After the comparison, SI and DI will automatically be incremented or
decremented to point to the next or previous element in the two strings.
● The CMPS instruction can be used with a REPE or REPNE prefix to compare
all the elements of a string.
REP/REPE/REPZ/REPNE/REPNZ prefix
REP – A prefix written before string instructions
REP CX!=0
STOS/STOSB/STOSW
To store/copy a byte/word from accumulator to a memory location in the extra
segment [ES]. DI s used to hold the offset memory of ES
“CALL address”
Ex: CALL 1234 – The MP control will be moved to the address 1234 and all
statements in that procedure are executed.
● Here first conditions will be evaluated, If the condition is TRUE the MP control
will be shifted from one place of program to another place of program.
● The condition of flags are checked.
This instruction is usually used after a Compare instruction. If the zero flag is 0,
then this instruction will cause a jump to the label given in the instruction.
Ex:
IN AL, 0F8H Read data value from port
CMP AL, 72 Compare (AL –72)
JNE NEXT Jump to label NEXT if AL != 72
This instruction will cause a jump to the specified destination address if the
sign flag is set. Since a 1 in the sign flag indicates a negative signed number,
you can think of this instruction as saying “jump if negative”.
Ex:
ADD DL, DH Add signed byte in DH to signed byte in DL
JS NEXT Jump to label NEXT if result of addition is
negative number
This instruction will cause a jump to the specified destination address if the
sign flag is 0. Since a 0 in the sign flag indicate a positive signed number, you
can think to this instruction as saying “jump if positive”.
Ex:
DEC AL Decrement AL
JNS NEXT Jump to label NEXT if AL has not decremented to FFH
If the number of 1’s left in the lower 8 bits of a data word after an instruction
which affects the parity flag is even, then the parity flag will be set. If the parity
flag is set, the JP / JPE instruction will cause a jump to the specified
destination address.
Ex:
IN AL, 0F8H Read ASCII character from Port F8H
OR AL, AL Set flags
JPE ERROR Odd parity expected, send error message if
parity found even
If the number of 1’s left in the lower 8 bits of a data word after an instruction
which affects the parity flag is odd, then the parity flag is 0. The JNP / JPO
instruction will cause a jump to the specified destination address, if the parity
flag is 0.
Ex:
IN AL, 0F8H Read ASCII character from Port F8H
OR AL, AL Set flags
JPO ERROR Even parity expected, send error message if
parity found odd
Ex:
ADD AL, BL Add signed bytes in AL and BL
JO ERROR Jump to label ERROR if overflow from add
LOOP:
● Used to loop a group of instructions until the condition satisfies i.e. CX = 0
● The number of times the instruction to be repeated is loaded into CX.
● Each time the loop instruction executes, CX is automatically decremented by 1.
LOOPE/ LOOPZ
Used to loop a group of instructions till it satisfies ZF=1 and CX=0 i.e. exit when CX=0
LOOPNE/ LOOPNZ
Used to loop a group of instructions till it satisfies ZF=0 and CX=0 i.e. exit when CX=0
JCXZ
Used to jump to provided address when CX=0
ESC
● It is an instruction prefix.
● It indicates the current instruction escape to external device like NDP (numeric
data coprocessor) – for 8087
● 8086 treats the instruction as NOP
WAIT
● Holds operation of processor with current status till TEST pin goes low
● It is used to synchronize 8086 with other peripherals.
HLT
● Cause the processor to stop fetching and executing instructions.
● 8086 comes out of halt state if it finds INTR or NMI=1 or by reset.
LOCK
● This is a bus lock instruction prefix. LOCK=0 activates the signal to ensure
concurrency.
Ex: LOCK IN AL, 08H
This instruction is locked where it prevents any external bus master taking control of the
system bus during execution of this instruction.
Prepared by M.V.Bhuvaneswari, Asst.Prof, CSE, MVGRA
External Hardware Synchronization Instructions
CLC [Clear Carry Instruction]: Used to reset the carry flag i.e. CF=0
CMC [Complement Carry Instruction]: Used to complement the carry flag i.e.
CF=0 1 or CF=1 0
STD [Set Direction Instruction]: Set DF=1 so that SI/DI can be decremented automatically after execution
of string instruction.
CLD [Clear Direction Instruction]: Reset DF=0 so that SI/DI can be incremented automatically after
execution of string instruction.
STI [Set Interrupt flag]: If STI is set the INTR will be enabled. MP receives it when IF=1
CLI [Clear interrupt]: MP will not respond to any interrupt when IF=0 on its INTR input.
Prepared by M.V.Bhuvaneswari, Asst.Prof, CSE, MVGRA
Interrupt Instructions
Sources of Interrupts:
● External signal – peripheral devices interrupt main program of MP
● Special Instruction – special instruction INT to execute special program
● Condition produced by instruction – interrupted by some condition by
execution of some instruction.
Ex: DIV by 0 instruction
NMI
● It is a single pin non maskable hardware interrupt which cannot be disabled (always on).
● It is highest priority interrupt and is of type 2.
● Address of NMI processing routine is stored in location 0008h.
INTR
● Provides a single request and is activated by I/O port.
● This can be masked or delayed
● Interrupt flag is used to set this type.
opcode
Immediate value
INT 20H
Type * 4 = 20*4 = 80H
Pointer to IP and CS of the ISR is 0000H : 0080H
Interrupt Priority
NMI
INTR
Type 3 Interrupt
Break point interrupt
Type 2 Interrupt
Nonmaskable interrupt
Type 1 Interrupt
Single step interrupt
Type 0 Interrupt
Divide Error
Prepared by M.V.Bhuvaneswari, Asst.Prof, CSE, MVGRA
Assembler Directives
● The assembler directives are the special instructions used to indicate the
assembler how a program is to be assembled and executed in a proper way.
● assembler directives are the commands or instructions that control the
operation of the assembler.
● Assembler directives are the instructions provided to the assembler, not the
processor as the processor has nothing to do with these instructions. These
instructions are also known as pseudo-instructions or pseudo-opcode.
ALIGN
● This directive aligns next variable or instruction
● If the value has to be changed, all that has to change the EQU statement and reassemble the
program.
ORG [originate]
● This directive directs the assembler to start memory allotment for a particular segment, block
or code from the declared address.
“ORG expression”
NUMBER 10H
20H
30H
PUBLIC
● This directive is used to tell the assembler that a specified name or label will
be accessed from other modules
Ex: PUBLIC XXX It makes XXX available for other modules
TABLE 10H
“NAME Data-type Num DUP (value)”
10H
Ex: TABLE DB 5 DUP (10H)
Reserves an array of 5bytes of memory location
10H
with the value 0
10H
10H
Ex: MOV AL, BYTE PTR [SI] Moves content of memory location addressed by SI
(8 bit ) to AL
EVEN
● It is used to inform the assembler to align the data beginning from an even address.
The above statement directs the loader/linker to prepare an EXE file such that CODE, DATA
and STACK segments must lie within a 64K byte memory segment that is named as
PROGRAM
Prepared by M.V.Bhuvaneswari, Asst.Prof, CSE, MVGRA
Steps Involved in Programming
● Specifying the problem: The first step in the programming is to find out which
task is to be performed. This is called specifying the problem.
● Designing the problem solution: The exact step-by-step process that is to be
followed (program logic)is developed and written down.
● Coding: Once the program is specified and designed it can be implemented. It
tells the processor the exact step by step process in its language.
Programmer has to chose appropriate instructions from the instruction set to
build the program.
● Debugging: Once coding is done next step is to debug the program. It tests
the code to see if the task is done or not. If program is not working properly
debugging process helps to find and correct the errors.
Assembler
Loader
Memory
Prepared by M.V.Bhuvaneswari, Asst.Prof, CSE, MVGRA
Assembler:
An Assembler is a program that translates the source file assembly language into
machine language [Binary or object code].
The Assembler generates two files
Object file
It contains the binary codes for the instruction and data. “.obj file”
Assembler list file
It contains the assembly language statements, the binary code for each instruction and
the offset for each instruction. “.asm file”
Assemblers are:
1) MASM – Microsoft macro assembler
2) TASM – Turbo assembler
Types
1) Linkage Editor
2) Dynamic Linker
It loads the executable files into memory and then the program is executed.
Types
1) Relocating loader
2) Absolute loader
3) Bootstrap loader
4) Direct linking loader
● Operators are Arithmetic (+, -, *, /) and Logical Operators (AND, OR, NOT
XOR)
Prepared by M.V.Bhuvaneswari, Asst.Prof, CSE, MVGRA
Assembly Language Instruction