0% found this document useful (0 votes)
30 views

Microprocessor Lab Practicals

The document describes a menu driven assembly language program that performs basic arithmetic operations like addition, subtraction, multiplication and division on two 64-bit numbers. It displays a menu, accepts the user's choice, calls the corresponding function to perform the operation, and displays the result. The functions implement the arithmetic logic to perform the operations and display the output in hexadecimal format.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Microprocessor Lab Practicals

The document describes a menu driven assembly language program that performs basic arithmetic operations like addition, subtraction, multiplication and division on two 64-bit numbers. It displays a menu, accepts the user's choice, calls the corresponding function to perform the operation, and displays the result. The functions implement the arithmetic logic to perform the operations and display the output in hexadecimal format.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

EXPERIMENT NO :

Program =>

msg1 db 10,13,"Enter 5 64 bit numbers"


len1 equ $-msg1
msg2 db 10,13,"Entered 5 64 bit numbers"
len2 equ $-msg2
section .bss
array resd 200
counter resb 1
section .text
global _start
_start:
;display
mov Rax,1
mov Rdi,1
mov Rsi,msg1
mov Rdx,len1
syscall
;accept
mov byte[counter],05
mov rbx,00
loop1:
mov rax,0 ; 0 for read
mov rdi,0 ; 0 for keyboard
mov rsi, array ;move pointer to start of array
add rsi,rbx
mov rdx,17
syscall
add rbx,17 ;to move counter
dec byte[counter]
JNZ loop1
;display
mov Rax,1
mov Rdi,1
mov Rsi,msg2
mov Rdx,len2
syscall
;display
mov byte[counter],05
mov rbx,00
loop2:
mov rax,1 ;1 for write
mov rdi, 1 ;1 for monitor
mov rsi, array
add rsi,rbx
mov rdx,17 ;16 bit +1 for enter
syscall
add rbx,17
dec byte[counter]
JNZ loop2
;exit system call
mov rax ,60
mov rdi,0
syscall
OUTPUT=>
Enter 5 64 bit numbers
42
18
59
36
53
Enter 5 64 bit numbers
42
18
59
36
53
EXPERIMENT NO 2 :
Program =>

section .data
msg1 db 10,13,"Enter a string:"
len1 equ $-msg1
section .bss
str1 resb 200 ;string declaration
result resb 16
section .text
global _start
_start:
;display
mov Rax,1
mov Rdi,1
mov Rsi,msg1
mov Rdx,len1
syscall
;store string
mov rax,0
mov rdi,0
mov rsi,str1
mov rdx,200
syscall
call display
;exit system call
mov Rax ,60
mov Rdi,0
syscall
%macro dispmsg 2
mov Rax,1
mov Rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
display:
mov rbx,rax ; store no in rbx
mov rdi,result ;point rdi to result variable
mov cx,16 ;load count of rotation in cl
up1:
rol rbx,04 ;rotate no of left by four bits
mov al,bl ; move lower byte in dl
and al,0fh ;get only LSB
cmp al,09h ;compare with 39h
jg add_37 ;if greater than 39h skip add 37
add al,30h
jmp skip ;else add 30
add_37:
add al,37h
skip:
mov [rdi],al ;store ascii code in result variable
inc rdi ; point to next byte
dec cx ; decrement counter
jnz up1 ; if not zero jump to repeat
dispmsg result,16 ;call to macro
ret

OUTPUT=>
Enter a string: I Will Be Back
0000000000000000F
EXPERIMENT NO :
PROGRAM=>

section .data
array db 11h, 55h, 33h, 22h,44h
msg1 db 10,13,"Largest no in an array is:"
len1 equ $-msg1

section .bss
cnt resb 1
result resb 16

section .text
global _start
_start:
mov byte[cnt],5
mov rsi,array
mov al,0
LP: cmp al,[rsi]
jg skip
xchg al ,[rsi]
skip: inc rsi
dec byte[cnt]
jnz LP

;display
mov Rax,1
mov Rdi,1
mov Rsi,msg1
mov Rdx,len1
syscall
;display al
call display
;exit system call
mov Rax ,60
mov Rdi,0
syscall
%macro dispmsg 2
mov Rax,1
mov Rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
display:
mov rbx,rax ; store no in rbx
mov rdi,result ;point rdi to result variable
mov cx,16 ;load count of rotation in cl
up1:
rol rbx,04 ;rotate no of left by four bits
mov al,bl ; move lower byte in dl
and al,0fh ;get only LSB
cmp al,09h ;compare with 39h
jg add_37 ;if greater than 39h skip add 37
add al,30h
jmp skip1 ;else add 30
add_37:
add al,37h
skip1:
mov [rdi],al ;store ascii code in result variable
inc rdi ; point to next byte
dec cx ; decrement counter
jnz up1 ; if not zero jump to repeat
dispmsg result,16 ;call to macro
ret

OUTPUT:
Largest no in an array is:000000000000001C
EXPERIMENT NO :
Program =>
section .data
menumsg db 10,'****** Menu ******',
db 10,'1: Addition'
db 10,'2: Subtraction'
db 10,'3: Multiplication'
db 10,'4: Division'
db 10,10,'Enter your choice:: '

menumsg_len: equ $-menumsg


addmsg db 10,'Welcome to additon',10
addmsg_len equ $-addmsg
submsg db 10,'Welcome to subtraction',10
submsg_len equ $-submsg
mulmsg db 10,'Welcome to Multiplication',10
mulmsg_len equ $-mulmsg
divmsg db 10,'Welcome to Division',10
divmsg_len equ $-divmsg
wrchmsg db 10,10,'You Entered a Wrong Choice....!',10
wrchmsg_len equ $-wrchmsg
no1 dq 08h
no2 dq 02h
nummsg db 10
result dq 0
resmsg db 10,'Result is:'
resmsg_len equ $-resmsg
qmsg db 10,'Quotient::'
qmsg_len equ $-qmsg
rmsg db 10,'Remainder::'
rmsg_len equ $-rmsg
nwmsg db 10
resh dq 0
resl dq 0
section .bss
choice resb 2
dispbuff resb 16
%macro scall 4
mov rax,%1
mov rdi,%2
mov rsi,%3
mov rdx,%4
syscall
%endmacro

section .text
global _start
_start:
up:
scall 1,1,menumsg,menumsg_len
scall 0,0,choice,2
cmp byte [choice],'1'
jne case2
call add_proc
jmp up
case2:
cmp byte [choice],'2'
jne case3
call sub_proc
jmp up
case3:
cmp byte [choice],'3'
jne case4
call mul_proc
jmp up
case4:
cmp byte [choice],'4'
jne caseinv
call div_proc
jmp up
caseinv:
scall 1,1, wrchmsg,wrchmsg_len
exit:
mov eax,01
mov ebx,0
int 80h
add_proc:
mov rax,[no1]
adc rax,[no2]
mov [result],rax
scall 1,1,resmsg,resmsg_len
mov rbx,[result]
call disp64num
scall 1,1,nummsg,1
ret
sub_proc:

mov rax,[no1]
sub rax,[no2]
mov [result],rax
scall 1,1,resmsg,resmsg_len
mov rbx,[result]
call disp64num
scall 1,1,nummsg,1
ret
mul_proc:
scall 1,1,mulmsg,mulmsg_len
mov rax,[no1]
mov rbx,[no2]
mul rbx
mov [resh],rdx
mov [resl],rax
scall 1,1, resmsg,resmsg_len
mov rbx,[resh]
call disp64num
mov rbx,[resl]
call disp64num
scall 1,1,nwmsg,1
ret
div_proc:
scall 1,1,divmsg,divmsg_len
mov rax,[no1]
mov rdx,0
mov rbx,[no2]
div rbx
mov [resh],rdx ;Remainder
mov [resl],rax ;Quotient
scall 1,1, rmsg,rmsg_len
mov rbx,[resh]
call disp64num
scall 1,1, qmsg,qmsg_len
mov rbx,[resl]
call disp64num
scall 1,1, nwmsg,1
ret
disp64num:
mov ecx,16
mov edi,dispbuff
dup1:
rol rbx,4
mov al,bl
and al,0fh
cmp al,09
jbe dskip
add al,07h
dskip: add al,30h
mov [edi],al
inc edi
loop dup1
scall 1,1,dispbuff,16
ret

OUTPUT=>
****** Menu ******
+: Addition
- :Subtraction
*: Multiplication
/: Division

Enter your choice:: +

Result is : 000000000000000A

****** Menu ******


+: Addition
- : Subtraction
*: Multiplication
/: Division

Enter your choice:: -


Result is:0000000000000006

****** Menu ******


+: Addition
- : Subtraction
*: Multiplication
/: Division

Enter your choice:: *

Result is: 00000000000000000000000000000010

****** Menu ******


+: Addition
-: Subtraction
*: Multiplication
/: Division

Enter your choice:: /

Remainder::000000000000000
Quotient::00000000000004

You might also like