Skip to content
Advertisement

How to clear screen on protected mode

I’m using NASM for Linux and I’d like know how, in the protected mode, you can clear the screen. I found a solution using the int10h, but on the protected mode I can only use int80h. Thanks in advance.

Advertisement

Answer

You can write x1b[2J to the standard output so the terminal get cleared and fix the cursor position using x1b[H, for example in nasm:

global  _start

section .data
  clr    db 0x1b, "[2J", 0x1b, "[H"
  clrlen equ $ - clr

section .text
_start:
  mov eax, 4
  mov ebx, 1
  mov ecx, clr
  mov edx, clrlen
  int 0x80

  mov eax, 1
  mov ebx, 0
  int 0x80

for gnu assembler:

.globl _start

.data
  clr     : .ascii "x1b[2Jx1b[H"
  clrlen  =  . - clr

.text
_start:
  movl $4, %eax
  movl $1, %ebx
  movl $clr, %ecx
  movl $clrlen, %edx
  int $0x80

  movl $1, %eax
  movl $0, %ebx
  int $0x80
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement