NASM Forum > Example Code
Command 'Clear' (Clear the gnu/linux console)
fredericopissarra:
--- Quote from: Ferran on September 06, 2020, 11:47:18 AM ---P.D: Today we've grandmother's lasagna
--- End quote ---
Ahhhhhh... please, don't tempt me! ;D
Ferran:
All right, here we go again after the feast.
Finally i clean the screen without using the printf C instruction. Pure Assembly with NASM only. I was impressed with how easy it was to adapt federicopissarra's code and how well everything worked.
well, if you wants clear screen with printf C instruction see it above, but if you don't like this option, you could to use the next code:
--- Code: ---
; -----------------------------------------------------------------------
; cls.asm (ver.2.0)
; Clear the screen & display a sympa text
; (pure GNU/linux assembly x80_64 code with NASM)
;
; Compile: nasm -f elf64 cls.asm
; link: ld -s -o cls cls.o
; run: ./cls
;
; Auhors: Ferran & federicopisarra (NASM forum members)
; -----------------------------------------------------------------------
bits 64
segment .rodata
msg:
db `\033[2J\033[H`, 0 ; ANSI code for clear screen
db `Hello, NASM members!`,10,0 ; Sympa message
msglen equ $ - msg ; Length of msg
segment .text
global _start
_start:
; ------- clear screen ------------------
mov rax,1 ; 1 = sys_write number
mov rdi,1 ; 1 = STDOUT file descriptor
mov rsi,msg ; input the ANSI code from msg
mov rdx,msglen ; input the length of msg
syscall ; Kernel calls
; ------- print message -----------------
mov rax,1 ; 1 = sys_write number
mov rdi,1 ; 1 = STDOUT file descriptor
mov rsi,msg ; message's buffer
mov rdx,msglen ; input the length
syscall ; Kernel calls
; ------- end program ------------------
mov eax, 60
xor edi, edi
syscall
--- End code ---
Enjoy it !
Navigation
[0] Message Index
[*] Previous page
Go to full version