| | |
Problem with sprinter.s, a reduced version of sprintf (GAS)
Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2008
Posts: 3
Reputation:
Solved Threads: 0
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:
Link to assembly file: http://folk.uio.no/kabeern/sprinter.s
Link to C test file: http://folk.uio.no/kabeern/test-sprinter.c
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:
Assembly Syntax (Toggle Plain Text)
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
Last edited by punmeister; Apr 24th, 2008 at 2:36 pm.
![]() |
Other Threads in the Assembly Forum
- Previous Thread: Convert decimal to binary number?
- Next Thread: Trying to build my own os, Help me out here
| Thread Tools | Search this Thread |





