; 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 fail-linux-amd64.o fail-linux-amd64.asm ; ld -n -s fail-linux-amd64.o -o fail ; fail [code...] ; ; Do nothing but quit with the status code/number given as an argument; if no ; status code/number was given, quit using code 1 by default. If given 0 for ; the status code, it will paradoxically succeed, as 0 is the success code. sys_exit equ 60 section .text global _start _start: ; rcx = argc pop rcx ; just quit with the default code, if no arguments were given cmp rcx, 1 mov rdx, 1 je quit ; skip argv[0] pop rbx ; get argv[1] pop rbx ; an empty string fails to parse: if so, quit with the default code mov al, [rbx] cmp al, 0 je bad_code mov rdx, 0 mov rax, 0 parse_code: mov al, [rbx] cmp al, 0 je quit cmp al, '0' jl bad_code cmp al, '9' jg bad_code imul rdx, 10 sub al, '0' add rdx, rax inc rbx jmp parse_code bad_code: mov rdx, 1 quit: ; exit(rdx) mov rax, sys_exit mov rdi, rdx syscall