ALP to convert the Binary Coded Decimal (BCD) to hexadecimal number (64-bit)
kw.asm
section.datatitledb"———————————————————————————————————————————"db10,"ALPtoconverttheBCDtohexadecimalnumber"
db 10, "———————————————————————————————————————————"
db 10, "Enter5digitBCDnumber"title_len equ$-titleoutputdb10,"Hexadecimalequivalentis"output_len equ$-outputenddb10,"———————————————————————————————————————————",10end_len equ$-endsection.bssnumasciiresb06opbuffresb05dnumbuffresb08%macro display 4
movrax,%1movrdi,%2movrsi,%3movrdx,%4syscall%endm
section.textglobal_start_start:bcd2hex_proc:display1,1,title,title_lendisplay0,0,numascii,6display1,1,output,output_lenmovrsi,numasciimovrcx,05movrax,0movrbx,0ahb2hup1:movrdx,0mulrbxmovdl,[rsi]subdl,30haddrax,rdxincrsiloopb2hup1movrbx,raxcalldisp32_numcallexitretdisp32_num:movrdi,dnumbuffmovrcx,08dispup1:rolebx,4movdl,blanddl,0fhadddl,30hcmpdl,39hjbedispskip1adddl,07hdispskip1:mov[rdi],dlincrdiloopdispup1display1,1,dnumbuff+3,5retexit:display1,1,end,end_lenmovrax,60movrdi,0syscall
Output
kodingwindow@kw:~$ nasm -felf64 kw.asm kodingwindow@kw:~$ ld kw.o && ./a.out
———————————————————————————————————————————
ALP to convert the BCD to hexadecimal number
———————————————————————————————————————————
Enter 5 digit BCD number 65535
Hexadecimal equivalent is 0FFFF
———————————————————————————————————————————
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.