MP 6
MP 6
Program
section .data
section .bss
arr resb 6 ; Common buffer for choice, hex and BCD input
%macro disp 2
mov rax, 01
mov rdi, 01
mov rsi, %1
mov rdx, %2
syscall
%endmacro
%macro accept 2
mov rax, 0
mov rdi, 0
mov rsi, %1
mov rdx, %2
syscall
%endmacro
section .text
global _start
_start:
menu:
jne l1
call hex2bcd_proc
jmp menu
l1:
jne l2
call bcd2hex_proc
jmp menu
l2:
je exit
jmp menu
exit:
mov rax, 60
mov rbx, 0
syscall
hex2bcd_proc:
mov rcx, 0
mov ax, bx
l33:
mov dx, 0
inc rcx
cmp ax, 0
jne l33
l44:
mov [ans], dl
disp ans, 1 ; Display the digit
jnz l44
ret
bcd2hex_proc:
mov rcx, 5
mov rax, 0
l55:
mov rdx, 0
inc rsi
dec rcx
jnz l55
mov ebx, eax ; Store the result in ebx
ret
conversion:
mov bx, 0
up1:
jbe l22
l22:
add bl, al
inc esi
loop up1
ret
disp32_num:
l77:
mov dl, bl
jbe l66
l66:
mov [rdi], dl
inc rdi
dec rcx
jnz l77
ret
output:
1: Hex to BCD
2: BCD to Hex
3: Exit
Enter Choice:1
Enter 4 digit hex number::2345
BCD Equivalent:9029
1: Hex to BCD
2: BCD to Hex
3: Exit
Enter Choice:2
Hex Equivalent::00929