Home > other >  BIOS keyboard input only reading 2 letters, loop not working
BIOS keyboard input only reading 2 letters, loop not working

Time:02-15

I'm trying to make a code that is getting a letter and until it's not 'a' it will print the letter or other letter that have been entered but when I am running this code I can only enter 2 letters and after it, it doesn't give me to enter another letter. How can I fix it?

mov ah,0
    int 16h
Print:
    cmp al,'a'
    je Finish
    mov ah,2
    mov dl,al
    int 21h
    mov ah,1
    int 16h
    jmp Print
Finish:

CodePudding user response:

BIOS service Int 16/AH=01h checks if a key was pressed but you don't test ZeroFlag before jmp Print, that's why DOS service keeps printing. You should read the value only when a key was actually pressed:

loop1:mov ah,1h   ; CHECK FOR KEYSTROKE
      int 16h
      jz loop1    ; Jump if none pressed.
      mov ah,0h   ; GET KEYSTROKE to AL.
      int 16h
      mov ah,0Eh  ; TELETYPE OUTPUT.
      mov bh,0    ; Videopage number.
      int 10h     ; Print the character in AL.
      cmp al, 'a' ; Check if it was 'a'.
      jne loop1   ; If not, continue. Keybuffer is now empty.
      ret         ; Terminate COM program.

CodePudding user response:

These seem like they can't both be right:

    mov ah,0
    int 16h
    mov ah,1
    int 16h

They're both in the position for read character.

  • Related