Skip to content
Advertisement

Clean console on assembly

Is there anything similar to system("cls"); that exists on C for Assembly?

I’m using NASM to compile and I’m working on a x86 linux.

UPDATE 1: Here’s my modified code to integrate sugestion:

section .data

%define SC_write        4   ; eax = write(ebx, ecx, edx)
%define ESC         033q


MAX_PALAVRA equ 40

(...)

num1        dd  0
num2        dd  0
result      dd  0
tamstr      dd  0

section .bss
strnum      resb    MAX_PALAVRA
opc     resb    2

section .text

global _start

   refresh:
        mov eax, ESC | ('[' << 8) | (BOTTOMROW << 16)
        stosd
        mov eax, ';0H' | (SI << 24)
        stosd
        mov edx, edi
        mov edi, outbuf
        mov ecx, edi
        sub edx, ecx
        xor ebx, ebx
        lea eax, [byte ebx + SC_write]
        inc ebx
        int 0x80

_start:

mov eax, ds
mov es, eax

Cheers

Advertisement

Answer

To imitate the terminals clear command have in a .data section:

ClearTerm: db   27,"[H",27,"[2J"    ; <ESC> [H <ESC> [2J
CLEARLEN   equ  $-ClearTerm         ; Length of term clear string

then whenever you want to clear the terminal do:

mov eax, 4                          ; Specify sys_write call
mov ebx, 1                          ; Specify File Descriptor 1: Stdout
mov ecx, ClearTerm                  ; Pass offset of terminal control string
mov edx, CLEARLEN                   ; Pass the length of terminal control string
int 80h
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement