Write a switch case driven X86/64 ALP to perform 64-bit hexadecimal arithmetic operations (+,-,*, /) using suitable macros. Define procedure for each operation.
%macro disp 2
mov rax,01h
mov rdi,01h
mov rsi,%1
mov rdx,%2
syscall
%endmacro
%macro inp 2
mov rax,00h
mov rdi,00h
mov rsi,%1
mov rdx,%2
syscall
%endmacro
section .data
msg1 db "enter first 8 bit hex no:",10
len1: equ $-msg1
msg2 db "enter second 8 bit hex no:",10
len2: equ $-msg2
msg3 db "Addition result is:",10
len3: equ $-msg3
section .bss
num1 resb 3
num2 resb 3
res resb 02
section .text
global _start
_start:
disp msg1,len1
inp num1,03
disp msg2,len2
inp num2,03
mov rsi,num1
mov cl,04
xor bx,bx
mov ch,02
up:
cmp byte[rsi],39h
jng sk
sub byte[rsi],07h
sk:
sub byte[rsi],30h
shl bx,cl
add bl,[rsi]
inc rsi
dec ch
jnz up
xor dx,dx
mov rsi,num2
mov cl,04
mov ch,02
up1:
cmp byte[rsi],39h
jng sk1
sub byte[rsi],07h
sk1:
sub byte[rsi],30h
shl dx,cl
add dl,[rsi]
inc rsi
dec ch
jnz up1
add bl,dl
mov al,bl
mov rsi,res
mov ch,02
mov cl,04
again1:
rol al,cl
mov bl,al
and bl,0fh
cmp bl,09h
jng skip2
add bl,07h
skip2:
add bl,30h
mov [rsi],bl
inc rsi
dec ch
jnz again1
disp res,02
mov rax,3ch
mov rdi,00
syscall
Comments
Post a Comment