Programming With 8086
Programming With 8086
The MOV instruction is used to transfer data from one register to another.
Example:
MOV AX, BX ; Move data from BX to AX
Example:
MOV AX, [5000h] ; Move data from memory address
5000h into AX
MOV [6000h], AX ; Move data from AX into memory
address 6000h
Example:
MOV AX, [5000h] ; Load data from address
5000h into AX
MOV [6000h], AX ; Store data from AX into
address 6000h
1’s complement subtraction can be done by inverting the bits and adding
1.
Example:
MOV AX, 0001h ; Load AX with 1
NOT AX ; Invert the bits (1's
complement)
ADD AX, 1 ; Add 1 to complete the
subtraction
Example:
MOV CX, n ; Set CX as the counter for 'n'
numbers
MOV AX, 0 ; Initialize AX to 0
(accumulator)
LOOP_ADD:
ADD AX, [SI] ; Add number at memory address
SI to AX
INC SI ; Increment SI to point to the
next number
LOOP LOOP_ADD ; Repeat the loop for 'n'
times
4.5 Write Simple Assembly Language Programs Using
Logical Instructions
i) To Perform AND/OR/XOR Operations on Two 8/16 Bit Numbers
Example:
MOV AL, 0Ah ; Load AL with binary number
(1010)
XOR AL, 0Ah ; Convert to Gray Code by
XORing with the next bit
Example of a subroutine:
MAIN:
CALL FACTORIAL
; Continue execution here
FACTORIAL:
; Subroutine to calculate factorial
RET
FACTORIAL:
MOV BX, AX ; Copy number to BX
DEC AX ; Decrement number
MUL BX ; Multiply AX by BX (AX = AX *
BX)
RET
-o0o-