Search code examples
assemblyx86keyboardnasm

How to show symbol with 16h BIOS


This program has to get and show the symbol. But instead I have this strange array of strange symbols org 100h

org 100h

section .text
_start:
    
    mov ah, 0     
    int 16h         

    mov [znak], al

    mov ah, 9   
    mov dx, znak     
    int 21h        

    mov ah, 4Ch         
    int 21h         

section .data
    znak db 0        

Output

I tried to change syntax, but it doesnt work, or I just cant see that


Solution

  • Instead of using the DOS.PrintString function 09h (that requires the string to be terminated by a $ character), use the DOS.PrintCharacter function 02h:

    mov  ah, 00h   ; BIOS.GetKeystroke
    int  16h       ; -> AX
    mov  dl, al
    mov  ah, 02h   ; DOS.PrintCharacter     
    int  21h       ; -> (AL)
    mov  ax, 4C00h ; DOS.Terminate        
    int  21h
    

    Still want to use the DOS.PrintString function 09h?
    Then

    • make sure to setup the DS segment register
    • terminate the string by a $ character
        mov  ax, @data
        mov  ds, ax
        mov  ah, 00h   ; BIOS.GetKeystroke
        int  16h       ; -> AX
        mov  [znak], al
        mov  dx, znak
        mov  ah, 09h   ; DOS.PrintString     
        int  21h       ; -> (AL)
        mov  ax, 4C00h ; DOS.Terminate        
        int  21h
    
    section .data
        znak db 0, '$'