Problem with sprinter.s, a reduced version of sprintf (GAS)

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 3
Reputation: punmeister is an unknown quantity at this point 
Solved Threads: 0
punmeister punmeister is offline Offline
Newbie Poster

Problem with sprinter.s, a reduced version of sprintf (GAS)

 
0
  #1
Apr 24th, 2008
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:
  1. loop:
  2. movb (%eax, %esi, 1), %cl # Move (*format[formati]) to %cl
  3. testb %cl, %cl # (*format[formati]) == 0?
  4. jz done # If yes, jump to done, else continue
  5.  
  6. testb %cl,prosent # (*format[formati]) == '%'?
  7. je prosentloop # If yes, jump to prosentloop, else continue
  8.  
  9. # This byte isn't 0 and it isn't '%'
  10. movb %cl, (%edx, %edi, 1) # *res[resi] = *format[formati]
  11.  
  12. incl %edi # resi++
  13. incl %esi # formati++
  14. jmp loop # Go through loop again
  15.  
  16. prosentloop:
  17. incl %esi # Since % works more like a escape sign, we need to iterae
  18. # formati to get the next charaxter
  19.  
  20. movb (%eax, %esi, 1), %cl # Moves next byte to %cl
  21.  
  22. testb %cl, %cl # (*format[formati]) == 0?
  23. jz done # If yes, jump to done
  24.  
  25. testb %cl, prosent # (*format[formati]) == '%'?
  26. je prosentcon # If it's a percent character again, jump to prosentcon
  27.  
  28. prosentcon:
  29. movb %cl, (%edx, %edi, 1) # %cl is '%', store it at (*res[resi])
  30. incl %edi # resi++
  31. incl %esi # formati++
  32. jmp loop # Jump back to loop
  33. .data
  34. prosent: .byte '%' # % - Percentage char is dec 37 and hex 25 in ASCII-table
  35.  

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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC