Advertisement
Eternoseeker

ass 4 BCD to HEX part1

Jun 5th, 2023
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASM (NASM) 1.38 KB | Source Code | 0 0
  1. ;ALP program to convert 5 digit BCD to HEX
  2. ;------------------------------------------------------------
  3. section .data
  4.  
  5. msg db "Enter 5 digit number:"
  6. msg_len equ $-msg
  7.  
  8. msg1 db "Conerted into Hexadecimal No:"
  9. msg1_len equ $-msg1
  10.  
  11. newline db 10
  12. newline_len equ $-newline
  13.  
  14. ;--------------------------------------------------------------
  15.  
  16. section .bss
  17.  
  18. buf resb 1
  19. ans resb 2
  20. char_ans resb 2
  21.  
  22. ;---------------------------------------------------------------
  23.  
  24. %macro print 2
  25. mov rax,1
  26. mov rdi,1
  27. mov rsi,%1
  28. mov rdx,%2
  29. syscall
  30. %endmacro
  31.  
  32. %macro read 2
  33. mov rax,0
  34. mov rdi,0
  35. mov rsi,%1
  36. mov rdx,%2
  37. syscall
  38. %endmacro
  39.  
  40. %macro end 0
  41. mov rax,60
  42. mov rdi,0
  43. syscall
  44. %endmacro
  45.  
  46. ;-------------------------------------------------------------
  47.  
  48. section .text
  49. global _start
  50. _start:
  51.  
  52. Call BCD_HEX
  53. print newline,newline_len
  54. end
  55.  
  56. BCD_HEX:
  57.  
  58. print msg,msg_len
  59. read buf,6
  60.  
  61. mov rsi,buf
  62. mov ax,0
  63. mov rbp,5                  ;counter
  64. mov rbx,10
  65.  
  66. next:
  67. mov cx,0
  68. mul bx
  69. mov cl,[rsi]
  70. sub cl,30h                ;cl is the one we have taken from console
  71. add ax,cx
  72.  
  73. inc rsi
  74. dec rbp
  75. jnz next
  76.  
  77. mov [ans],ax
  78. print msg1,msg1_len
  79.  
  80. mov ax,[ans]
  81. call Display
  82. ret
  83.  
  84.  
  85. Display:
  86. mov rbx,16
  87. mov rcx,4
  88. mov rsi,char_ans+3
  89.  
  90. back:
  91. mov rdx,0
  92. div rbx
  93.  
  94. cmp dl,09h
  95. jbe add30
  96. add dl,07h
  97.  
  98. add30:
  99. add dl,30h
  100.  
  101. mov [rsi],dl
  102. dec rsi
  103. dec rcx
  104. jnz back
  105.  
  106. print char_ans,4
  107. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement