; The MIT License (MIT) ; ; Copyright (c) 2026 pacman64 ; ; Permission is hereby granted, free of charge, to any person obtaining a copy ; of this software and associated documentation files (the "Software"), to deal ; in the Software without restriction, including without limitation the rights ; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ; copies of the Software, and to permit persons to whom the Software is ; furnished to do so, subject to the following conditions: ; ; The above copyright notice and this permission notice shall be included in ; all copies or substantial portions of the Software. ; ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ; SOFTWARE. ; To compile this app for linux/amd64, use the commands ; ; nasm -f elf64 -o cls-linux-amd64.o cls-linux-amd64.asm ; ld -n -s cls-linux-amd64.o -o cls ; cls ; ; CLear Screen ; ; Options, also with optional leading single or double dash ; ; h, help show this help message stdout equ 1 sys_write equ 1 sys_exit equ 60 section .rodata clear: db 0x1b, '[H', 0x1b, '[2J', 0x1b, '[3J' clear_length: equ $ - clear info: db 'cls [options...]', 10 db 10 db 'CLear Screen', 10 db 10 db 'Options, also with optional leading single or double dash', 10 db 10 db ' h, help show this help message', 10 info_length: equ $ - info section .text global _start _start: ; rcx = argc pop rcx cmp rcx, 1 je no_args ; skip argv[0] pop rbx ; get argv[1] pop rbx ; check/skip (optional) leading dash mov al, [rbx + 0] cmp al, '-' jne no_dashes inc rbx ; check/skip (optional) second leading dash mov al, [rbx + 0] cmp al, '-' jne single_dash inc rbx single_dash: no_dashes: ; check letter 'h' mov al, [rbx + 0] cmp al, 'h' jne no_args ; check null byte: `h` is a valid help-option mov al, [rbx + 1] cmp al, 0 je help ; check letter 'e' mov al, [rbx + 1] cmp al, 'e' jne no_args ; check letter 'l' mov al, [rbx + 2] cmp al, 'l' jne no_args ; check letter 'p' mov al, [rbx + 3] cmp al, 'p' jne no_args ; check null byte: `help` is also a valid help-option mov al, [rbx + 4] cmp al, 0 je help no_args: ; write(stdout, clear, clear_length) mov rax, sys_write mov rdi, stdout mov rsi, clear mov rdx, clear_length syscall quit: ; exit(0) mov rax, sys_exit mov rdi, 0 syscall help: ; write(stdout, info, info_length) mov rax, sys_write mov rdi, stdout mov rsi, info mov rdx, info_length syscall jmp quit