Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: A program in Debug?  (Read 5782 times)

0 Members and 1 Guest are viewing this topic.

Bones92

    Topic Starter


    Hopeful

  • Website Designer and Microcontroller Programmer
  • Thanked: 3
    • PIC Programming New Zealand
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
A program in Debug?
« on: December 23, 2009, 04:56:39 PM »
(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 XD
« Last Edit: December 23, 2009, 11:46:46 PM by Bones92 »

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: A program in Debug?
« Reply #1 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. 

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.  8)

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: A program in Debug?
« Reply #2 on: December 23, 2009, 07:36:57 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.
I was trying to dereference Null Pointers before it was cool.

Bones92

    Topic Starter


    Hopeful

  • Website Designer and Microcontroller Programmer
  • Thanked: 3
    • PIC Programming New Zealand
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: A program in Debug?
« Reply #3 on: December 23, 2009, 11:37:32 PM »
So I couldn't try and run this as it is in windows?

Bones92

    Topic Starter


    Hopeful

  • Website Designer and Microcontroller Programmer
  • Thanked: 3
    • PIC Programming New Zealand
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: A program in Debug?
« Reply #4 on: December 23, 2009, 11:50:30 PM »
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.

Bones92

    Topic Starter


    Hopeful

  • Website Designer and Microcontroller Programmer
  • Thanked: 3
    • PIC Programming New Zealand
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: A program in Debug?
« Reply #5 on: December 24, 2009, 12:04:39 AM »
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.

Bones92

    Topic Starter


    Hopeful

  • Website Designer and Microcontroller Programmer
  • Thanked: 3
    • PIC Programming New Zealand
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: A program in Debug?
« Reply #6 on: December 24, 2009, 08:34:26 PM »
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???