Minime80
02-13-2002, 04:43 AM
Okay, this assembly stuff is really getting on my nerves. I just don't thing I'm getting it. This program is supposed to go through and display some numbers to the screen digit by digit, but it just segfaults before outputting anything. What am I doing wrong now? Here's the code: section .data
section .text
global main
printchar:
push ebp
mov ebp, esp
mov eax, 4
mov ebx, 1
mov ecx, dword [ebp + 8]
mov edx, 1
int 80H
leave
ret
putdec_unsigned:
push ebp
mov ebp, esp
mov eax, dword [ebp + 8]
mov ebx, -1
push ebx
.startwhile:
mov edx, 0
mov ebx, 10
idiv ebx
push edx
cmp eax, 0
jne .startwhile
.startloop:
pop eax
cmp eax, -1
je .endloop
push eax
call printchar
pop eax
jmp .startloop
.endloop:
mov ebx, 10
push ebx
call printchar
pop ebx
leave
ret
putdec:
push ebp
mov ebp, esp
mov eax, dword [ebp + 8]
push eax
cmp eax, 0
jnl .endif
mov ebx, 45
push ebx
call printchar
pop ebx
.endif:
pop eax
neg eax
push eax
call putdec_unsigned
pop eax
leave
ret
main:
push ebp
mov ebp, esp
mov eax, -1
push eax
call putdec
pop eax
mov eax, -32768
push eax
call putdec
pop eax
mov eax, -32767
push eax
call putdec
pop eax
mov eax, 1000
push eax
call putdec
pop eax
mov eax, -100
.startwhile:
cmp eax, 100
jg .endwhile
push eax
call putdec
pop eax
add eax, 10
jmp .startwhile
.endwhile:
mov eax, 1
push eax
call putdec
pop eax
mov eax, 32767
push eax
call putdec
pop eax
mov eax, 1000
push eax
call putdec
pop eax
mov eax, 109
push eax
call putdec
pop eax
mov eax, -2
push eax
call putdec
pop eax
mov eax, -1024
push eax
call putdec
pop eax
leave
ret
One thing I know that's wrong is that I forgot to add the ASCII '0' to each digit before trying to display it, but even after I fixed that it still blew up before outputting anything. HELP PLEASE!!!
section .text
global main
printchar:
push ebp
mov ebp, esp
mov eax, 4
mov ebx, 1
mov ecx, dword [ebp + 8]
mov edx, 1
int 80H
leave
ret
putdec_unsigned:
push ebp
mov ebp, esp
mov eax, dword [ebp + 8]
mov ebx, -1
push ebx
.startwhile:
mov edx, 0
mov ebx, 10
idiv ebx
push edx
cmp eax, 0
jne .startwhile
.startloop:
pop eax
cmp eax, -1
je .endloop
push eax
call printchar
pop eax
jmp .startloop
.endloop:
mov ebx, 10
push ebx
call printchar
pop ebx
leave
ret
putdec:
push ebp
mov ebp, esp
mov eax, dword [ebp + 8]
push eax
cmp eax, 0
jnl .endif
mov ebx, 45
push ebx
call printchar
pop ebx
.endif:
pop eax
neg eax
push eax
call putdec_unsigned
pop eax
leave
ret
main:
push ebp
mov ebp, esp
mov eax, -1
push eax
call putdec
pop eax
mov eax, -32768
push eax
call putdec
pop eax
mov eax, -32767
push eax
call putdec
pop eax
mov eax, 1000
push eax
call putdec
pop eax
mov eax, -100
.startwhile:
cmp eax, 100
jg .endwhile
push eax
call putdec
pop eax
add eax, 10
jmp .startwhile
.endwhile:
mov eax, 1
push eax
call putdec
pop eax
mov eax, 32767
push eax
call putdec
pop eax
mov eax, 1000
push eax
call putdec
pop eax
mov eax, 109
push eax
call putdec
pop eax
mov eax, -2
push eax
call putdec
pop eax
mov eax, -1024
push eax
call putdec
pop eax
leave
ret
One thing I know that's wrong is that I forgot to add the ASCII '0' to each digit before trying to display it, but even after I fixed that it still blew up before outputting anything. HELP PLEASE!!!