summaryrefslogtreecommitdiff
path: root/builtin_echo.asm
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2018-06-23 15:12:55 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2018-06-23 15:12:55 -0400
commit3b46e7ef1f4c3f364e75e780eff923ef146ee42c (patch)
treec1e08f6ec3925c9c57f2093d59ab7444de9e28ce /builtin_echo.asm
parent2362c3ae6b32c816c4febe9714847fa4d80e1ad5 (diff)
downloadminos-3b46e7ef1f4c3f364e75e780eff923ef146ee42c.tar.gz
Implement initial builtin commands
Diffstat (limited to 'builtin_echo.asm')
-rw-r--r--builtin_echo.asm29
1 files changed, 19 insertions, 10 deletions
diff --git a/builtin_echo.asm b/builtin_echo.asm
index 1b4af89..9cc1e9c 100644
--- a/builtin_echo.asm
+++ b/builtin_echo.asm
@@ -5,16 +5,25 @@ builtin_echo:
push bp
mov bp, sp
- mov bx, word [bp + 4]
- add bx, 2
- push word [bx]
- push .msg_fmt
- call printf
- add sp, 2 * 2
+ mov cx, word [bp + 4] ; argc
+ mov bx, word [bp + 6] ; argv
- mov sp, bp
- pop bp
- ret
- .msg_fmt db '%s\n', 0
+ cmp cx, 0 ; if no arguments, return
+ jbe .return
+
+ .output: ; print argv
+ push word [bx]
+ push .msg_fmt
+ call printf
+ add sp, 2 * 2
+ add bx, 2
+ dec cx
+ jne .output
+
+ .return:
+ mov sp, bp
+ pop bp
+ ret
+ .msg_fmt db '%s ', 0
%endif