aboutsummaryrefslogtreecommitdiffstats
path: root/cat.s
diff options
context:
space:
mode:
authorturret <turret@duck.com>2023-09-07 13:34:44 +0000
committerturret <turret@duck.com>2023-09-07 13:34:44 +0000
commit7fe2c32d10543e5d06b745f92bea86d7483c4b5d (patch)
tree1ded704e8a5dd2f4da990334d77b24b287e1465b /cat.s
parent551145f1478bd3e34127d5b2f3322cdeae8daf80 (diff)
downloadcat-7fe2c32d10543e5d06b745f92bea86d7483c4b5d.tar.gz
cat-7fe2c32d10543e5d06b745f92bea86d7483c4b5d.tar.bz2
cat-7fe2c32d10543e5d06b745f92bea86d7483c4b5d.zip
undo work
Diffstat (limited to 'cat.s')
-rw-r--r--cat.s42
1 files changed, 15 insertions, 27 deletions
diff --git a/cat.s b/cat.s
index e6854a8..b02be26 100644
--- a/cat.s
+++ b/cat.s
@@ -15,7 +15,7 @@ process_fd:
cmp rax, 1
jl .ret
- ; TODO special case handling
+ ; TODO flag handling
; write(1, buf, rax)
mov rdi, 1
mov rsi, buf
@@ -32,8 +32,11 @@ process_fd:
ret
_start:
+ ; TODO: cmd flag consumer
+
; r12 = argc
mov rbp, rsp
+ mov r13, [rbp]
mov r12, [rbp]
cmp r12, 2
jl .stdin
@@ -44,13 +47,16 @@ _start:
; if no more entries; exit
cmp r12, 2
jl exit
+ mov r10, [rbp]
+ cmp r10, 1
+ jl .cont
; arguments starting with "-" are special cases
mov r11, [rbp]
mov r11, [r11]
and r11, 0xff
cmp r11, 0x2d ;'-'
- je .special
+ je .stdin
; open(rbp, 0, 0)
mov rax, 2
@@ -61,7 +67,7 @@ _start:
; make sure fd exists
cmp rax, 1
- jl .error
+ jl error
; print file
call process_fd
; returns input
@@ -71,41 +77,23 @@ _start:
syscall
; prepare registers for next loop
+.cont:
add rbp, 8
sub r12, 1
jmp .loop
- ; unreachable. insurance
- jmp exit
-
-.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
+ jmp .cont
-.usage:
+usage:
; TODO: usage message
- jmp .errorexit
-.error:
+ jmp errorexit
+error:
;exit(1)
; TODO: process RAX to print meaningful message
-.errorexit:
+errorexit:
mov rax, 60
mov rdi, 1
syscall