KEMBAR78
Nasm Lab Manual | PDF | Assembly Language | Computer Engineering
0% found this document useful (0 votes)
122 views45 pages

Nasm Lab Manual

Num=5, 3, 1, 8 For (i=0; i<3; i++) { For (i=0; i<3; i++) { Num= 1, 3, 5, 8 }}  Solution: [org 0x100] push bp mov bp, sp mov si, 0 ; i mov di, 0 ; j outer: push si inner: push di mov al, [num+di] mov bl, [num+di+1] cmp al, bl jg swap inc di cmp di, 3 jl inner pop di

Uploaded by

Toheed Sheikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views45 pages

Nasm Lab Manual

Num=5, 3, 1, 8 For (i=0; i<3; i++) { For (i=0; i<3; i++) { Num= 1, 3, 5, 8 }}  Solution: [org 0x100] push bp mov bp, sp mov si, 0 ; i mov di, 0 ; j outer: push si inner: push di mov al, [num+di] mov bl, [num+di+1] cmp al, bl jg swap inc di cmp di, 3 jl inner pop di

Uploaded by

Toheed Sheikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

ALLAH DOES NOT BURDEN A SOUL BEYOND THAT IT CAN BEAR.

Al-Baqarah, 2:286.

Course: Computer Organisation and Assembly Language


Instructor: Sardar Mehboob Hussain

MS COMSATS Institute of Information Technology


Islamabad, 44000, Pakistan
+923025896689
You can see me at:
• http://www.researcherid.com/rid/F-5984-2017
• http://orcid.org/0000-0003-2084-9880
• https://www.researchgate.net/profile/Sardar_Hussain5
• https://scholar.google.co.uk/citations?hl=en&pli=1&user=oq-
EEOAAAAAJ
You can meet me at:
CS faculty office,
Adjacent Dean office,
CS & IT department, The University of Lahore,
Chenab Campus, Gujrat, Pakistan.
Note: Please schedule an appointment by email before searching me in office.
(Except too necessary).
I may or may not be found in office.
mehboobhussain.sardar@gmail.com
My Thursdays and Fridays are much busy.
Please excuse on said days. (Except too necessary).
Microprocessor And
Assembly Language

LAB MANUAL

BSCS IV

Sardar Mehboob Hussain


Contents
Lab No. 1 ................................................................................................................................................. 2
Introduction to nasm and dosbox software. How to install and run the software. Complete
explanation of nasm. .......................................................................................................................... 2
Lab No. 2 ................................................................................................................................................. 3
Using registers perform addition & subtraction on 2 imidiate values................................................ 3
Lab No. 3 ................................................................................................................................................. 4
Perform if statement and else statement on assembly language. ..................................................... 4
Lab No. 4 ................................................................................................................................................. 6
Extract data from memory and perform arithmetic operation. ......................................................... 6
LAB No. 5 ................................................................................................................................................. 7
Extract data from memory and perform if else operation. ................................................................ 7
LAB No. 6 ................................................................................................................................................. 9
Extract data using for loop and direct address method. .................................................................... 9
LAB No. 7 ............................................................................................................................................... 10
Perform addition using byte operation and for loop. ....................................................................... 10
LAB No. 8 ............................................................................................................................................... 11
Write algorithm of multiplication. (Multiplexing)............................................................................. 11
LAB No. 9 ............................................................................................................................................... 13
Perform arithmetic operation using extended function................................................................... 13
LAB No. 10 ............................................................................................................................................. 16
Using function call perform given operation. ................................................................................... 16
LAB NO. 11 ............................................................................................................................................ 18
Using bubble sorting perform ascending operation. ........................................................................ 18
LAB NO. 12 ............................................................................................................................................ 20
Using stack function perform ascending operation.......................................................................... 20
Lab No. 1
Introduction to nasm and dosbox software. How to install and run the
software. Complete explanation of nasm.

 General syntax for loading a file:

Z:\mount (Space) E (Space) E:\nasm

Z:\ E:

 Making com and list file of a nasm file:

E:\ folder name(Space) file name.asm (Space) –o (Space) file name.com

–l (Space) file name.lst

 Now to run the prog:

Afd (Space) file name.com


Lab No. 2
Using registers perform addition & subtraction on 2 imidiate values.

 General syntax:

For assigning value to register we use command mov.

i.e. mov ax , 5

For addition we use command add.

For subtraction we use command sub.

 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:

we use cmp command for comparison.

Jne command for jump.

i.e. cmp ax,0

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.

 General Syntax for storing value in memory:

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

Mov ax, [A+2]

Mov bx, [A+8]

Mov cx, [A]

Add ax, bx

Add ax, cx

Mov [C], ax

Jne exit

Else:

Mov ax, [A+4]

Mov bx, [A+8]


Mov cx, [A+6]

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:

For(i=0; i<5 ; i++)

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

Mov ax, 0x4c00

Int 0x21

Num: dw 5, 9, 12, 13, 15


LAB No. 7
Perform addition using byte operation and for loop.

 Program:

For(i=0; i<5 ; i++)

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:

A=(50+100+150+800) – (80+60+20) + (200+12)

 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

For (i=0; i<3; i++)

For (i=0; i<3; i++)

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

Sardar Mehboob Hussain


Contents
Lab No. 1 ................................................................................................................................................. 2
Introduction to nasm and dosbox software. How to install and run the software. Complete
explanation of nasm. .......................................................................................................................... 2
Lab No. 2 ................................................................................................................................................. 3
Using registers perform addition & subtraction on 2 imidiate values................................................ 3
Lab No. 3 ................................................................................................................................................. 4
Perform if statement and else statement on assembly language. ..................................................... 4
Lab No. 4 ................................................................................................................................................. 6
Extract data from memory and perform arithmetic operation. ......................................................... 6
LAB No. 5 ................................................................................................................................................. 7
Extract data from memory and perform if else operation. ................................................................ 7
LAB No. 6 ................................................................................................................................................. 9
Extract data using for loop and direct address method. .................................................................... 9
LAB No. 7 ............................................................................................................................................... 10
Perform addition using byte operation and for loop. ....................................................................... 10
LAB No. 8 ............................................................................................................................................... 11
Write algorithm of multiplication. (Multiplexing)............................................................................. 11
LAB No. 9 ............................................................................................................................................... 13
Perform arithmetic operation using extended function................................................................... 13
LAB No. 10 ............................................................................................................................................. 16
Using function call perform given operation. ................................................................................... 16
LAB NO. 11 ............................................................................................................................................ 18
Using bubble sorting perform ascending operation. ........................................................................ 18
LAB NO. 12 ............................................................................................................................................ 20
Using stack function perform ascending operation.......................................................................... 20
Lab No. 1
Introduction to nasm and dosbox software. How to install and run the
software. Complete explanation of nasm.

 General syntax for loading a file:

Z:\mount (Space) E (Space) E:\nasm

Z:\ E:

 Making com and list file of a nasm file:

E:\ folder name(Space) file name.asm (Space) –o (Space) file name.com

–l (Space) file name.lst

 Now to run the prog:

Afd (Space) file name.com


Lab No. 2
Using registers perform addition & subtraction on 2 imidiate values.

 General syntax:

For assigning value to register we use command mov.

i.e. mov ax , 5

For addition we use command add.

For subtraction we use command sub.

 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:

we use cmp command for comparison.

Jne command for jump.

i.e. cmp ax,0

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.

 General Syntax for storing value in memory:

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

Mov ax, [A+2]

Mov bx, [A+8]

Mov cx, [A]

Add ax, bx

Add ax, cx

Mov [C], ax

Jne exit

Else:

Mov ax, [A+4]

Mov bx, [A+8]


Mov cx, [A+6]

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:

For(i=0; i<5 ; i++)

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

Mov ax, 0x4c00

Int 0x21

Num: dw 5, 9, 12, 13, 15


LAB No. 7
Perform addition using byte operation and for loop.

 Program:

For(i=0; i<5 ; i++)

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:

A=(50+100+150+800) – (80+60+20) + (200+12)

 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

For (i=0; i<3; i++)

For (i=0; i<3; i++)

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

You might also like