1.

Solve : A program in Debug??

Answer»

(Posting this because I couldn't get a straight answer from google, so I've written up how I did it incase anyone ELSE runs into the same problem)

While using my palmtop (HP200LX!!), which runs MS-DOS 5.0, i decided i needed a batch file to ask a yes/no question and get an answer. Unfortunately, under MS-DOS 5.0, there is no way to accommodate this. There wasn't even the program 'CHOICE' on it. While flicking through my manual, I saw something that said
"A very common form of use of Errorlevel depends on a short program not usually found on MS-DOS DISKS called YN. This returns an errorlevel of 1 if the n key is pressed when the program runs."
I didn't have this program, so i decided to make one myself using something I'd never used before: Debug.
After a bit of googling, and looking on


i had my source code ready!
Code: [Select]0100 mov ah, 01 ; keyboard input subprogram. all the examples have an h after 01, is used, but in debug remove it or else face an error.

0102 int 21h ; read character into al. Removal of h not necessary here

0104 cmp al, 79 ; compare al with the hex value of lowercase y, 79

0106 jne 010D ; jump if they're different to line 010D

0108 mov ax, 4c00 ; return to ms-dos. Errorlevel 0

010B int 21h

010D mov ax, 4c01 ; return to ms-dos. Errorlevel 1

0110 int 21h
The next step was to enter it into debug. Using instructions from
I entered the code, using these keystrokes.

Code: [Select]C:\>DEBUG
-N YN.COM
-A
0100 mov ah, 01
0102 int 21h
0104 cmp al, 79
0106 jne 010D
0108 mov ax, 4c00
010B int 21h
010D mov ax, 4c01
0110 int 21h
0112
-RCX
CX0000
:10
-W
00010 Bytes Written
-Q
C:\>

Now, my program was ready!

Note: RCX and its 10 input was used to SET the number of bytes that needed to be written. (Hexadecimal 0110 - 0100 = 10) The write command will not function without RCX being used first.

Heres the example i used:

Code: [Select]@echo off
echo Press y or n...
yn
echo.
if errorlevel == 1 goto n
if errorlevel == 0 goto y
:y
echo You pressed Y!
goto end
:n
echo You pressed N...
:end
Anyways, if you ever need a YN substitute i hope this helps! Cheers XDI like it.
It should work in 32 bit mode . There are no memory references.
Just standard calls into the OS.

JNE is a relative jump inside the code area. But you can even eliminate that... but let's not go there. You have done enough!

Simple is beautiful. Quote from: Geek-9pm on December 23, 2009, 05:15:01 PM
I like it.
It should work in 32 bit mode . There are no memory references.
Just standard calls into the OS.


Well yeah, once it's properly compiled into a PE executable rather then a COM file, it can run in 32-bit mode.So I couldn't try and run this as it is in windows?I tried it, made it using debug again (in the command shell in xp) and it made it and all, but it doesn't seem to be setting the errorlevel correctly, either that or the batch program i made to use it isn't working properly. Otherwise, it works exactly the same as it does on my palmtop.Ok, I've worked out that the program is not returning the correct errorlevel, so I don't KNOW how to do that in XP... doesn't really matter though, i'd just use "choice" under XP.Ok, something very weird just happened.
Every time I ran the above program in ms-dos, it ran slower and slower. Soon, if I pressed 'N' the program would crash. I decompiled it using debug and i saw two things:
1. JNE had been changed to JNZ.
2. The second int 21 (line 0110) had changed to a series of 6 commands, things like "add [si,al]" (not sure about that though.) I don't know why.
The last time I ran the program it crashed altogether, freezing my palmtop. I had to flash its memory. What went wrong???


Discussion

No Comment Found