diff options
author | pommicket <pommicket@gmail.com> | 2022-01-06 23:29:59 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-01-06 23:30:24 -0500 |
commit | 4cd2b7047c19e45dc2e664bb6666ee1f288b126c (patch) | |
tree | fca1460e2662c042ecc1ab0ecda4948bd8b139d5 /04b/in04b | |
parent | 3e73f6625cf4ee1c0ac7263d293dcc62fcc53597 (diff) |
04b initial readme, guessing game, compiler fixes
Diffstat (limited to '04b/in04b')
-rw-r--r-- | 04b/in04b | 73 |
1 files changed, 11 insertions, 62 deletions
@@ -1,93 +1,42 @@ -; declaration: -; global <name> -; local <name> -; argument <name> -; :<label> -; statement: -; <declaration> -; if <term> <==/</>/>=/<=/!=/[/]/[=/]=> <term> goto <label> NOTE: this uses signed comparisons -; goto <label> -; <lvalue> = <rvalue> -; <lvalue> += <rvalue> -; <lvalue> -= <rvalue> -; <function>(<term>, <term>, ...) -; return <rvalue> -; string <str> -; byte <number> -; term: -; <var> -; .<label> -; <number> -; number: -; 'c -; 12345 -; 0xabc -; lvalue: -; <var> -; *1<var> / *2<var> / *4<var> / *8<var> -; rvalue: -; <term> -; &<var> -; *1<var> / *2<var> / *4<var> / *8<var> -; ~<term> -; <function>(<term>, <term>, ...) -; <term> + <term> -; <term> - <term> -; NOTE: *, /, % are signed (imul and idiv) -; <term> * <term> -; <term> / <term> -; <term> % <term> -; <term> & <term> -; <term> | <term> -; <term> ^ <term> -; <term> < <term> (left shift) -; <term> > <term> (unsigned right shift) - main() -:main -function +function main puts(.str_hello_world) putc(10) ; newline syscall(0x3c, 0) + :str_hello_world -string Hello, world! -byte 0 + string Hello, world! + byte 0 -:strlen -function +function strlen argument s - local len local c local p - len = 0 + p = s :strlen_loop - p = s + len c = *1p if c == 0 goto strlen_loop_end - len += 1 + p += 1 goto strlen_loop :strlen_loop_end - return len + return p - s -:putc -function +function putc argument c local p p = &c syscall(1, 1, p, 1) return -:puts -function +function puts argument s local len len = strlen(s) syscall(1, 1, s, len) return -:syscall -function +function syscall ; I've done some testing, and this should be okay even if ; rbp-56 goes beyond the end of the stack. ; mov rax, [rbp-16] |