Can't clear entire screen in 16-bit real mode Assembly
Asked Answered
I

1

5

I'm trying to clear the screen in my simple 16-bit real mode operating system. Below is the code:

clearScreen:
    pusha

    mov ah, 0x7
    mov al, 0
    int 0x10

    popa
    ret

I read that setting al to 0 and calling the scroll screen interrupt would clean the screen but it only seems to change the colour of the first line to grey.

Thanks to anyone who can explain why this is not working.

Incompletion answered 9/4, 2014 at 20:8 Comment(0)
F
9

The problem is that int 0x10 function 0x07 takes more parameters than you've given. Specifically,

  • AH = 07 = scroll window down
  • AL = number of lines to scroll (or 0 for all)
  • BH = attribute to write to blank lines
  • CH, CL = row, column of window upper left corner
  • DH, DL = row, column of window lower right corner

Unless you set them, they'll just contain whatever happens to be there from previous instructions, which is very unlikely to be what you want!

So assuming that you're using the standard 80x25 character screen, your code should instead be written like this:

clearScreen:
    pusha

    mov ax, 0x0700  ; function 07, AL=0 means scroll whole window
    mov bh, 0x07    ; character attribute = white on black
    mov cx, 0x0000  ; row = 0, col = 0
    mov dx, 0x184f  ; row = 24 (0x18), col = 79 (0x4f)
    int 0x10        ; call BIOS video interrupt

    popa
    ret

See this version of the famous Ralf Brown interrupt list for more details.

Fernferna answered 9/4, 2014 at 20:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.