Getting input without newline

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

Join Date: Jan 2009
Posts: 16
Reputation: venomxxl is an unknown quantity at this point 
Solved Threads: 2
venomxxl's Avatar
venomxxl venomxxl is offline Offline
Newbie Poster

Getting input without newline

 
0
  #1
Feb 2nd, 2009
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
  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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 26
Reputation: jt_murphree is an unknown quantity at this point 
Solved Threads: 1
jt_murphree's Avatar
jt_murphree jt_murphree is offline Offline
Light Poster

Re: Getting input without newline

 
0
  #2
Feb 2nd, 2009
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.

  1. cmp al, lf
  2. jne _wczytuj_zapisz
  1. wczytuj_zapisz:
  2. mov [bufor2+esi], al
  3. inc
  4. esi ret
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



Tag cloud for Assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC