tags:

views:

452

answers:

3

the following script works fine if I type it line-by-line in debug. When I copy it to a file called script.txt, it hangs up after "enter 3 numbers". I run it like so:

D:>debug < script.txt

the file is:

a
mov cx, 3
jmp 0119
db 0d,0a,"enter 3 numbers",0d,0a,"$"
mov dx, 0105
mov ah, 09
int 21h
mov ah, 01
int 21h
and al, 0f
add bl, al
mov dl, 0a
mov ah, 02
int 21h
loop 0120
jmp 013a
db 0d,0a,"sum: ","$"
mov dx,0132
mov ah, 09
int 21h
or bl, 30
mov dl, bl
mov ah, 02
int 21h
mov ax, 4c00
int 21h

g

what am I doing wrong? Any hints or links appreciated. keith

+2  A: 

You're telling debug to take all its input from script.txt, so when your program tries to read the numbers from standard input, it's reading from the file, not from the console.

jdigital
+5  A: 

You redirected input to debug to be from the script, not from the console, so debug is never receiving your keystrokes The program is hanging, waiting for more data to come in from the script.

If you put 3 numbers after the 'g' in the script, it should continue

Michael
thanks for the explanation, jdigital, Michael, your suggestion works, but can I do both? I want the console user to provide the input, but I don't want them to have to type the entire code to run it again. Can the script redirect back to the console for input?
Keith
I don't believe there is a straightforward way to . . . you might be able to reopen CON and replace the stdin handle with that somehow, but I've no idea - I haven't coded for DOS since the Clinton administration
Michael
Forget about that last comment of mine!
jdigital
Try reading directly from the keyboard; for example, int 16 function 0
jdigital
jdigital, thanks that works! (changed line 8: mov ah,0 line 9: int 16h) now trying to make it echo so you can see the inputs...
Keith
A: 

good explanations. Thanks Michael, your suggestion worked, but I want to get input from the console and still run a script so I don't have to type the entire code to run it again. Thanks jdigital!, that's the answer I'm looking for. Using your hints (in comments above) I was able to make a simple working script:

a
mov cx, 3
jmp 0119
db 0d,0a,"enter 3 numbers",0d,0a,"$"
mov dx, 0105
mov ah, 09
int 21h
mov ah, 0     ; for console input
int 16h       ; use int 16h function 0.
mov dl,al     ; echo input to screen
mov ah,02
int 21h
and al, 0f
add bl, al
mov dl, 0a
mov ah, 02
int 21h
loop 0120
jmp 0140
db 0d,0a,"sum: ","$"
mov dx,0138
mov ah, 09
int 21h
or bl, 30
mov dl, bl
mov ah, 02
int 21h
mov ax, 4c00
int 21h

g
Keith