I'm pretty new at assembly code, I'm using DOS debugging. I've gotten an Hello World program to work, Then I took it one tiny step further and used int 16,0 to stop and wait for a keystroke and then Hello World pops up. Now what I want to be able to do is have a certain key (y) to make the program continue. When the program is run I want it to look like this...
c:hellow.com
"Are you sure you want to continue? (y/n)"
if "y" then...
"Hello World"
if "n" then...
"program terminated" (or somthing like that...)
Comments
: gotten an Hello World program to work, Then I took it one tiny step
: further and used int 16,0 to stop and wait for a keystroke and then
: Hello World pops up. Now what I want to be able to do is have a
: certain key (y) to make the program continue. When the program is
: run I want it to look like this...
:
: c:hellow.com
: "Are you sure you want to continue? (y/n)"
: if "y" then...
: "Hello World"
: if "n" then...
: "program terminated" (or somthing like that...)
:
:
You'll have to wait for a character, then read it and compare it to 'Y' (and perhaps also to 'y').
To check if the character is 'Y', use the following snippet of code:
[code]
WaitForCharacter:
*** Your wait for a character code here ***
*** After this piece of code, AL must ***
*** contain the entered key ***
; AL contains the character code
cmp al, 59h ;AL == 'Y'?
je Continue
cmp al, 79h ;AL == 'y'?
je Continue
jmp WaitForCharacter ;Or possible first print "Bad input" and then jmp
Continue:
;Rest of the code after the Y prompt goes here
[/code]
Best Regards,
Richard
The way I see it... Well, it's all pretty blurry
Int 16h, function 0 returns an ASCII character. The good thing about ASCII is that it's very simple to convert between lower case and upper case - simply toggle the fifth bit. So to easily check for both 'y' and 'Y', set the 5th bit, after that you only need to check for the lower-case letters:
[code]
WaitForCharacter:
mov ah, 0
int 16h
or al, 32 ; Set the fifth bit (1 << 5 == 32)
cmp al, 'y'
je PrintHello
cmp al, 'n'
je PrintSomething
jmp WaitForCharacter
[/code]
Just in case you didn't know, [b]je[/b] is a conditional jump, whether or not the jump is taken depends on the condition set by the [b]cmp[/b] instruction. Read more about it here:
http://www.geocities.com/SiliconValley/Park/3230/x86asm/asml1006.html
Good luck, mates!