diff options
| author | mithe24 <mithe24@student.sdu.dk> | 2025-10-30 10:32:02 +0100 |
|---|---|---|
| committer | mithe24 <mithe24@student.sdu.dk> | 2025-10-30 10:32:02 +0100 |
| commit | fb4efd3131c2223cd56376c56704d30f20efc29e (patch) | |
| tree | f1012f8516bda12e59e698158e6e2dff33567e93 | |
| parent | 597022b22e0e499a567d29c7248e90b7726e0770 (diff) | |
| download | sorter-fb4efd3131c2223cd56376c56704d30f20efc29e.tar.gz sorter-fb4efd3131c2223cd56376c56704d30f20efc29e.zip | |
forgot lib
Diffstat (limited to '')
| -rw-r--r-- | src/lib/int2str.s | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/lib/int2str.s b/src/lib/int2str.s index 0acf4b8..5d4ab1e 100644 --- a/src/lib/int2str.s +++ b/src/lib/int2str.s @@ -22,46 +22,46 @@ int2str: # handle sign testq %rax, %rax - jns .convert + jns .int2str_convert negq %rax # if the number negative we negate it and movq $1, %r10 # set sign flag -.convert: +.int2str_convert: testq %rax, %rax - jnz .loop # check if the number is 0 + jnz .int2str_loop # check if the number is 0 # if the number is 0, we just set the char to '0', and length to 0. movb $'0', (%r8) movq %r8, %rax movq $1, %rdx - jmp .shift_left # shift the result leftmust + jmp .int2str_shift_left # shift the result leftmust -.loop: +.int2str_loop: xorq %rdx, %rdx # clear rdx before division divq %rcx # divide rdx:rax by 10 addb $'0', %dl # add ASCII base movb %dl, (%r8) # move digit into buffer decq %r8 # decrement pointer testq %rax, %rax # while quotient is not 0, loop - jnz .loop + jnz .int2str_loop incq %r8 # move back to first digit # add '-' if negative testq %r10, %r10 - jns .calc_len + jns .int2str_calc_len decq %r8 movb $'-', (%r8) -.calc_len: # count length of the string +.int2str_calc_len: # count length of the string movq %r8, %rax # string start leaq 20(%r9), %rdx # end of buffer subq %rax, %rdx # string length -.shift_left: +.int2str_shift_left: # shift string to leftmost in buffer if not already there cmpq %rax, %r9 - je .done # already leftmost + je .int2str_done # already leftmost cld # Clear direction flag (forward copy) movq %rdx, %rcx # rcx = length of string movq %rax, %rsi # rsi = source :: start of string @@ -79,6 +79,6 @@ int2str: # https://stackoverflow.com/questions/27804852/assembly-rep-movs-mechanism movq %r9, %rax # return pointer to start -.done: +.int2str_done: popq %rbx ret |