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

后端 未结 1 481
北恋
北恋 2021-01-19 01:22

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
             


        
相关标签:
1条回答
  • 2021-01-19 01:50

    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.

    0 讨论(0)
提交回复
热议问题