Chapter 3 List of Program Code - Corrected
Chapter 3 List of Program Code - Corrected
Lecture 4
EXAMPLE1
Write an assembly language program in 8086
microprocessor to find sum of digit of an 8 bit
number.
Assume Data 1 : 12h & Data 2 : 02h;
Storage location: 2000h
Assembply Program
START
MOV AL, 0012 ;load AL register with 0012h
MOV BL, 0002 ;loads BL register with 0002h
ADD AL, BL ; addition
MOV [2000], AL ; store result into Memory
END START
2
EXAMPLE2
Write an assembly language program in 8086
microprocessor to find sum of digit of 8-bits data
at memory locations 2000h and 3000h.
START
Assembply Program
MOV AL, [2000] ;load AL register with data
MOV BL, [3000] ;loads BL register with data
ADD AL, BL ; addition
MOV [2000], AL ; store result into Memory
END START
3
EXAMPLE3
Write an assembly language program to add two
16-bit numbers with carry handling and store the
result.
Assume Data 1 : F7h & Data 2 : DFh;
Algorithm Steps:
Step-1: Input the Number 7Fh
Step-2: Input the Number DFh
Assembply Program
Step-3: Perform Addition
Step-4: Store the result to memory location
Step-5: Jump if CF = 1
Step-6: store the carry value if CF = 1
Step-7: Stop Execution 4
CODE: ADD TWO NUMBER WITH CARRY
START:
MOV AX,F7 ; Load first number
MOV BX,DF ; Load second number
ADD AX, BX ; Perform addition
MOV [0100], AX ; Store the result
JC L1 ; Jump if CF = 1
MOV [0110], 00 ; store NO carry
Assembply Program
HLT ; End of program
L1: MOV [0110], 01 ; store carry
HLT ; End of program
5
EXAMPLE4
Write 8086 ASSEMBLY PROGRAM TO MULTIPLY TWO
16 BIT NUMBERS (Data1=20ACH, Data2=209DH) and
store the result at Memory Location starting from
0100H.
START
MOV AX, 20AC ;load first data
MOV BX, 209D ;load Second data
Assembply Program
MUL BX ; BX*AX = DX:AX
MOV [0100], AX ; store result into Memory location
MOV [0102], DX ; store result into Memory location
END START
6
EXAMPLE5
Write an assembly language program for calculating
the factorial of a number using 8086 microprocessor.
Algorithm Steps:
Step-1: Input the Number whose factorial is to be find and
Store that Number in CX Register
Step-2: Insert 0001 in AX(Condition for MUL Instruction) and
Assembply Program
0000 in DX
Step-3: Multiply CX with AX using loop and jump if CX
become Zero
Step-4: Store the result to memory location
Step-5: Stop Execution 7
CODE: FACTORIAL OF GIVEN NUMBER 05H
START
MOV CX, 5 ;load 5H value to CX Register
MOV AX, 0001 ;load AX register with 0001
MOV DX, 0000 ;loads DX register with 0000
L1: MUL CX ;multiply AX & CX and result in DX:AX
DEC CX ;CX = CX-1
JNZ L1
Assembply Program
;run loop between L1 till CX not equal to Zero
MOV [2000], AX ; store result into Memory location
MOV [2001], DX ; store result into Memory location
END START
8
EXAMPLE6
Write 8086 ASSEMBLY PROGRAM TO DIVIDE TWO
16 BIT NUMBERS (Data1=10FCH, Data2=20FBH)
START
MOV AX, 10FC ;load first data
MOV BX, 20FB ;load Second data
DIV BX ; AX/BX = AL, remainder=AH
MOV [0100], AX ; store result into Memory location
Assembply Program
END START
9
EXAMPLE7
Write 8086 ASSEMBLY PROGRAM TO ADD 5 8-
BITS DATAS STORED AT STARTING MEMORY
LOCATION FROM 2000 TO 2004 USING JNZ
START
MOV CL, 05 ;load 5H value AS COUNTER
MOV SI, 2000 ;load ADDRESS AS POINTER
Assembply Program
MOV AX, 0000 ;loads AX register with 0000
L1: ADC AX, [SI] ;add-withCarryfrom memorylocation
DEC CL ;decrement counter
JNZ L1 ;run loop between L1 till CL not Zero
MOV [2001], AX ; store result into Memory location
END START
10