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.

[org 0100h]
%include "Library.asm"

[section .text]

string msg1		;Display "Press"
arg			;Grab the arguments off the stack
mov si,bx		;LODSB!
jmp GRABKEY		;Get the FIRST argument

GRABKEY:
lodsb			;Advance ONE character in SI
cmp al,0d		;Check if End of Line
je INVALID		;If it is, exit with ERRORLEVEL 0
mov [character],al	;Store this character in a word
string character	;Display the character
string msg2		;Display "to continue. . ."
jmp INPUTKEY		;Start asking for the key

INPUTKEY:
input [character]	;Use library procedure to check\compare AL
			;For the key passed as an argument
je VALIDPRESS		;If it's equal, we can leave!
jmp INPUTKEY		;Loop if it's not equal

INVALID:
exit 0

VALIDPRESS:
exit 1

[section .data]

character dw 0, "$"
msg1 db "Press ", "$"
msg2 db "to continue . . .", 13, 10, "$"

Dani AI

Generated

A more robust way to detect "no arguments" in a small DOS .COM utility is to read the command-tail length stored in the Program Segment Prefix (PSP) instead of scanning for the terminator character. That length byte (PSP:80h) tells you exactly how many characters were supplied; when it is zero you can take the no-argument path immediately (avoid waiting for a key that will never match). If your program might not be a simple .COM or DS does not point at the PSP, obtain the PSP segment with INT 21h/AH=62h and read the length there. Also trim any leading space characters and support quoted arguments so a single quoted-empty string does not look like "no args." (pcjs.org)

Example (compact, .COM-style check):

; org 100h
mov al, [80h]      ; read command-tail length from PSP
or  al, al
jz  .NoArgs        ; jump if zero
; ...process arguments starting at 81h...

If you need to work from an arbitrary segment, call INT 21h/AH=62h to get the PSP segment in BX, set DS (or use segment overrides) and then inspect offset 80h. This approach avoids edge cases that scanning-only code can miss and complements 's point about the command-tail layout while giving a reliable way to distinguish "no argument" from an argument that happens to be empty or hidden. (pcjs.org)

Recommended Answers

All 2 Replies

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.

CLD ; make DF zero
MOV SI, 200h
LODSB ; get byte at DS:SI, after execution SI=201h
CMP AL, 66h ; did we retrieve the MARK???
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.

Hey, thanks.. But i've actually changed my code around a little, and this is not as much of a problem anymore.

[org 0100h]
%include "Library.asm"

[section .text]

arg			;Grab the arguments off the stack
mov si,bx		;LODSB
jmp GRABKEY		;Get the FIRST argument

GRABKEY:
lodsb			;Advance ONE character in SI
cmp al,2dh		;Check if a "-" (Hide text)
je GRABKEY2		;If equal, jump to new procedure
mov [character],al	;Store this character in a word
jmp DISPLAYTEXT		;Start asking for the key

GRABKEY2:
lodsb			;Advance one MORE character in SI
			;This gets the actual character to display
mov [character],al	;Store the character in a word
jmp INPUTKEY


DISPLAYTEXT:
string msg1		;Display "Press"
string character	;Display the FIRST letter passed as an argument
string msg2		;Display "to continue . . ."
jmp INPUTKEY

INPUTKEY:
input [character]	;Use library procedure to check\compare AL
			;For the key passed as an argument
je VALIDPRESS		;If it's equal, we can leave!
cmp al,1bh		;Check if ESCAPE is pressed
je INVALID		;Exit if it was pressed
jmp INPUTKEY		;Loop if it's not equal

INVALID:
exit 0

VALIDPRESS:
exit 1

[section .data]

character dw 0, "$"
msg1 db "Press ", "$"
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.