88 lines
1.6 KiB
Plaintext
88 lines
1.6 KiB
Plaintext
extern _printf
|
|
|
|
section .data
|
|
output db 0,0,0,0
|
|
reversedOutput db 0,0
|
|
|
|
section .text
|
|
global _main
|
|
_main:
|
|
mov ecx, 0
|
|
looping:
|
|
inc ecx
|
|
mov eax, ecx
|
|
push ecx
|
|
cmp ecx, 5
|
|
je do5
|
|
cmp ecx, 10
|
|
je do10
|
|
don:
|
|
call createOutput
|
|
mov [eax+1], byte 0x2c
|
|
mov [eax+2], byte 0x20
|
|
push eax
|
|
call _printf
|
|
add esp, 4
|
|
pop ecx
|
|
jmp looping
|
|
do5:
|
|
call createOutput
|
|
mov [eax+1], byte 0x0a
|
|
push eax
|
|
call _printf
|
|
add esp, 4
|
|
pop ecx
|
|
jmp looping
|
|
do10:
|
|
call createOutput
|
|
mov [eax+2], byte 0x0a
|
|
push eax
|
|
call _printf
|
|
add esp, 4
|
|
pop ecx
|
|
xor eax, eax
|
|
ret
|
|
|
|
|
|
createOutput: ;parameter in eax
|
|
;eax between 1 and 99
|
|
push ebx
|
|
mov ecx, 0
|
|
clearOutput:
|
|
mov [output+ecx], byte 0
|
|
cmp ecx, 3
|
|
je next
|
|
inc ecx
|
|
jmp clearOutput
|
|
next:
|
|
mov ecx, 0
|
|
mov ebx, 10
|
|
cOlooping:
|
|
xor edx, edx
|
|
div ebx
|
|
mov [reversedOutput+ecx], dl
|
|
add [reversedOutput+ecx], byte 0x30
|
|
cmp eax, 0
|
|
je reverse
|
|
cmp ecx, 1
|
|
je reverse
|
|
inc ecx
|
|
jmp cOlooping
|
|
reverse:
|
|
mov ecx, -1
|
|
mov ebx, 0
|
|
name:
|
|
inc ecx
|
|
neg ecx
|
|
mov dl, [reversedOutput+ecx+1]
|
|
neg ecx
|
|
cmp dl, 0
|
|
je name
|
|
mov [output + ebx], dl
|
|
inc ebx
|
|
cmp ecx, 1
|
|
jl name
|
|
mov eax, output
|
|
pop ebx
|
|
ret
|