Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;ALP program to convert 5 digit BCD to HEX
- ;------------------------------------------------------------
- section .data
- msg db "Enter 5 digit number:"
- msg_len equ $-msg
- msg1 db "Conerted into Hexadecimal No:"
- msg1_len equ $-msg1
- newline db 10
- newline_len equ $-newline
- ;--------------------------------------------------------------
- section .bss
- buf resb 1
- ans resb 2
- char_ans resb 2
- ;---------------------------------------------------------------
- %macro print 2
- mov rax,1
- mov rdi,1
- mov rsi,%1
- mov rdx,%2
- syscall
- %endmacro
- %macro read 2
- mov rax,0
- mov rdi,0
- mov rsi,%1
- mov rdx,%2
- syscall
- %endmacro
- %macro end 0
- mov rax,60
- mov rdi,0
- syscall
- %endmacro
- ;-------------------------------------------------------------
- section .text
- global _start
- _start:
- Call BCD_HEX
- print newline,newline_len
- end
- BCD_HEX:
- print msg,msg_len
- read buf,6
- mov rsi,buf
- mov ax,0
- mov rbp,5 ;counter
- mov rbx,10
- next:
- mov cx,0
- mul bx
- mov cl,[rsi]
- sub cl,30h ;cl is the one we have taken from console
- add ax,cx
- inc rsi
- dec rbp
- jnz next
- mov [ans],ax
- print msg1,msg1_len
- mov ax,[ans]
- call Display
- ret
- Display:
- mov rbx,16
- mov rcx,4
- mov rsi,char_ans+3
- back:
- mov rdx,0
- div rbx
- cmp dl,09h
- jbe add30
- add dl,07h
- add30:
- add dl,30h
- mov [rsi],dl
- dec rsi
- dec rcx
- jnz back
- print char_ans,4
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement