diff options
Diffstat (limited to 'builtin_echo.asm')
-rw-r--r-- | builtin_echo.asm | 29 |
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 |