Adds hex2str
This commit is contained in:
@@ -5,15 +5,16 @@ section .bss
|
||||
section .text
|
||||
global dec2str
|
||||
global udec2str
|
||||
global hex2str
|
||||
|
||||
;----- dec2str(num) -----;
|
||||
;----- dec2str(int) -----;
|
||||
; Converts a signed integer to a string (decimal output)
|
||||
; Return value: Pointer to string containing the converted number
|
||||
; Return value: Pointer to string containing the converted integer
|
||||
; Used registers:
|
||||
; rax* num stored for div >> (ret) pointer to cnvtBuff[]
|
||||
; rax* int stored for div >> (ret) pointer to cnvtBuff[]
|
||||
; rcx* Counts length of created string
|
||||
; rdx* modulo as calculated by div >> character storage for cnvtBuff
|
||||
; rdi* (arg) number to convert to string >> Remembers if num is negative
|
||||
; rdi* (arg) integer to convert to string >> Remembers if num is negative
|
||||
; rsi* Points to cnvtBuff for writing characters
|
||||
; r8* Dividor for div
|
||||
dec2str:
|
||||
@@ -56,14 +57,14 @@ dec2str:
|
||||
mov rax, cnvtBuff
|
||||
ret
|
||||
|
||||
;----- udec2str(num) -----;
|
||||
;----- udec2str(uint) -----;
|
||||
; Converts an unsigned integer to a string (decimal output)
|
||||
; Return value: Pointer to string containing the converted number
|
||||
; Return value: Pointer to string containing the converted integer
|
||||
; Used registers:
|
||||
; rax* num stored for div >> (ret) pointer to cnvtBuff[]
|
||||
; rax* uint stored for div >> (ret) pointer to cnvtBuff[]
|
||||
; rcx* Counts length of created string
|
||||
; rdx* modulo as calculated by div >> character storage for cnvtBuff
|
||||
; rdi* (arg) number to convert to string
|
||||
; rdi* (arg) integer to convert to string
|
||||
; rsi* Points to cnvtBuff for writing characters
|
||||
; r8* Dividor for div
|
||||
udec2str:
|
||||
@@ -97,3 +98,63 @@ udec2str:
|
||||
.quit:
|
||||
mov rax, cnvtBuff
|
||||
ret
|
||||
|
||||
;----- hex2str(uint, bool uppercase) -----;
|
||||
; Converts an unsigned integer to a string (hexadecimal output)
|
||||
; Return value: Pointer to string containing the converted integer
|
||||
; Used registers:
|
||||
; rax* uint stored for div >> (ret) Pointer to cnvtBuff[]
|
||||
; rdi (arg) Integer to convert
|
||||
; rsi* (arg) 0=convert lowercase, (any other value)=convert uppercase >> Points to cnvtBuff for writing characters
|
||||
; rdx* module as calculated by div
|
||||
; rcx* Counts length of created string
|
||||
; r8* Dividor for div
|
||||
; r9* Store arg rsi (uppercase)
|
||||
hex2str:
|
||||
mov r9, rsi
|
||||
mov rsi, cnvtBuff
|
||||
test rdi, rdi
|
||||
jnz .notZero
|
||||
mov word [rsi], '0x'
|
||||
mov byte [rsi + 2], '0'
|
||||
mov byte [rsi + 3], EOS
|
||||
jmp .quit
|
||||
|
||||
.notZero:
|
||||
mov rax, rdi
|
||||
xor dil, dil
|
||||
xor rcx, rcx
|
||||
.convert:
|
||||
xor rdx, rdx
|
||||
mov r8, 16
|
||||
div r8
|
||||
cmp rdx, 10
|
||||
jb .num
|
||||
cmp r9, 1
|
||||
jne .lower
|
||||
;.upper:
|
||||
add rdx, 55
|
||||
jmp .push
|
||||
.lower:
|
||||
add rdx, 87
|
||||
jmp .push
|
||||
.num:
|
||||
add rdx, '0'
|
||||
.push:
|
||||
push rdx
|
||||
inc rcx
|
||||
test rax, rax
|
||||
jnz .convert
|
||||
|
||||
mov word [rsi], '0x'
|
||||
add rsi, 2
|
||||
.makeString:
|
||||
pop rdx
|
||||
mov byte [rsi], dl
|
||||
inc rsi
|
||||
loop .makeString
|
||||
mov byte [rsi], EOS
|
||||
|
||||
.quit:
|
||||
mov rax, cnvtBuff
|
||||
ret
|
||||
|
Reference in New Issue
Block a user