punmeister 0 Newbie Poster

Wohoo, first post.
I have a problem with my code, the problem is that instead of writing "%" in res, when the pattern "%%" shows up, it writes it out as "%%" anyways. Currently I have it working so it works as strcpy. Seriously, I don't understand what I'm doing wrong. No matter what I do I can't make the loop process "%%". Here's the relevant code:

loop:
	movb	(%eax, %esi, 1), %cl	# Move (*format[formati]) to %cl
	testb	%cl, %cl		# (*format[formati]) == 0?
	jz	done			# If yes, jump to done, else continue
		
	testb	%cl,prosent		# (*format[formati]) == '%'?
	je	prosentloop		# If yes, jump to  prosentloop, else continue
	
					# This byte isn't 0 and it isn't '%'
	movb	%cl, (%edx, %edi, 1)	# *res[resi] = *format[formati]
	
	incl	%edi			# resi++
	incl	%esi			# formati++
	jmp	loop			# Go through loop again
	
prosentloop:
	incl	%esi			# Since % works more like a escape sign, we need to iterae
					# formati to get the next charaxter

	movb	(%eax, %esi, 1), %cl	# Moves next byte to %cl
	
	testb	%cl, %cl		# (*format[formati]) == 0?
	jz	done			# If yes, jump to done
	
	testb	%cl, prosent		# (*format[formati]) == '%'?
	je	prosentcon		# If it's a percent character again, jump to prosentcon
	
prosentcon:
	movb	%cl, (%edx, %edi, 1)	# %cl is '%', store it at (*res[resi])
	incl	%edi			# resi++
	incl	%esi			# formati++
	jmp	loop			# Jump back to loop
	.data
prosent:	.byte	'%'		# % - Percentage char is dec 37 and hex 25 in ASCII-table

Link to assembly file: http://folk.uio.no/kabeern/sprinter.s
Link to C test file: http://folk.uio.no/kabeern/test-sprinter.c

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.