diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-01-01 17:23:29 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-01-01 17:23:29 -0800 |
commit | 113bae7311b63e55e55160970718d19bfeeb56c3 (patch) | |
tree | d2468b58470e173329c7ef6e8da496c2f768b037 /apps/ex4.subx | |
parent | 1b050736eea04323e09e5e8e7499c33cee1899d0 (diff) | |
download | mu-113bae7311b63e55e55160970718d19bfeeb56c3.tar.gz |
5856
Diffstat (limited to 'apps/ex4.subx')
-rw-r--r-- | apps/ex4.subx | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/apps/ex4.subx b/apps/ex4.subx new file mode 100644 index 00000000..78a97433 --- /dev/null +++ b/apps/ex4.subx @@ -0,0 +1,39 @@ +# Read a character from stdin, save it to a global, write it to stdout. +# +# To run: +# $ ./subx translate init.linux examples/ex4.subx -o examples/ex4 +# $ ./subx run examples/ex4 + +== data + +# the global variable we save to +X: + 0/imm32 # space for read() to write to + +== code + +Entry: +# read(stdin, X, 1) +# . fd = 0 (stdin) +bb/copy-to-ebx 0/imm32 +# . data = X (location to write result to) +b9/copy-to-ecx X/imm32 +# . size = 1 character +ba/copy-to-edx 1/imm32 +# . syscall +e8/call syscall_read/disp32 + +# write(stdout, X, 1) +# . fd = 1 (stdout) +bb/copy-to-ebx 1/imm32 +# . initialize X (location to read from) +b9/copy-to-ecx X/imm32 +# . size = 1 character +ba/copy-to-edx 1/imm32 +# . syscall +e8/call syscall_write/disp32 + +# exit(ebx) +e8/call syscall_exit/disp32 + +# . . vim:nowrap:textwidth=0 |