4 MP
4 MP
: 04
;Rollno. : B-79
;Name : Vaishnavi Goraksh Kaware
;Write a switch case driven ALP to perform 64-bit hexadecimal arithmetic
operations (+,-,*, /) using suitable macros. Define procedure for each
operation.
section .data
menumsg db 10,'****** Menu ******',
db 10,'+: Addition'
db 10,'-: Subtraction'
db 10,'*: Multiplication'
db 10,'/: Division'
db 10,10,'Enter your choice:: '
menumsg_len: equ $-menumsg
no1 dq 0ff05h
no2 dq 0ffh
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
accbuff resb 2
dispbuff resb 16
%macro print 2
mov eax, 4
mov ebx, 1
mov ecx, %1
mov edx, %2
int 80h
%endmacro
section .text
global _start
_start: print menumsg,menumsg_len
mov eax,03
mov ebx,01
mov ecx,accbuff
mov edx,02
int 80h
call add_proc
jmp exit
case2:
cmp byte [accbuff],'-'
jne case3
call sub_proc
jmp exit
case3:
cmp byte [accbuff],'*'
jne case4
call mul_proc
jmp exit
case4:
cmp byte [accbuff],'/'
jne caseinv
call div_proc
jmp exit
caseinv:
print wrchmsg,wrchmsg_len
add_proc:
print addmsg,addmsg_len
mov rax,[no1]
add rax,[no2]
jnc addnxt1
inc qword [resh]
addnxt1:
mov [resl],rax
print resmsg,resmsg_len
mov rbx,[resh]
call disp64num
mov rbx,[resl]
call disp64num
print nwmsg,1
ret
sub_proc:
print submsg,submsg_len
mov rax,[no1]
sub rax,[no2]
jnc addnxt1
inc qword [resh]
subnxt1:
mov [resl],rax
print resmsg,resmsg_len
mov rbx,[resh]
call disp64num
mov rbx,[resl]
call disp64num
print nwmsg,1
ret
mul_proc:
print mulmsg,mulmsg_len
mov rax,[no1]
mov rbx,[no2]
mul rbx
mov [resh],rdx
mov [resl],rax
print resmsg,resmsg_len
mov rbx,[resh]
call disp64num
mov rbx,[resl]
call disp64num
print nwmsg,1
ret
div_proc:
print divmsg,divmsg_len
mov rax,[no1]
mov rdx,0
mov rbx,[no2]
div rbx
print rmsg,rmsg_len
mov rbx,[resh]
call disp64num
print qmsg,qmsg_len
mov rbx,[resl]
call disp64num
print 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
print dispbuff,16
ret
------------------------------------------------------------------------
Output
;Welcome to additon
;Result is:00000000000000000000000000010004
;[vaishnavi @(none) alp]$ ./ MPL4
;Welcome to subtraction
;Result is:0000000000000000000000000000FE06
;[vaishnavi@(none) alp]$ ./MPL4
;Welcome to Multiplication
;Result is:00000000000000000000000000FE05FB
;[vaishnavi@(none) alp]$ ./MPL4
;Welcome to Division
;Remainder::0000000000000005
;Quotient::0000000000000100
;[vaishnavi@(none) alp]$