Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- toHex PROC
- push ax
- push bx
- push cx
- push dx
- push di
- push si
- divisor dw 16 ;
- lea si, buffer2 ;buffer in which final result appears
- xor ax,ax ;clear ax
- xor dx,dx ;clear dx
- mov cx, 1
- mov bx, divisor ; bx = divisor
- for:
- mov ax, buffer ;moves number to ax register
- cmp cx,0; useless but most likely not safe to delete
- je endFor
- div2:
- ;mov al, dl
- ;xor dl, dl
- div bx ;divides by 16
- push dx; saves dx
- xor dx, dx; zero extends input divisor
- cmp ax, 15; skips division loop if ax is single digit
- jle getHex2
- pop dx ;gets dx
- push dx ;saves it
- xor dx, dx;clears it
- inc cx;increments the counter of divisions
- jg div2
- getHex2WithPop:
- pop dx ;gets remainder
- jmp secondCharAdd
- getHex2:
- mov dl, al
- add dl, 30h ;makes into ascii
- cmp dl, 39h ;
- jle writeFirstChar; adds more in >=10
- add dl, 7h
- writeFirstChar:
- mov [si], dl;writes first number
- inc si
- pop dx
- secondCharAdd:
- add dl, 30h
- cmp dl, 39h
- jle writeSecondChar
- add dl,7h
- writeSecondChar:
- mov [si], dl ;writes remainder
- inc si
- loop getHex2WithPop ;loops
- endFor:
- mov [si], "$"
- inc si
- pop si
- pop di
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- toHex ENDP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement