944,014 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Marked Solved
  • Views: 1466
  • Assembly RSS
Oct 29th, 2009
0

Help with End of Line character

Expand Post »
Hey all, I've been working on this little program in NASM 16 bit assembly, under a windows operating system.

It works, I just have a problem. If you don't pass it any arguments, it fails to see that there is an end of line character.

You pass arguments as..
INKEY a
and it responds "Press a to continue . . ."

If you don't pass anything, by just saying
INKEY
then it responds "Press to continue . . ." and will not exit unless I "End now"

Here's my code, any nudge in the right direction would be appreciated.


NOTE: I am using my own library for this, so if you do not recognize some commands, that is why.. Hopefuly you can see the basic idea of what's happening though, I always try to comment on every line.



Assembly Syntax (Toggle Plain Text)
  1. [org 0100h]
  2. %include "Library.asm"
  3.  
  4. [section .text]
  5.  
  6. string msg1 ;Display "Press"
  7. arg ;Grab the arguments off the stack
  8. mov si,bx ;LODSB!
  9. jmp GRABKEY ;Get the FIRST argument
  10.  
  11. GRABKEY:
  12. lodsb ;Advance ONE character in SI
  13. cmp al,0d ;Check if End of Line
  14. je INVALID ;If it is, exit with ERRORLEVEL 0
  15. mov [character],al ;Store this character in a word
  16. string character ;Display the character
  17. string msg2 ;Display "to continue. . ."
  18. jmp INPUTKEY ;Start asking for the key
  19.  
  20. INPUTKEY:
  21. input [character] ;Use library procedure to check\compare AL
  22. ;For the key passed as an argument
  23. je VALIDPRESS ;If it's equal, we can leave!
  24. jmp INPUTKEY ;Loop if it's not equal
  25.  
  26. INVALID:
  27. exit 0
  28.  
  29. VALIDPRESS:
  30. exit 1
  31.  
  32. [section .data]
  33.  
  34. character dw 0, "$"
  35. msg1 db "Press ", "$"
  36. msg2 db "to continue . . .", 13, 10, "$"
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Goalatio is offline Offline
72 posts
since Oct 2009
Oct 30th, 2009
0
Re: Help with End of Line character
On the MS-DOS system functions for input I usually
use, atimes a Carriage-Return character is at the
end of the buffer lest the maximum count of
characters is met. 21/3F
0xd ends the input, that is, from the
console.
0D or 13 the Carriage Return is the end of line character.

Read a byte from a string pointed to by source index into
al, increment si to advance to the offset of the next character
in the string.

Assembly Syntax (Toggle Plain Text)
  1. CLD ; make DF zero
  2. MOV SI, 200h
  3. LODSB ; get byte at DS:SI, after execution SI=201h
  4. CMP AL, 66h ; did we retrieve the MARK???
  5. JZ EXITER

Acidio hex burner is very pleased to have these inverted bits.
A text-file is nothing but a string or array of bytes,
in which every "line" of the file is suffixed by an ending
carriage return character, which indicates end of line.

Thats why, "I am hated", more about inverted words:
radio static beat inverted.
The interdimensional vortex: REIGN!!!! engulfed by nothingness.

Working well for a new-tomorrow.
Have a good day.
Last edited by NotNull; Oct 30th, 2009 at 1:03 am.
Reputation Points: 36
Solved Threads: 19
Junior Poster
NotNull is offline Offline
198 posts
since Oct 2008
Oct 30th, 2009
0
Re: Help with End of Line character
Hey, thanks.. But i've actually changed my code around a little, and this is not as much of a problem anymore.



Assembly Syntax (Toggle Plain Text)
  1. [org 0100h]
  2. %include "Library.asm"
  3.  
  4. [section .text]
  5.  
  6. arg ;Grab the arguments off the stack
  7. mov si,bx ;LODSB
  8. jmp GRABKEY ;Get the FIRST argument
  9.  
  10. GRABKEY:
  11. lodsb ;Advance ONE character in SI
  12. cmp al,2dh ;Check if a "-" (Hide text)
  13. je GRABKEY2 ;If equal, jump to new procedure
  14. mov [character],al ;Store this character in a word
  15. jmp DISPLAYTEXT ;Start asking for the key
  16.  
  17. GRABKEY2:
  18. lodsb ;Advance one MORE character in SI
  19. ;This gets the actual character to display
  20. mov [character],al ;Store the character in a word
  21. jmp INPUTKEY
  22.  
  23.  
  24. DISPLAYTEXT:
  25. string msg1 ;Display "Press"
  26. string character ;Display the FIRST letter passed as an argument
  27. string msg2 ;Display "to continue . . ."
  28. jmp INPUTKEY
  29.  
  30. INPUTKEY:
  31. input [character] ;Use library procedure to check\compare AL
  32. ;For the key passed as an argument
  33. je VALIDPRESS ;If it's equal, we can leave!
  34. cmp al,1bh ;Check if ESCAPE is pressed
  35. je INVALID ;Exit if it was pressed
  36. jmp INPUTKEY ;Loop if it's not equal
  37.  
  38. INVALID:
  39. exit 0
  40.  
  41. VALIDPRESS:
  42. exit 1
  43.  
  44. [section .data]
  45.  
  46. character dw 0, "$"
  47. msg1 db "Press ", "$"
  48. msg2 db "to continue . . .", 13, 10, "$"

You see, I changed how most of it works, and made it so you can press ESCAPE as a "Backup" way to make it exit. I also made it so you can put a "-" sign before your argument to hide the text.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Goalatio is offline Offline
72 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: x86 32-bit registers
Next Thread in Assembly Forum Timeline: TSR Help...





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


Follow us on Twitter


© 2011 DaniWeb® LLC