943,512 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 665
  • Assembly RSS
Apr 24th, 2008
0

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

Expand Post »
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:
Assembly Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
punmeister is offline Offline
3 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Convert decimal to binary number?
Next Thread in Assembly Forum Timeline: Trying to build my own os, Help me out here





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC