943,724 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 1283
  • Assembly RSS
Feb 2nd, 2009
0

Getting input without newline

Expand Post »
Hello everyone,
I started learning assembly yesterday. Yes maybe I chose a wrong guide but I have a little problem here. It's about getting some integers without a newline. That is probably very easy to solve but I was searching for a solution for a few hours and no results. Well, enough about that, let's get to the point.
I need to get an input cointaining some integers, but I need them to be without a newline. I wrote a small loop to do that for me, I think everything is OK, yet it gives me a "Segmentation fault".

CPU: i486
Assembler: NASM version 0.99.06-20071101
OS: Ubuntu 8.04 (Hardy)
Linux kernel: 2.6.24-22-generic

Commands:
nasm -f elf kalkulator.asm
ld -s -o kalkulator kalkulator.o
asm Syntax (Toggle Plain Text)
  1. %define lf 10
  2.  
  3. bufor1: times 40 db 0
  4. bufor2: times 40 db 0
  5.  
  6. wczytuj:
  7. xor esi, esi
  8. mov esi, 0
  9.  
  10. petla:
  11. push eax
  12. push ebx
  13. push ecx
  14. push edx
  15.  
  16. mov eax, 3
  17. mov ebx, 0
  18. lea ecx, [bufor1]
  19. mov edx, 1
  20. mov al, [bufor1]
  21.  
  22. cmp al, lf
  23. jne _wczytuj_zapisz
  24.  
  25. push esi
  26. push eax
  27. int 80h
  28.  
  29. pop eax
  30. pop esi
  31. pop edx
  32. pop ecx
  33. pop ebx
  34. pop eax
  35.  
  36. cmp al, lf
  37. jne petla
  38.  
  39. ret
  40.  
  41. _wczytuj_zapisz:
  42. mov [bufor2+esi], al
  43. inc esi
  44. ret

Note that I am a complete newbie in assembly, so please try to explain my mistakes as precisely and as easy to understand as possible. I'd be happy if you correct the whole code, but I'll accept any help.

Thanks
-Marek
Last edited by venomxxl; Feb 2nd, 2009 at 12:45 pm.
Similar Threads
Reputation Points: 34
Solved Threads: 7
Junior Poster in Training
venomxxl is offline Offline
72 posts
since Jan 2009
Feb 2nd, 2009
0

Re: Getting input without newline

I believe the code listed below is giving you oyur segmentation fault.
When the branch is taken you are not poping your stack and the return address is burried under everything you pushed. You should change your label to. It should be something short but descriptive. A lot of people won't even take time to look at code if it is confusing.

Assembly Syntax (Toggle Plain Text)
  1. cmp al, lf
  2. jne _wczytuj_zapisz
Assembly Syntax (Toggle Plain Text)
  1. wczytuj_zapisz:
  2. mov [bufor2+esi], al
  3. inc
  4. esi ret
Reputation Points: 34
Solved Threads: 2
Light Poster
jt_murphree is offline Offline
40 posts
since Dec 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: Passing Variables
Next Thread in Assembly Forum Timeline: hex->ascii question





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


Follow us on Twitter


© 2011 DaniWeb® LLC