Professional Documents
Culture Documents
Logic Operations
Branching Instructions
Arithmetic Instructions
Other Instructions
Procedures
8086 Assembly Programming
Logic Operations
AND, OR, XOR, NOT, SHIFT
OR Destination, Source
BL
MOV BL, 35H ; 00110101
00111111
OR BL, 0FH ; 00001111
SF=0 , ZF= 0 , PF=1 ,
; check for zero operand CF= 0 , OF=0
OR AL, AL ; or
OR AL, 0
; set certain bits of an operand AL
MOV AL, 3AH ; 00111010 00111111
OR AL, 00000101b
8086 Assembly Programming
Logic Operations
AND, OR, XOR, NOT, SHIFT
NOT dest
0 MSB LSB CF
MOV AL, 10101100b
SHR AL, 1
CF MSB LSB 0
MOV CL, 3
SHR AL, CL
8086 Assembly Programming
Branching Instructions
JMP, LOOP, JNZ/JNE, JZ/JE
Example:
XOR AX, AX
L1: INC AX
JMP L1
MOV BX, 20 ; unreachable instruction
8086 Assembly Programming
Branching Instructions
JMP, JNZ/JNE, JZ/JE, LOOP
.DATA
Num DD 0
.CODE
MOV AX, WORD PTR Num[0]
MOV DX, WORD PTR Num[2]
8086 Assembly Programming
Other Instructions
XCHG, PTR, EQU, DUP
EQU (=) can be used to define constants that can’t be changed
during execution. No memory location is allocated!
.data
count equ 30 ; count = 30
.code
-----
mov cx, count
-----
mov ax, count
end
8086 Assembly Programming
Other Instructions
XCHG, PTR, EQU, DUP
DUP used to allocate memory locations with specific value
.data
Num db 10 dup(0)
.code
Mov [Num], 3
Mov [Num+1], 5
mov al,[num+1]
end
8086 Assembly Programming
Procedures
PROC, ENDP, CALL
.MODEL SMALL
Name PROC .DATA
---- MSG DB 'Hello world!',13,10, '$'
---- .CODE
.STARTUP
RET CALL Print_MSG
Name ENDP CALL Print_MSG
MOV AH, 4CH
INT 21H
Print_MSG PROC
MOV DX,OFFSET MSG
MOV AH,9
INT 21H
RET
Print_MSG ENDP
END
8086 Assembly Programming
Procedures
PROC, ENDP, CALL
.MODEL SMALL
Passing parameters to procedures: .DATA
In registers SUM DB ?
In memory .CODE
In stack .STARTUP
MOV AL,5
MOV BL,3
CALL ADD_NUMBERS
MOV AH, 4CH
INT 21H
ADD_NUMBERS PROC
ADD AL, BL
MOV SUM, AL
RET
ADD_NUMBERS ENDP
END
8086 Assembly Programming
Procedures
8086 Assembly Programming
Lab Assignments
Write a program that adds numbers from 1 to 100.
Write a program that print the char ‘*’ 100 times.
Write a procedure that add 2 numbers passed to it by
registers and use it in your main code.
Write 3 programs that print the following 3 patterns.
* * ********************* *********************
* * * * ******************
* * * * ***************
* * * ************
********************* *********
*******
****
**
*