Home > Blockchain >  masm not taking input after first input
masm not taking input after first input

Time:11-03

whenever i run this code, the program only takes the first input from me and then send a grabage value in the 2nd input itself and then prints a totally random garbage value

.model small
.stack 100h
.data

.code 
main proc

mov ah , 1      ;input 1
int 21h

mov bl,al

mov al , 1        ;input 2
int 21h

add bl , al

sub bl , 48

mov dl , bl

mov ah , 2
int 21h

mov ah , 4ch
int 21h

main endp
end main

ive tried changing the mov al , 1 to mov ah , 1 to take the input but that doesnt work either

CodePudding user response:

This looks like an adder of two single digits.

READ CHARACTER FROM STANDARD INPUT doesn't wait for Enter. Apparently when you tried 3 4 you pressed 3 Enter 4 Enter and your ;input 2 returned 0Dh in AL, which is not the second decimal digit.

Try to press both digits without Enter, it should look like 347.

You can omit the line mov al , 1 ;input 2 completely, the interrupt doesn't clobber AH=1 from previous input, but it overwrites AL with the second input character.

CodePudding user response:

mov al , 1      ;input 2
int 21h

You got away with this typo on AL vs AH because the AH register still held the value 01h from before.


Although the pressing of Enter after each digit will indeed mess with the calculation in your program, it would also mean that you would be inputting that second digit and its accompanying Enter long after the program had terminated! The second digit would have appeared at the DOS prompt.

Example: 1Enter2Enter

C:\>prog
♫
C:\>2
Bad command or Filename

My best guess is that you probably are using the numeric keypad but without the NumLock lit.
Under these circumstances, if you press eg. 1 it is actually End, and the DOS.GetKeyboardInputWithEcho function 01h will return a zero in AL and a second invokation of the same function will return the scancode also in AL.

Example: 12

C:\>prog
 O▼
C:\>

The 1st int 21h returns 0 and echoes a " "
The 2nd int 21h returns 4Fh and echoes an uppercase "O"
The program calculates 0 4Fh - 48 = 1Fh and displays "▼"
Without NumLock lit, 2 will actually be which does not show at the DOS prompt

  • Related