Microprocessor Lab Practicals
Microprocessor Lab Practicals
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:: '
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
Result is : 000000000000000A
Remainder::000000000000000
Quotient::00000000000004