diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-09-23 09:23:21 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-09-23 09:23:21 -0700 |
commit | aa00959024643a33f766ef3f060a934006fe7725 (patch) | |
tree | f73a6ade8937c70a4df6b480ac8602e21ae1d7d3 /transect/ex4.k2 | |
parent | 7d4e351a0d1e3c4e71b58d3218b4e6b833f542f2 (diff) | |
download | mu-aa00959024643a33f766ef3f060a934006fe7725.tar.gz |
4504
Diffstat (limited to 'transect/ex4.k2')
-rw-r--r-- | transect/ex4.k2 | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/transect/ex4.k2 b/transect/ex4.k2 new file mode 100644 index 00000000..9a7ddee7 --- /dev/null +++ b/transect/ex4.k2 @@ -0,0 +1,34 @@ +## read a character from stdin, save it to a global, write it to stdout + +# variables are always references +# read their address with their names: x (can't write to their address) +# read/write their contents with a lookup: *x +var x : char + +fn main [ + call read 0/stdin, x, 1/size + result/EAX <- call write 1/stdout, x, 1/size + call exit, result/EAX +] + +fn read fd : int, x : (address array byte), size : int [ + EBX <- copy fd + ECX <- copy x + EDX <- copy size + EAX <- copy 3/read + syscall +] + +fn write fd : int, x : (address array byte), size : int [ + EBX <- copy fd + ECX <- copy x + EDX <- copy size + EAX <- copy 4/write + syscall +] + +fn exit x : int [ + code/EBX <- copy x + code/EAX <- copy 1/exit + syscall +] |