1

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:

  • I am writing directly to the text video memory, starting from address 0xb8000, using method described in this forum post.
  • I am using flat assembler 1.73.27 for Windows (fasm assembler).
  • I am testing my program on real computer (booting from usb), not an emulator.
  • I am not including any photos, because of this post.

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
Julian
  • 134
  • 11

1 Answers1

3

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)

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
vitsoft
  • 5,515
  • 1
  • 18
  • 31
  • 2
    Number `0xFF` is actually minus one, not minus 128. – ecm May 12 '21 at 09:20
  • Thanks, now the loop is working, but I get the same 8 colors twice instead of all 16 bios colors, but as I read in [wikipedia](https://en.wikipedia.org/wiki/BIOS_color_attributes), there are only 8 background colors with an exception to have 16 colors, of turning off the "blinking attribute", but as I'm not using any interrupts now, I will not change that. – Julian May 12 '21 at 09:45
  • 1
    @ecm Ooops, mea culpa. But the conclusion is still valid. @Julian I think using BIOS service is harmless. Just do `MOV AX,0x1003` and `INT 0x10` somewhere in the beginning, and you'll see the bright colors. – vitsoft May 12 '21 at 10:31
  • 1
    It's a good idea not to leave confusing mis-statements in your answers, regardless of the conclusion. I fixed that 0xff = -1 for you. – Peter Cordes May 12 '21 at 14:33
  • 2
    @vitsoft You also need to add `mov bx,0` before `int 0x10` (to set BH and BL to 0), See [_Ralf Brown's Interrupt List_ Int 10/AX=1003h](http://www.ctyme.com/intr/rb-0117.htm). – Julian May 12 '21 at 21:18