diff options
author | turret <turret@duck.com> | 2023-09-07 13:21:24 +0000 |
---|---|---|
committer | turret <turret@duck.com> | 2023-09-07 13:21:24 +0000 |
commit | 551145f1478bd3e34127d5b2f3322cdeae8daf80 (patch) | |
tree | cbd004a6aca2806a9876ab39d77c18c020aa72b3 /cat.s | |
parent | 5dd59a4060aa72ad359bec110b38f4b9e73b9150 (diff) | |
download | cat-551145f1478bd3e34127d5b2f3322cdeae8daf80.tar.gz cat-551145f1478bd3e34127d5b2f3322cdeae8daf80.tar.bz2 cat-551145f1478bd3e34127d5b2f3322cdeae8daf80.zip |
cat: start special case handling more complex
and fix bug that doesnt actually let just a single - work
Diffstat (limited to 'cat.s')
-rw-r--r-- | cat.s | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -15,6 +15,7 @@ process_fd: cmp rax, 1 jl .ret + ; TODO special case handling ; write(1, buf, rax) mov rdi, 1 mov rsi, buf @@ -45,8 +46,10 @@ _start: jl exit ; arguments starting with "-" are special cases - mov r13, [rbp] - cmp r13, 0x2d ;'-' + mov r11, [rbp] + mov r11, [r11] + and r11, 0xff + cmp r11, 0x2d ;'-' je .special ; open(rbp, 0, 0) @@ -77,15 +80,32 @@ _start: .special: ;special case handler (TODO) + ; get second character + mov r11, [rbp] + add r11, 1 + mov r10, [r11] + and r10, 0xff + + ; just a single - + cmp r10, 0x00 + je .stdin + + jmp .usage ; stdin passthrough .stdin: mov rax, 0 call process_fd + add rbp, 8 + sub r12, 1 jmp .loop +.usage: + ; TODO: usage message + jmp .errorexit .error: ;exit(1) ; TODO: process RAX to print meaningful message +.errorexit: mov rax, 60 mov rdi, 1 syscall |