Home > Back-end >  How to print inputted text in x86 assembly
How to print inputted text in x86 assembly

Time:07-14

I am working on a little assembly project, and I'm running into some issues displaying inputted text. Here's the code I have so far:

[org 0x7c00]

mov ah, 0
int 0x16
mov al, [key]
int 0x10

key:
    db 0

jmp $

times 510-($-$$) db 0
db 0x55, 0xaa

I'm pretty sure I'm just doing operations in the wrong order, though I don't know in which way. For a bit more context, I'm using NASM to convert to a .bin, and QEMU to run the program.

CodePudding user response:

The mov ah, 0 int 0x16 instructions wait for a keypress.
To store the result you get in the AX register, you need to write mov [key], al with the destination as the leftmost operand.

If you want to output the character then just having int 0x10 is not enough! You need to specify a function number and possibly also some additional parameters.

mov bx, 0007h   ; DisplayPage 0, ColorAttribute 7
mov al, [key]   ; ASCII code
mov ah, 0Eh     ; BIOS.Teletype
int 0x10

Very important 1

Because you address a memory variable at key, you need to have the DS segment register setup correctly. In accordance with the [org 0x7c00] directive, you need DS=0.
Write the following first:

[org 0x7C00]
xor ax, ax
mov ds, ax

Very important 2

The jmp $ instruction must be on the execution path. You have placed it below the key data. Remember that data is not to be executed.

jmp $
key:
    db 0
times 510-($-$$) db 0
db 0x55, 0xaa
  • Related