ALP to convert the hexadecimal to BCD number (64-bit)
kw.asm
section.datatitledb"———————————————————————————————————————————"db10,"ALPtoconvertthehexadecimaltoBCDnumber"
db 10, "———————————————————————————————————————————"
db 10, "Enter4digithexadecimalnumaber"title_len equ$-titleoutputdb10,"BinaryCodedDecimalequivalentis"output_len equ$-outputenddb10,"———————————————————————————————————————————",10end_len equ$-endsection.bsshexresb05bcdresb05%macro display 4
movrax,%1movrdi,%2movrsi,%3movrdx,%4syscall%endm
section.textglobal_start_start:display1,1,title,title_lendisplay0,0,hex,5movbx,0movrcx,04movrsi,hexup1:rolbx,04moval,[rsi]cmpal,39hjbeskip1subal,07hskip1:subal,30haddbl,alincrsiloopup1movrcx,5movax,bxmovbx,10h2b1:movdx,0divbxpushrdxlooph2b1movrdi,bcdmovrcx,5h2b2:poprdxadddl,30hmov[rdi],dlincrdilooph2b2display1,1,output,output_lendisplay1,1,bcd,5display1,1,end,end_lenexit:movrax,60movrbx,0syscall
Output
kodingwindow@kw:~$ nasm -felf64 kw.asm kodingwindow@kw:~$ ld kw.o && ./a.out
———————————————————————————————————————————
ALP to convert the hexadecimal to BCD number
———————————————————————————————————————————
Enter 4 digit hexadecimal numaber FFFF
Binary Coded Decimal equivalent is 65535
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.