diff --git a/.gitignore b/.gitignore index 1a687bd..462395b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.o a.out +solution diff --git a/02/main.s b/02/main.s index 2b331a4..cd3ec5e 100644 --- a/02/main.s +++ b/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]