I'd like to print the counter of a loop (0 --> 4). In the code below diff is the ASCII number of '0' character, max the times the loop repeats, count the counter and p is the variable that contain the character.
.data
.text
.global main
diff = 48
max = 5
count: .byte 0
p: .long 0
main:
compare:
cmpb $max,count # if counter is equal or above max
jae end # jump to end
movl $4,%eax # write
movl $1,%ebx # stdout
xor %ecx,%ecx # reset ecx
addb $diff,%cl # add ASCII number of '0'
addb count,%cl # add value of counter
movb %cl,p # move ASCII value of the counter
movl $p,%ecx # move the number to third argument of write
movl $4,%edx # size of long
int $0x80 # interrupt
movb count,%al # move value of the counter to al
inc %al # increment al
movb %al,count # move value of al to counter
jmp compare # always jump to compare
end:
movl $1,%eax # exit
movl $0,%ebx # exit(0)
int $0x80 # interrupt
It doesn't work. gcc doesn't give me errors, but executing it gives a core dump. Why?