Skip to content

Instantly share code, notes, and snippets.

/functions Secret

Created October 16, 2017 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8acab8cb8240c0bed0d4c7961f45511d to your computer and use it in GitHub Desktop.
Save anonymous/8acab8cb8240c0bed0d4c7961f45511d to your computer and use it in GitHub Desktop.
Convert int to string
; Pass in value in BX
Console_Write_Int:
mov si, IntBuffer + 4 ; Get last digit of intbuffer
mov ax, bx ; Move BX into AX
GetDigit:
xor dx, dx ; Clear DX
mov cx, 10 ; Counter to 10
div cx ; Divide by 10
add dl, 48 ; Convert to ASCII (add 48 to remainder)
mov [si], dl ; Store converted number to si
dec si
cmp ax, 0
jne GetDigit
inc si
call Console_Write_16
ret
IntBuffer db ' ', 0
; Convert value in BX as 4 digit hexadecimal number
; Pass in value in BX
Console_Write_Hex:
mov cx, 4
HexLoop:
rol bx, 4
mov si, bx
and si, 000Fh
mov al, byte [si + HexChars]
mov ah, 0Eh
int 10h
loop HexLoop
ret
HexChars db '0123456789ABCDEF'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment