I'm trying to do a quick test program in x86 assembly that takes a string and just outputs it again, that also detects if there is a space and displays some text. This program is mainly so I can figure out detection of the space character.
LC0:
.ascii "Enter a string: \0"
LC1:
.ascii "%[^\n]\0"
LC2:
.ascii "Your string is:\12\0"
LC4:
.ascii "%c\12\0" # print out the character
LC6:
.ascii "Yeehaw!\12\0" # test message
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $112, %esp
movl $LC0, (%esp)
call _puts # similar to _printf function
leal 8(%esp), %eax
movl %eax, 4(%esp)
movl $LC1, (%esp)
call _scanf # get string
movl $LC2, (%esp)
call _printf # printout the output text of LC2
###### A[i] ###### ebx is the index
movl $0, %ebx #index of array i=0
jmp .L2
.L1: #TEXT PORTION
movsbl %al, %eax # eax =FFFFFFXX XX means for each character print out the input character
incl %ebx # next index of array
movl %eax, 4(%esp) # print out from the first element of the array
movl $LC4, (%esp)
call _printf
.L2: #TEXT PORTION
movzbl 8(%esp,%ebx), %eax # the value of esp+8+0 strating address of the array to eax
#Problem lines
cmpb 0x20, %al # compare eax to see if it is a space
jne .EndOfLine
#should only run if %al is a space
movl $LC6, (%esp) # test message to check if properly detecting spaces
call _printf
.EndOfLine:
testb %al, %al # if eax is not equal to zero jump to L3, if is zero menas end of the string
jne .L1
movl $0, %eax
addl $112, %esp
leave
ret
Without cmpb 0x20, %al my program works just fine (if input is "Hello", will print "Hello"), but as soon as I add that line it doesn't print anything and just goes to the end of the program. Anyone know why this is happening?