lundi 25 mai 2020

MASM doesn't pause on ReadString and IF block is not being executed

1.) I am supposed to write a program that generates the following output:

Enter a digit: 8

You entered a digit.

Do you want to run the program again (Y or N)? Y
(The user enters Y, so the screen clears and the programs runs again.)

Enter a digit: Q You did not enter a digit.

Do you want to run the program again (Y or N)? N
(The user enters N, so the .REPEAT - .UNTIL loop ends.

2.) Use a block-structured .IF statement, or use jump instructions (I use both)

3.) Use a .REPEAT - .UNTIL Directive to allow the user to run the program repeatedly. - If the user enters Y, then the screen clears and the program runs again.

However the problem I am running into is that my output doubles up on the consoles both the digitprompt and the runagain, meaning that it skips all the way to the end of the program bypassing the IF blocks along the way. How can I fix this please? I want it to pause appropriately on the way, and no, "WaitMsg" won't work here because I'm anticipating an input. Here is what the console looks like with a dumpregs wedged in-between the perpetrators:

Enter a digit:
  EAX=00000000  EBX=002E3000  ECX=0040100A  EDX=00406010
  ESI=0040100A  EDI=0040100A  EBP=0019FF80  ESP=0019FF74
  EIP=00403683  EFL=00000246  CF=0  SF=0  ZF=1  OF=0  AF=0  PF=1

Do you want to run the program again (Y or N)? _   

ABOVE IS THE ERROR...

INCLUDE Irvine32.inc

.data
digitprompt BYTE "Enter a digit: ",0
userDig db 64 dup(?),0
runagain BYTE "Do you want to run the program again (Y or N)? ",0
characterans BYTE ?,0
digit BYTE "You entered a digit.",0
notdigit BYTE "You did not enter a digit.",0


.code
main PROC
.REPEAT
call Clrscr

mov edx, 0
mov edx, OFFSET digitprompt
call WriteString
mov edx, OFFSET userDig
call ReadString

.IF edx >= 0 
    jmp L1 
.ELSE
    jmp isNotDig
.ENDIF

L1: 
.IF edx <= 9 
    jmp isDig
.ELSE
    jmp isNotDig
.ENDIF

isDig: mov edx, OFFSET digit
jmp L2

isNotDig: mov edx, OFFSET notdigit

L2:
mov edx, OFFSET runagain
call WriteString
call ReadChar
mov characterans, al

.UNTIL characterans == 'N'


exit
main ENDP
END main

Aucun commentaire:

Enregistrer un commentaire