Professional Documents
Culture Documents
MP Unit 1 Part D
MP Unit 1 Part D
MP Unit 1 Part D
IN accumulator, port
The IN instruction reads from an input port into
AL or AX (only these two registers), to be
specified in the instruction
OUT DX, AX
Example 2: MOV 0C8H,AL
out 16h, ax; write to output port at address 16h from reg. ax
out 23h, al; write to output port at address 23h from reg al
The OF, SF, ZF, AF, PF, and CF flags are set according
to the result
The OF, SF, ZF, AF, PF, and CF flags are set
according to the result
The OF, SF, ZF, AF, PF, and CF flags are set
according to the result
3/9/2022 NMAMIT, Nitte 2021-22 34
SBB
Subtract with borrow
The OF, SF, ZF, AF, PF, and CF flags are set
according to the result
CF ZF SF
CX = BX 0 1 0 : Result of subtraction is 0
CX > BX 0 0 0 :No borrow required, so CF = 0
CX < BX 1 0 1 :Subtraction requires borrow, so CF = 1
Operation:
The CF, OF, SF, ZF, AF, and PF flags are set
according to the result
CMP BX, SI
Operation:
IF byte operation
THEN
AX ← AL SRC
ELSE (* word operation *)
DX:AX ← AX SRC
Examples:
MUL BX
MUL WORDPTR [BX + DI]48 H
MUL BYTEPTR [SI]
MUL CL
Example: cwd
DIV BX;
DIV WORDPTR [DI];
DIV CL;
DIV BYTEPTR [SI];
Operation:
DEST ← DEST + 1;
The OF, SF, ZF, AF, and PF flags are set according to the
result
3/9/2022 NMAMIT, Nitte 2021-22 56
Examples
The 8086 allows you to add the ASCII codes for two
decimal digits without masking off the “3” in the upper
nibble of each.
Operation:
DEST ← DEST AND SRC;
Flags Affected:
The OF and CF flags are cleared; the SF, ZF,
and PF flags are set according to the result; The
state of the AF flag is undefined
AND BX, 00FFH: 00FFH Masks upper byte, leaves lower byte
unchanged.
Operation:
DEST ← DEST OR SRC;
Flags Affected:
The OF and CF flags are cleared; the SF, ZF,
and PF flags are set according to the result; The
state of the AF flag is undefined
Operation:
DEST ← DEST XOR SRC;
Flags Affected:
The OF and CF flags are cleared; the SF, ZF,
and PF flags are set according to the result; The
state of the AF flag is undefined
CF MSB LSB 0
For shifts of more than 1 bit position, the desired number of
shifts is loaded into the CL register
Example: MOV CL, 05H
SHL AX, CL
0 MSB LSB CF
Example:
MOV CL, 03H
SHR AL,CL: Shift byte in AL 3 bits right; 0’s in 3 MSBs
CF MSB LSB
Example:
ROR BL, 1: Rotate all bits in BL right 1 bit position LSB to MSB
and to CF
MOV CL,08H :Load CL with number of bit positions to be rotated
ROR WORD PTR [BX], CL Rotate word in DS at offset [BX]
8 bit position right
Examples:
CMP AX, 4371H : Compare by subtracting 4371H from AX
JA NEXT : Jump to label NEXT if AX above 4371H
Examples:
CMP AX, 4371H : Compare (AX – 4371H)
JBE NEXT :Jump to label NEXT if AX is below or equal to 4371H
Examples:
CMP BL, 39H : Compare by subtracting 39H from BL
JG NEXT : Jump to label NEXT if BL more positive than 39H
Example:
CMP BL, 39H : Compare by subtracting 39H from BL
JGE NEXT : Jump to label NEXT if BL more positive than or equal to 39H
Example:
CMP BL, 39H : Compare by subtracting 39H from BL
JL AGAIN : Jump to label AGAIN if BL more negative than 39H
Examples:
CMP BL, 39H : Compare by subtracting 39H from BL
JLE NEXT : Jump to label NEXT if BL more negative than or equal to 39H
Example:
CMP BX, DX : Compare (BX-DX)
JE DONE :Jump to DONE if BX = DX
Example:
IN AL, 0F8H : Read data value from port
CMP AL, 72 : Compare (AL –72)
JNE NEXT : Jump to label NEXT if AL is not 72
Example:
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.
Example:
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
LOOP LABEL
The destination address for the jump must be in the range of –128
bytes to +127 bytes from the address of the instruction after the
LOOPNE / LOOPZ instruction.
data segment
array1 db 10h,20h,30h,40h,50h
len db $-array1
array2 db 5 dup(?)
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov cx, len ; set Counter
lea si, array1
lea di, array2
up: mov al,[si]
mov [di],al
inc si
inc di
loop up ; decrement cx by 1 compare with 0 if false loop up else break
mov ah,4ch ; Terminate the program
int 21h
code ends
end start