Help with End of Line character

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

Join Date: Oct 2009
Posts: 33
Reputation: Goalatio is an unknown quantity at this point 
Solved Threads: 0
Goalatio Goalatio is offline Offline
Light Poster

Help with End of Line character

 
0
  #1
Oct 29th, 2009
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.



  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, "$"
It's passion that drives me.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 143
Reputation: NotNull is an unknown quantity at this point 
Solved Threads: 14
NotNull's Avatar
NotNull NotNull is offline Offline
Junior Poster
 
0
  #2
Oct 30th, 2009
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.

  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.
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 33
Reputation: Goalatio is an unknown quantity at this point 
Solved Threads: 0
Goalatio Goalatio is offline Offline
Light Poster
 
0
  #3
Oct 30th, 2009
Hey, thanks.. But i've actually changed my code around a little, and this is not as much of a problem anymore.



  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.
It's passion that drives me.
Reply With Quote Quick reply to this message  
Reply

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




Views: 446 | Replies: 2
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC