make print_dec clearer
This commit is contained in:
parent
563076a899
commit
ba2250c29c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
*.o
|
||||
a.out
|
||||
solution
|
||||
|
30
02/main.s
30
02/main.s
@ -123,34 +123,42 @@ pop ecx
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
; i hate this
|
||||
; input in EAX, all regs unmodified
|
||||
print_dec:
|
||||
pushad ; save regs
|
||||
; max 4294967296 is 10 chars
|
||||
; round to nearest 32-bit boundary
|
||||
sub esp, 12
|
||||
lea ecx, [esp+11]
|
||||
; string in ECX, length in EDX
|
||||
lea ecx, [esp+11] ; last possible byte
|
||||
; check for 0
|
||||
test eax, eax
|
||||
jz .zero
|
||||
mov esi, 0
|
||||
mov ebx, 10
|
||||
mov ebx, 10 ; base 10
|
||||
xor esi, esi ; counter
|
||||
.div_shit:
|
||||
xor edx, edx
|
||||
; divide
|
||||
div ebx
|
||||
dec ecx
|
||||
dec ecx ; next char
|
||||
inc esi
|
||||
; store
|
||||
add dl, '0'
|
||||
mov byte [ecx], dl
|
||||
; check if done
|
||||
test eax, eax
|
||||
jnz .div_shit
|
||||
mov edx, esi
|
||||
jnz .div_shit ; continue
|
||||
mov edx, esi ; counter in edx
|
||||
jmp .write
|
||||
.zero:
|
||||
mov byte [esp+10], 0
|
||||
lea ecx, [esp+10]
|
||||
mov edx, 1 ; count
|
||||
mov byte [ecx], '0'
|
||||
mov edx, 1 ; length
|
||||
.write:
|
||||
mov eax, 4 ; write
|
||||
mov ebx, 1 ; stdout
|
||||
int 0x80
|
||||
add esp, 12
|
||||
add esp, 12 ; restore stack
|
||||
popad ; restore regs
|
||||
ret
|
||||
|
||||
[section .data]
|
||||
|
Loading…
Reference in New Issue
Block a user