I would like to make a simple bootloader, that writes all the background colors to next lines on the screen.
The problem is, that it only changes the color of the first line to black and the second line to blue, while it should display all 16 colors. I think, that there is something wrong with loop1:, but I don't know what.
Useful informations:
My code (fasm assembly):
format binary
use16
org 0x7c00
mov ax,0xb800
mov es,ax
mov bx,0
mov al,0
mov ah,0x0f
mov cx,160
loop1:
call procedure1
add ax,0x1000
add cx,160
cmp ah,0xff
jl loop1
call procedure1
mov cx,4000
mov ah,0x0f
call procedure1
jmp $
procedure1:
mov word [es:bx],ax
add bx,2
cmp bx,cx
jl procedure1
ret
times 510-($-$$) db 0
dw 0xaa55
You are leaving loop1
when ah
is not less than 0xff
anymore.
The term less/greater is used in x86 assembly when signed numbers are compared.
Number 0xff
treated as signed 8bit integer has the value -1
and ah
as signed byte (-128..+127), starts at 0x0f + 0x10 = 0x1f
. And 31 < -1
is false on the first iteration, so loop1
is abandoned after the first call procedure1
.
When comparing unsigned numbers we use term below/above.
Instead of jl loop1
use jb loop1
. Similary in procedure1:
replace jl procedure1
with jb procedure1
. (https://www.felixcloutier.com/x86/jcc)