Page 1 of 1

putint function not working

Posted: Fri Sep 11, 2015 8:37 pm
by zerorax
hello, i have written this function to print in base 10 an integer.
putc which it calls,takes dl as character and cl as color code

when i call putint with eax at 1024 it outputs 3 and a half lines of '5' then does nothing. can anyone tell me what I'm doing wroing?

putint:

.printdigit:
cmp eax, 0
je .zero
mov ebx, 10
push edx
div ebx
mov dl, '0'
add dl, al
mov cl, 7
call putc
mov eax, edx
pop edx

jmp .printdigit
.zero:
mov dl, '0'
mov cl, 7
call putc
ret

Re: putint function not working

Posted: Fri Sep 11, 2015 10:42 pm
by alexfru
Flip the switch from writing code position to reading code position. And go line by line. See what every instruction does with/to your inputs.

Re: putint function not working

Posted: Sat Sep 12, 2015 12:38 am
by Combuster
Which three registers are used by DIV?

Re: putint function not working

Posted: Sat Sep 12, 2015 2:38 am
by Roman
(R/E)DX must be null before executing DIV.

Re: putint function not working

Posted: Sat Sep 12, 2015 3:32 am
by glauxosdever
Hi,
Combuster wrote:Which three registers are used by DIV?
Roman wrote:(R/E)DX must be null before executing DIV.
His code has more flaws than just the DIV assumption.

zerorax: If you are being serious, study carefully the code you write and the instructions you use. If not, stop waiting for us to tell you what you are doing wrong.

Regards,
glauxosdever