Micro-Processor and Assembly Language: Lab Assignment#7
Micro-Processor and Assembly Language: Lab Assignment#7
Micro-Processor and Assembly Language: Lab Assignment#7
Lab Assignment#7
Task 1:
Write an assembly program for 8086 Microprocessor which adds 2 32-bit numbers and stores result in
memory starting with offset address 0001H up to 0005H.
Introduction:
The task is devised into storing 32-bit numbers in memory accessing them through assembly variables
and adding them alongside of carry.
Code
org 100h
.model small
.data
op1 dd 12345678h
ans dd ?
.code
mov ds, ax
mov dh, 2
jbe l4
int 21H
jnz l2
dec dh
cmp dh, 0
jnz l1
int 21h
ret
Screenshot
Conclusion
Using carry bits, we can add number of bits
Task 2:
Write an assembly program for 8086 Microprocessor which sorts three 8-bit numbers stored in AL,BL
and CL. Place largest number in AH middle number in BH and smallest in CH register.
Introduction
The program us very straight forward it used cmp (compare statement) and jmp (jump) to compare
numbers and perform required series of actions:
Code
start:
cmp bh, ah
jge notLess
jmp bhGreat
notLess:
cmp ch, bh
jge AllRight
jmp chGreat
bhGreat:
mov bl, ah
mov al, bh
mov ah, al
mov bh, bl
cmp ch, bh
jge AllRight
jmp chGreat:
AllRight:
mov al, ah
mov cl, ch
mov bl, bh
ret
chGreat:
mov bl, ch
mov cl, bh
mov bl, bh
mov bl, ch
jmp AllRight
Screenshot
Conclusion
A deeper understanding of algorithms is required to perform this task how control is shifted through jmp
(jump statements).
Task 3
Write an assembly program for 8086 Microprocessor which calculates Square of 8-bit number stored in
AL if number is ODD and Cube if number is even.
Introduction
Code
DATA SEGMENT
NO DB 2
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE
MOV AX,0000
MOV AL,BL
MUL BL
MOV CX,AX
MUL BL
MOV BX,AX
RET
SQUARE ENDP
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV BL,NO
CALL SQUARE
MOV BL,00H
MOV AH,4CH
INT 21H
CODE ENDS
END START
Ret
Screenshot
Conclusion
You can take square or cube of any number by simple multiplication.