This commit is contained in:
Kimapr 2024-04-03 17:18:26 +05:00
commit c2c4447632
3 changed files with 95 additions and 0 deletions

9
build Executable file
View file

@ -0,0 +1,9 @@
#!/bin/sh
#~/stuff/zig/zig cc -static -nostdlib -nodefaultlibs meow.s -o amogus || exit
#gcc -static -nostdlib -nodefaultlibs meow.s -o amogus.o || exit
gcc -c meow.s -o amogus.o || exit
~/stuff/zig/zig cc -static -nostdlib -nodefaultlibs amogus.o -o amogus || exit
#clang -static -nostdlib -nodefaultlibs meow.s -o amogus || exit
objdump -d amogus
strip -K entry amogus
du -b amogus

84
meow.s Normal file
View file

@ -0,0 +1,84 @@
.globl _start
.type _start, @function
.globl entry
.type entry, @function
_start:
#mov -4(%ebp),%eax
pop %rax
mov %rax,argc(%rip)
mov %rax,%rdi
pop %rax
mov %rax,argv(%rip)
cmp $1,%rdi
jg endif
mov $1,%rdi
call usage
jmp _exit
endif:
mov $0,%rdi
jmp _exit
usage:
lea help0(%rip),%rdi
mov $help0l,%rsi
call write
mov [argv],%rdi
push %rdi
call strlen
pop %rdi
mov %rax,%rsi
call write
lea help1(%rip),%rdi
mov $help1l,%rsi
call write
ret
# rdi - buf
# -> rax - len
strlen:
mov %rdi,%rax
strlen_loop:
movb 0(%rax),%sil
inc %rax
test %sil,%sil
jnz strlen_loop
sub $1,%rax
sub %rdi,%rax
ret
# rdi - buf
# rsi - len
write:
push %rdi
push %rsi
pop %rdx
pop %rsi
mov $1,%rax
mov $1,%rdi
syscall
ret
help0:
.ascii "Usage: "
.set help0l, .-help0
help1:
.ascii " regex0 [regex1 ...]\nstdout: NUL-separated list of matching strings\n"
.set help1l, .-help1
_exit:
mov $0x3c,%rax
syscall
ret
entry:
ret
.bss
argc:
.zero 8
argv:
.zero 8
buf:
.zero 65536

2
test Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
./build && gdb -iex 'set confirm no' -ex 'run' amogus