From 551145f1478bd3e34127d5b2f3322cdeae8daf80 Mon Sep 17 00:00:00 2001 From: turret Date: Thu, 7 Sep 2023 13:21:24 +0000 Subject: cat: start special case handling more complex and fix bug that doesnt actually let just a single - work --- cat.s | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cat.s b/cat.s index 8a047e7..e6854a8 100644 --- a/cat.s +++ b/cat.s @@ -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 -- cgit v1.2.3