'Unable to print correct character using INT 10H
I have recently tried to make a simple bootloader to learn more about the 8086 Intel CPU. Along the way, I needed a way to print characters to screen. However, when I try to execute the following instructions, I get 'b' instead of 'a' in the QEMU output console.
[bits 16]
[org 0x7c00]
%macro read_sector 6
pusha
mov ah, 02H
mov dl, %1
mov dh, %2
mov ch, %3
mov cl, %4
mov al, %5
mov bx, %6
int 13H
jc error
popa
%endmacro%
%macro get_cursor_pos 0
push ax
push bx
mov ah, 03H
mov bh, 0
int 10H
pop ax
pop bx
%endmacro%
%macro set_cursor_pos 0
pusha
mov ah, 02H
mov bh, 0
int 10H
popa
%endmacro%
mov bp, 0x89B8
mov sp, bp
mov al, 97
loop:
mov ah, 0AH
mov bh, 0
mov cx, 1
int 10H
inc al
;cmp al, 98
;jl loop
end:
hlt
print_ch:
pusha
mov ah, 0AH
mov bh, 0
mov cx, 1
int 10H
; cmp al, 10
; je handle_newline
; get_cursor_pos modifies registers dh, dl
; get_cursor_pos
; inc dl
; set_cursor_pos
end_putch:
popa
ret
error:
hlt
handle_newline:
add dh, 1
mov dl, 0
set_cursor_pos
jmp end_putch
times 510 - ($ - $$) db 0
dw 0xaa55
But, If I add a jmp $ before inc al, QEMU console shows 'a' as output.
I have no idea about any mistakes in my code. Any help is welcome!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
