putint function not working

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
zerorax
Posts: 3
Joined: Wed Sep 09, 2015 3:41 pm
Libera.chat IRC: zerorax

putint function not working

Post 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
alexfru
Member
Member
Posts: 1123
Joined: Tue Mar 04, 2014 5:27 am

Re: putint function not working

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: putint function not working

Post by Combuster »

Which three registers are used by DIV?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: putint function not working

Post by Roman »

(R/E)DX must be null before executing DIV.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: putint function not working

Post 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
Post Reply