Nasm Lab Manual
Nasm Lab Manual
Nasm Lab Manual
Al-Baqarah, 2:286.
LAB MANUAL
BSCS IV
Z:\ E:
General syntax:
i.e. mov ax , 5
Program:
A=5+9
B=9-8
Solution:
[org 0x100]
mov ax ,5
mov bx ,9
add ax ,bx
mov ax ,8
sub bx ,ax
mov ax,0x4c00
int 0x21
Lab No. 3
Perform if statement and else statement on assembly language.
General Syntax:
jne else
Program:
If ( i==0)
A=5+6+7+8+9
Else
B=20-5-6
Solution:
[org 0x100]
mov ax,0
cmp ax,0
jne else
mov ax,5
mov bx,6
mov cx,7
mov dx,8
add ax,bx
add ax,cx
add ax,dx
mov bx,9
add ax,bx
jne exit
else:
mov ax,20
mov bx,5
mov cx,6
sub ax,bx
sub ax,cx
exit:
mov ax,0x4c00
int 0x21
Lab No. 4
Extract data from memory and perform arithmetic operation.
A : dw 5
Program:
A=B+C+D+E
Solution:
[org 0x100]
A : dw 0
B : dw 5
C : dw 6
D : dw 7
E : dw 8
Mov ax ,[B]
Mov bx ,[C]
Mov cx ,[D]
Mov dx ,[E]
Add ax , bx
Add ax , cx
Add ax ,dx
Mov [A] , ax
Mov ax , 0x4c00
Int 0x21
LAB No. 5
Extract data from memory and perform if else operation.
Program:
A=7,9,10,4,3
If ( i==0)
B=9+3+7
Else
C=10-3-4
Solution:
[org 0x100]
Mov ax, 0
Cmp ax, 0
Jne else
Add ax, bx
Add ax, cx
Mov [C], ax
Jne exit
Else:
Sub ax, bx
Sub ax, cx
Mov [B], ax
Exit:
Mov ax,0x4c00
Int 0x21
A: dw 7,9,10,4,3
B: dw 0
C: dw 0
LAB No. 6
Extract data using for loop and direct address method.
Program:
A=5+9+12+13+15
Solution
[org 0x100]
Mov ax, 0
Mov bx, 0
Mov dx, 0
For:
Mov cx,[num+bx]
Add dx, cx
Add bx, 2
Add ax, 1
Cmp ax, 5
Jne for
Int 0x21
Program:
A=4+7+10+13+8
Solution:
[org 0x100]
mov al, 0
mov bl, 0
mov dl, 0
for:
mov dh,[num+bl]
Add dl, dh
Add bl, 1
Add al, 1
cmp al, 5
jne for
mov ax,0x4c00
int 0x21
num: db 4,7,10,13,8
LAB No. 8
Write algorithm of multiplication. (Multiplexing)
Program:
A=4
B=5
Product=A*B
Solution:
[org 0x100]
mov ax,4
mov bx,5
mov cx,0
mov dx,0
mahad:
add cx,1
cmp cx,9
je exit
shr ax,1
jc addition
shl bx,1
jmp mahad
addition:
add dx,bx
shl bx,1
jmp mahad
exit:
int 0x21
mov ax,0x4c00
LAB No. 9
Perform arithmetic operation using extended function.
Program:
Solution:
[org 0x100]
mov ax,[num1]
mov bx,[num1+2]
mov cx,[num1+4]
mov dx,[num1+6]
add ax,cx
adc bx,dx
mov cx,[num1+8]
mov dx,[num1+10]
add ax,cx
adc bx,dx
mov cx,[num1+12]
mov dx,[num1+14]
add ax,cx
adc bx,dx
mov [A],ax
mov [A+2],bx
mov ax,[num2]
mov bx,[num2+2]
mov cx,[num2+4]
mov dx,[num2+6]
add ax,cx
adc bx,dx
mov cx,[num2+8]
mov dx,[num2+10]
add ax,cx
adc bx,dx
mov [B],ax
mov [B+2],bx
mov ax,[num3]
mov bx,[num3+2]
mov cx,[num3+4]
mov dx,[num3+6]
add ax,cx
adc bx,dx
mov cx,[A]
mov dx,[A+2]
add ax,cx
adc bx,dx
mov cx,[B]
mov dx,[B+2]
sub ax,cx
sbb bx,dx
mov [C],ax
mov [C+2],bx
int 0x21
mov ax,0x4c00
num1: dd 50,100,150,800
num2: dd 80,60,20
num3: dd 200,12
A: dd 0
B: dd 0
C: dd 0
LAB No. 10
Using function call perform given operation.
Program:
Addition:
A= 4+7+2+8
Subtraction:
B= 15 -3 -5
Solution:
[org 0x100]
call addition
call subtraction
addition:
mov ax,[A]
mov bx,[A+2]
mov cx,[A+4]
mov dx,[A+6]
add ax,bx
add ax,cx
add ax,dx
RET
subtraction:
mov ax,[B]
mov bx,[B+2]
mov cx,[B+4]
sub ax,bx
sub ax,cx
RET
exit:
int 0x21
mov ax,0x4c00
A: dw 4,7,2,8
B: dw 15,3,5
LAB NO. 11
Using bubble sorting perform ascending operation.
Program:
Num=5, 3, 1, 8
Num= 1, 3, 5, 8
}}
Solution:
[org 0x100]
mov bl,0
mov cl,0
mov dl,0
for:
mov ah,[num+bl]
mov bh,[num+bl+1]
cmp ah,bh
jl swap
add bl,1
add cl,1
cmp cl,3
jne for
mov bl,0
mov dl,1
cmp dl,3
jne for
jmp exit
swap:
mov [num+bl],bh
mov [num+bl+1],ah
add bl,1
add cl,1
jmp for
exit:
int 0x21
mov ax,0x4c00
num: db 5,3,1,8
LAB NO. 12
Using stack function perform ascending operation.
Program:
A= 5, 9, 8, 7, 6
Push:
(A= 5, 6, 7, 8, 9)
Pop:
(A= 9, 8, 7, 6, 5)
A= 5, 6, 7, 8, 9
Solution:
[org 0x100]
call pus
call po
mov [A],ax
mov [A+2],bx
mov [A+4],cx
mov [A+6],dx
mov [A+8],ax
jmp exit
pus:
mov ax,[A]
push ax
mov bx,[A+8]
push bx
mov cx,[A+6]
push cx
mov dx,[A+4]
push dx
mov ax,[A+2]
push ax
ret
po:
pop ax
pop dx
pop cx
pop bx
pop ax
ret
exit:
int 0x21
mov ax,0x4c00
A: dw 5,9,8,7,6
Microprocessor And
Assembly Language
LAB MANUAL
BSCS IV
Z:\ E:
General syntax:
i.e. mov ax , 5
Program:
A=5+9
B=9-8
Solution:
[org 0x100]
mov ax ,5
mov bx ,9
add ax ,bx
mov ax ,8
sub bx ,ax
mov ax,0x4c00
int 0x21
Lab No. 3
Perform if statement and else statement on assembly language.
General Syntax:
jne else
Program:
If ( i==0)
A=5+6+7+8+9
Else
B=20-5-6
Solution:
[org 0x100]
mov ax,0
cmp ax,0
jne else
mov ax,5
mov bx,6
mov cx,7
mov dx,8
add ax,bx
add ax,cx
add ax,dx
mov bx,9
add ax,bx
jne exit
else:
mov ax,20
mov bx,5
mov cx,6
sub ax,bx
sub ax,cx
exit:
mov ax,0x4c00
int 0x21
Lab No. 4
Extract data from memory and perform arithmetic operation.
A : dw 5
Program:
A=B+C+D+E
Solution:
[org 0x100]
A : dw 0
B : dw 5
C : dw 6
D : dw 7
E : dw 8
Mov ax ,[B]
Mov bx ,[C]
Mov cx ,[D]
Mov dx ,[E]
Add ax , bx
Add ax , cx
Add ax ,dx
Mov [A] , ax
Mov ax , 0x4c00
Int 0x21
LAB No. 5
Extract data from memory and perform if else operation.
Program:
A=7,9,10,4,3
If ( i==0)
B=9+3+7
Else
C=10-3-4
Solution:
[org 0x100]
Mov ax, 0
Cmp ax, 0
Jne else
Add ax, bx
Add ax, cx
Mov [C], ax
Jne exit
Else:
Sub ax, bx
Sub ax, cx
Mov [B], ax
Exit:
Mov ax,0x4c00
Int 0x21
A: dw 7,9,10,4,3
B: dw 0
C: dw 0
LAB No. 6
Extract data using for loop and direct address method.
Program:
A=5+9+12+13+15
Solution
[org 0x100]
Mov ax, 0
Mov bx, 0
Mov dx, 0
For:
Mov cx,[num+bx]
Add dx, cx
Add bx, 2
Add ax, 1
Cmp ax, 5
Jne for
Int 0x21
Program:
A=4+7+10+13+8
Solution:
[org 0x100]
mov al, 0
mov bl, 0
mov dl, 0
for:
mov dh,[num+bl]
Add dl, dh
Add bl, 1
Add al, 1
cmp al, 5
jne for
mov ax,0x4c00
int 0x21
num: db 4,7,10,13,8
LAB No. 8
Write algorithm of multiplication. (Multiplexing)
Program:
A=4
B=5
Product=A*B
Solution:
[org 0x100]
mov ax,4
mov bx,5
mov cx,0
mov dx,0
mahad:
add cx,1
cmp cx,9
je exit
shr ax,1
jc addition
shl bx,1
jmp mahad
addition:
add dx,bx
shl bx,1
jmp mahad
exit:
int 0x21
mov ax,0x4c00
LAB No. 9
Perform arithmetic operation using extended function.
Program:
Solution:
[org 0x100]
mov ax,[num1]
mov bx,[num1+2]
mov cx,[num1+4]
mov dx,[num1+6]
add ax,cx
adc bx,dx
mov cx,[num1+8]
mov dx,[num1+10]
add ax,cx
adc bx,dx
mov cx,[num1+12]
mov dx,[num1+14]
add ax,cx
adc bx,dx
mov [A],ax
mov [A+2],bx
mov ax,[num2]
mov bx,[num2+2]
mov cx,[num2+4]
mov dx,[num2+6]
add ax,cx
adc bx,dx
mov cx,[num2+8]
mov dx,[num2+10]
add ax,cx
adc bx,dx
mov [B],ax
mov [B+2],bx
mov ax,[num3]
mov bx,[num3+2]
mov cx,[num3+4]
mov dx,[num3+6]
add ax,cx
adc bx,dx
mov cx,[A]
mov dx,[A+2]
add ax,cx
adc bx,dx
mov cx,[B]
mov dx,[B+2]
sub ax,cx
sbb bx,dx
mov [C],ax
mov [C+2],bx
int 0x21
mov ax,0x4c00
num1: dd 50,100,150,800
num2: dd 80,60,20
num3: dd 200,12
A: dd 0
B: dd 0
C: dd 0
LAB No. 10
Using function call perform given operation.
Program:
Addition:
A= 4+7+2+8
Subtraction:
B= 15 -3 -5
Solution:
[org 0x100]
call addition
call subtraction
addition:
mov ax,[A]
mov bx,[A+2]
mov cx,[A+4]
mov dx,[A+6]
add ax,bx
add ax,cx
add ax,dx
RET
subtraction:
mov ax,[B]
mov bx,[B+2]
mov cx,[B+4]
sub ax,bx
sub ax,cx
RET
exit:
int 0x21
mov ax,0x4c00
A: dw 4,7,2,8
B: dw 15,3,5
LAB NO. 11
Using bubble sorting perform ascending operation.
Program:
Num=5, 3, 1, 8
Num= 1, 3, 5, 8
}}
Solution:
[org 0x100]
mov bl,0
mov cl,0
mov dl,0
for:
mov ah,[num+bl]
mov bh,[num+bl+1]
cmp ah,bh
jl swap
add bl,1
add cl,1
cmp cl,3
jne for
mov bl,0
mov dl,1
cmp dl,3
jne for
jmp exit
swap:
mov [num+bl],bh
mov [num+bl+1],ah
add bl,1
add cl,1
jmp for
exit:
int 0x21
mov ax,0x4c00
num: db 5,3,1,8
LAB NO. 12
Using stack function perform ascending operation.
Program:
A= 5, 9, 8, 7, 6
Push:
(A= 5, 6, 7, 8, 9)
Pop:
(A= 9, 8, 7, 6, 5)
A= 5, 6, 7, 8, 9
Solution:
[org 0x100]
call pus
call po
mov [A],ax
mov [A+2],bx
mov [A+4],cx
mov [A+6],dx
mov [A+8],ax
jmp exit
pus:
mov ax,[A]
push ax
mov bx,[A+8]
push bx
mov cx,[A+6]
push cx
mov dx,[A+4]
push dx
mov ax,[A+2]
push ax
ret
po:
pop ax
pop dx
pop cx
pop bx
pop ax
ret
exit:
int 0x21
mov ax,0x4c00
A: dw 5,9,8,7,6