section .data
msg db "welcome to code conversion",10
len: equ $-msg
note db 10,"enter your choice",10,"1.hexadecimal to bcd",10,"2.bcd to hexadecimal",10,"3.exit",10
notlen: equ $-note
hexmsg db "enter 16 bit hexadecimal number",10
hexlen: equ $-hexmsg
msg1 db "BCD no for given hexadecimal no is:",10
len1: equ $-msg1
msg2 db "Enter BCD no to convert in hexadecimal no(less than 65535)",10
len2: equ $-msg2
msg3 db "hexadecimal no for given BCD no is:",10
len3: equ $-msg3
msg4 db 13,"Thank you for using code conversion.",10
len4: equ $-msg4
section .bss
n resb 2
hex resb 5
bcd resb 6
%macro disp 2
mov rax,01
mov rdi,01
mov rsi,%1
mov rdx,%2
syscall
%endmacro
%macro inn 2
mov rax,00
mov rdi,00
mov rsi,%1
mov rdx,%2
syscall
%endmacro
section .text
global _start
_start:
disp msg,len
again:
disp note,notlen
inn n,02
cmp byte[n],31h
jne BCD
disp hexmsg,hexlen
inn hex,05
xor rax,rax
mov rsi,hex
mov cl,04
mov ch,04
up:
cmp byte[rsi],39h
jng skip1
sub byte[rsi],07h
skip1:
sub byte[rsi],30h
shl rax,cl
add al,[rsi]
inc rsi
dec ch
jnz up
xor ebx,ebx
mov bl,0Ah
xor edx,edx
mov rsi,bcd
add rsi,04
up1:
div ebx
mov [rsi],dl
xor edx,edx
dec rsi
cmp eax,00
jne up1
mov rsi,bcd
mov cl,05
up2:
add byte[rsi],30h
inc rsi
dec cl
jnz up2
disp msg1,len1
disp bcd,05
jmp again
BCD:
cmp byte[n],32h
jne exit
disp msg2,len2
inn bcd,06
xor rax,rax
mov rsi,bcd
mov ch,05
uphex:
sub byte[rsi],30h
inc rsi
dec ch
jnz uphex
mov cl,05h
mov rsi,bcd
j1:
add dx,0Ah
mul dx
xor bx,bx
mov bl,[rsi]
add al,bl
inc rsi
dec cl
jnz j1
mov rsi,hex
add rsi,03h
mov ch,04
mov cl,04
as:
mov bl,al
and bl,0fh
cmp bl,09h
jng skip6
add bl,07h
skip6:
add bl,30h
mov [rsi],bl
shr rax,cl
dec esi
dec ch
jnz as
disp msg3,len3
disp hex,04
jmp again
exit:
cmp byte[n],33h
je sn
sn:
disp msg4,len4
mov rax,3ch
mov rdi,00
syscall
msg db "welcome to code conversion",10
len: equ $-msg
note db 10,"enter your choice",10,"1.hexadecimal to bcd",10,"2.bcd to hexadecimal",10,"3.exit",10
notlen: equ $-note
hexmsg db "enter 16 bit hexadecimal number",10
hexlen: equ $-hexmsg
msg1 db "BCD no for given hexadecimal no is:",10
len1: equ $-msg1
msg2 db "Enter BCD no to convert in hexadecimal no(less than 65535)",10
len2: equ $-msg2
msg3 db "hexadecimal no for given BCD no is:",10
len3: equ $-msg3
msg4 db 13,"Thank you for using code conversion.",10
len4: equ $-msg4
section .bss
n resb 2
hex resb 5
bcd resb 6
%macro disp 2
mov rax,01
mov rdi,01
mov rsi,%1
mov rdx,%2
syscall
%endmacro
%macro inn 2
mov rax,00
mov rdi,00
mov rsi,%1
mov rdx,%2
syscall
%endmacro
section .text
global _start
_start:
disp msg,len
again:
disp note,notlen
inn n,02
cmp byte[n],31h
jne BCD
disp hexmsg,hexlen
inn hex,05
xor rax,rax
mov rsi,hex
mov cl,04
mov ch,04
up:
cmp byte[rsi],39h
jng skip1
sub byte[rsi],07h
skip1:
sub byte[rsi],30h
shl rax,cl
add al,[rsi]
inc rsi
dec ch
jnz up
xor ebx,ebx
mov bl,0Ah
xor edx,edx
mov rsi,bcd
add rsi,04
up1:
div ebx
mov [rsi],dl
xor edx,edx
dec rsi
cmp eax,00
jne up1
mov rsi,bcd
mov cl,05
up2:
add byte[rsi],30h
inc rsi
dec cl
jnz up2
disp msg1,len1
disp bcd,05
jmp again
BCD:
cmp byte[n],32h
jne exit
disp msg2,len2
inn bcd,06
xor rax,rax
mov rsi,bcd
mov ch,05
uphex:
sub byte[rsi],30h
inc rsi
dec ch
jnz uphex
mov cl,05h
mov rsi,bcd
j1:
add dx,0Ah
mul dx
xor bx,bx
mov bl,[rsi]
add al,bl
inc rsi
dec cl
jnz j1
mov rsi,hex
add rsi,03h
mov ch,04
mov cl,04
as:
mov bl,al
and bl,0fh
cmp bl,09h
jng skip6
add bl,07h
skip6:
add bl,30h
mov [rsi],bl
shr rax,cl
dec esi
dec ch
jnz as
disp msg3,len3
disp hex,04
jmp again
exit:
cmp byte[n],33h
je sn
sn:
disp msg4,len4
mov rax,3ch
mov rdi,00
syscall
No comments:
Post a Comment