Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. toHex PROC
  2. push ax
  3. push bx
  4. push cx
  5. push dx
  6. push di
  7. push si
  8.  
  9. divisor dw 16 ;
  10.  
  11. lea si, buffer2 ;buffer in which final result appears
  12.  
  13. xor ax,ax ;clear ax
  14. xor dx,dx ;clear dx
  15. mov cx, 1
  16.  
  17. mov bx, divisor ; bx = divisor
  18. for:
  19. mov ax, buffer ;moves number to ax register
  20. cmp cx,0; useless but most likely not safe to delete
  21. je endFor
  22. div2:
  23. ;mov al, dl
  24. ;xor dl, dl
  25. div bx ;divides by 16
  26. push dx; saves dx
  27.  
  28. xor dx, dx; zero extends input divisor
  29. cmp ax, 15; skips division loop if ax is single digit
  30. jle getHex2
  31. pop dx ;gets dx
  32. push dx ;saves it
  33. xor dx, dx;clears it
  34. inc cx;increments the counter of divisions
  35. jg div2
  36. getHex2WithPop:
  37. pop dx ;gets remainder
  38. jmp secondCharAdd
  39. getHex2:
  40. mov dl, al
  41. add dl, 30h ;makes into ascii
  42. cmp dl, 39h ;
  43. jle writeFirstChar; adds more in >=10
  44. add dl, 7h
  45. writeFirstChar:
  46. mov [si], dl;writes first number
  47. inc si
  48. pop dx
  49. secondCharAdd:
  50. add dl, 30h
  51. cmp dl, 39h
  52. jle writeSecondChar
  53. add dl,7h
  54. writeSecondChar:
  55. mov [si], dl ;writes remainder
  56. inc si
  57. loop getHex2WithPop ;loops
  58. endFor:
  59. mov [si], "$"
  60. inc si
  61.  
  62. pop si
  63. pop di
  64. pop dx
  65. pop cx
  66. pop bx
  67. pop ax
  68. ret
  69.  
  70. toHex ENDP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement