learning nasm assembly, need some help

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

Join Date: Jan 2008
Posts: 49
Reputation: flash121 is an unknown quantity at this point 
Solved Threads: 0
flash121 flash121 is offline Offline
Light Poster

learning nasm assembly, need some help

 
0
  #1
Nov 10th, 2008
Hello!

I've started learning assembly and I have some problems with a program. I'm trying to write a program that would print some text x-times (x would be inputed by me), but I always get an infinite loop, because it seems that the counter value doesn't get updated in the register in each iteration, therefore it never reaches the "x".

My code

  1. BITS 32
  2. extern printf
  3. extern scanf
  4. global main
  5.  
  6. section .data
  7.  
  8. text db "Random text",10,0
  9. input db "%d",10,0
  10. number dd 0
  11.  
  12. section .text
  13.  
  14. main:
  15.  
  16. push dword number
  17. push dword input
  18. call scanf
  19. add esp,8
  20. mov eax,[number]
  21. mov ecx,1
  22.  
  23. .loop:
  24.  
  25. push dword text
  26. call printf
  27. add esp,4
  28. inc ecx
  29. cmp ecx,eax
  30. jle .loop
  31.  
  32. ret

Any help would be much appriciated.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 19
Reputation: bionicseraph is an unknown quantity at this point 
Solved Threads: 6
bionicseraph bionicseraph is offline Offline
Newbie Poster

Re: learning nasm assembly, need some help

 
0
  #2
Nov 10th, 2008
I'd be willing to bet that printf changes the eax register... Have you looked into that?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 49
Reputation: flash121 is an unknown quantity at this point 
Solved Threads: 0
flash121 flash121 is offline Offline
Light Poster

Re: learning nasm assembly, need some help

 
0
  #3
Nov 11th, 2008
You're probably right, because i tried to increment the value in it twice in a row outside the loop, withouth using printf before. I only used it after and the value was indeed incremented twice like it was supposed to be.

Also, eax getting messed up isn't the only problem in my code, ecx doesn't get incremented either.
EDIT: well actually it does get, but it resets back after the code jumps back to the start of the loop
Last edited by flash121; Nov 11th, 2008 at 9:45 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 49
Reputation: flash121 is an unknown quantity at this point 
Solved Threads: 0
flash121 flash121 is offline Offline
Light Poster

Re: learning nasm assembly, need some help

 
0
  #4
Nov 11th, 2008
Managed to solve it. Printf was indeed messing with the values in the register, so a simple pushad before the function call and a popad after solved it.
Last edited by flash121; Nov 11th, 2008 at 4:39 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
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