about summary refs log tree commit diff stats
path: root/subx/examples/ex10.subx
Commit message (Collapse)AuthorAgeFilesLines
* 4963Kartik Agaram2019-02-141-2/+2
|
* 4961Kartik Agaram2019-02-141-1/+0
|
* 4893Kartik Agaram2018-12-301-2/+2
|
* 4888Kartik Agaram2018-12-291-2/+2
| | | | We only can't use rm32=5 when mod=0. Totally fine when it's mod=1.
* 4881Kartik Agaram2018-12-281-1/+1
|
* 4847Kartik Agaram2018-12-061-1/+1
|
* 4808 - clean up comments in all subx filesKartik Agaram2018-11-301-6/+5
|
* 4802Kartik Agaram2018-11-301-7/+7
| | | | | | | | | | | | | | | | Some automated commenting cleanup. Still needs more careful manual scanning. sed -i 's/^# 1-3/# . 1-3/' *.subx */*.subx sed -i 's/^# op/# . op/' *.subx */*.subx sed -i 's/# vim/# . . vim/' *.subx */*.subx sed -i 's/^ # push args/ # . . push args/' *.subx */*.subx sed -i 's/^ # discard args/ # . . discard args/' *.subx */*.subx sed -i 's/^ # call/ # . . call/' *.subx */*.subx sed -i 's/^ # prolog/ # . prolog/' *.subx */*.subx sed -i 's/^ # epilog/ # . epilog/' *.subx */*.subx sed -i 's/^ # save registers/ # . save registers/' *.subx */*.subx sed -i 's/^ # restore registers/ # . restore registers/' *.subx */*.subx sed -i 's/ operand / register /' *.subx */*.subx
* 4801Kartik Agaram2018-11-301-37/+37
| | | | Reindent all SubX code to make some room for the new comment style.
* 4668Kartik Agaram2018-10-051-5/+5
|
* 4667Kartik Agaram2018-10-051-11/+12
| | | | | Standardize on hyphens in all names. And we'll use colons for namespacing labels in functions.
* 4662Kartik Agaram2018-10-051-0/+2
|
* 4644Kartik Agaram2018-10-011-5/+5
|
* 4639Kartik Agaram2018-10-011-3/+3
|
* 4624Kartik Agaram2018-09-301-1/+1
| | | | | | | | Start requiring a '-o' flag to designate the output binary when translating. Things currently get funky if you pass in multiple inputs, but that's ok. This is the first step to supporting multiple input files for a single output binary.
* 4516Kartik K. Agaram2018-09-241-10/+9
| | | | | | | More calling convention tweaks. Use EBP to get consistently at parameters and locals. Always put the first function argument closest to EBP.
* 4591Kartik Agaram2018-09-221-2/+2
|
* 4585Kartik Agaram2018-09-211-72/+0
|
* 4584 - discrepancy between SubX and native x86Kartik Agaram2018-09-211-1/+76
| | | | | | | | | | | | | | | | | | | | | | | | | One of the more painful things I had to debug with machine code. Tricks I used can be seen in ex10.subx: - printing argv[1] in various places - printing a single 'X' in various places to count how many times we get to different instructions - exiting with the current value of EAX in various places I repeatedly went down the wrong trail in several ways: - forgetting that the problem lay in native runs, and accidentally switching to subx runs during debugging. - forgetting to pass commandline args, because ex10 doesn't check its argv - writing the wrong comment for an instruction, and then miscalculating the set of registers that need to be saved. - forgetting that syscalls clobber EAX. Debugging native runs is hard, because you have to write non-trivial code to instrument the binary, and instrumentation can itself be buggy. When we finally tracked it down, I recognized the problem immediately. I'd meant to confirm the behavior of opcode 8a against bare metal, and then forgot. In any case, opcode 8a was inconsistent with 88. Sloppy.
* 4583Kartik Agaram2018-09-211-1/+1
|
* 4581Kartik Agaram2018-09-211-1/+1
| | | | | | | | | | | | Even more cuddling. We want to keep lines short where the opcode and operands are self-explanatory. If there are any implicit registers, etc., we'll continue to do the table layout. The first two columns look messy now; let's see how this goes. Maybe I'll give up on the tabular layout altogether, just string args with a single space.
* 4579Kartik Agaram2018-09-211-0/+67
New example program: ascii null-terminated string comparison I'd hoped this would be a stepping stone to supporting general ascii comparison, but we're planning to use size-prefixed rather than null-terminated arrays everywhere. The only exception is commandline arguments, which will remain null-terminated to interoperate with Linux. So I'm going to need separate functions for "compare with argv" and for general string comparison.
er)) <- ((next-input))) arg: nil 0 (3) run: init-channel/main 6: 3 => ((4 integer)) mem: ((4 integer)): 1005 <= 3 run: init-channel/main 7: (((4 integer)) <- ((add)) ((4 integer)) ((1 literal))) mem: ((4 integer)) => 3 run: init-channel/main 7: 4 => ((4 integer)) mem: ((4 integer)): 1005 <= 4 run: init-channel/main 8: (((5 tagged-value-array-address-address)) <- ((get-address)) ((1 channel-address) (deref)) ((2 offset))) run: init-channel/main 8: 1033 => ((5 tagged-value-array-address-address)) mem: ((5 tagged-value-array-address-address)): 1006 <= 1033 run: init-channel/main 9: (((5 tagged-value-array-address-address) (deref)) <- ((new)) ((tagged-value-array literal)) ((4 integer))) mem: ((4 integer)) => 4 run: init-channel/main 9: 1034 => ((5 tagged-value-array-address-address) (deref)) mem: ((5 tagged-value-array-address-address) (deref)): 1033 <= 1034 run: init-channel/main 10: (((reply)) ((1 channel-address))) mem: ((1 channel-address)) => 1031 run: main 0: 1031 => ((1 channel-address)) mem: ((1 channel-address)): 1 <= 1031 run: main 1: (((2 integer)) <- ((copy)) ((34 literal))) run: main 1: 34 => ((2 integer)) mem: ((2 integer)): 2 <= 34 run: main 2: (((3 tagged-value)) <- ((save-type)) ((2 integer))) mem: ((2 integer)) => 34 run: main 2: #(tagged record (integer 34)) => ((3 tagged-value)) mem: ((3 tagged-value)): 3 <= integer mem: ((3 tagged-value)): 4 <= 34 run: main 3: (((1 channel-address) (deref)) <- ((write)) ((1 channel-address)) ((3 tagged-value))) mem: ((1 channel-address)) => 1031 mem: ((3 tagged-value)) => #(tagged record (integer 34 . nil)) run: write/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal))) run: write/main 0: 1043 => ((default-space space-address)) run: write/main 1: (((1 channel-address)) <- ((next-input))) arg: nil 0 (1031 #(tagged record (integer 34 . nil))) run: write/main 1: 1031 => ((1 channel-address)) mem: ((1 channel-address)): 1045 <= 1031 run: write/main 2: (((2 tagged-value)) <- ((next-input))) arg: nil 1 (1031 #(tagged record (integer 34 . nil))) run: write/main 2: #(tagged record (integer 34 . nil)) => ((2 tagged-value)) mem: ((2 tagged-value)): 1046 <= integer mem: ((2 tagged-value)): 1047 <= 34 run: write/main 3: (((4 boolean)) <- ((full?)) ((1 channel-address) (deref))) mem: ((1 channel-address) (deref)) => #(tagged record (0 0 1034 . nil)) run: full?/write/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal))) run: full?/write/main 0: 1074 => ((default-space space-address)) run: full?/write/main 1: (((1 channel)) <- ((next-input))) arg: nil 0 (#(tagged record (0 0 1034 . nil))) run: full?/write/main 1: #(tagged record (0 0 1034 . nil)) => ((1 channel)) mem: ((1 channel)): 1076 <= 0 mem: ((1 channel)): 1077 <= 0 mem: ((1 channel)): 1078 <= 1034 run: full?/write/main 2: (((4 integer)) <- ((get)) ((1 channel)) ((1 offset))) mem: ((1077 integer) (raw)) => 0 run: full?/write/main 2: 0 => ((4 integer)) mem: ((4 integer)): 1079 <= 0 run: full?/write/main 3: (((4 integer)) <- ((add)) ((4 integer)) ((1 literal))) mem: ((4 integer)) => 0 run: full?/write/main 3: 1 => ((4 integer)) mem: ((4 integer)): 1079 <= 1 run: full?/write/main 4: (((5 integer)) <- ((capacity)) ((1 channel))) mem: ((1 channel)) => #(tagged record (0 0 1034 . nil)) run: capacity/full?/write/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal))) run: capacity/full?/write/main 0: 1105 => ((default-space space-address)) run: capacity/full?/write/main 1: (((1 channel)) <- ((next-input))) arg: nil 0 (#(tagged record (0 0 1034 . nil))) run: capacity/full?/write/main 1: #(tagged record (0 0 1034 . nil)) => ((1 channel)) mem: ((1 channel)): 1107 <= 0 mem: ((1 channel)): 1108 <= 0 mem: ((1 channel)): 1109 <= 1034 run: capacity/full?/write/main 2: (((4 tagged-value-array-address)) <- ((get)) ((1 channel)) ((2 offset))) mem: ((1109 tagged-value-array-address) (raw)) => 1034 run: capacity/full?/write/main 2: 1034 => ((4 tagged-value-array-address)) mem: ((4 tagged-value-array-address)): 1110 <= 1034 run: capacity/full?/write/main 3: (((5 integer)) <- ((length)) ((4 tagged-value-array-address) (deref))) array-len: ((4 tagged-value-array-address) (deref)) mem: ((1034 integer) (raw)) => 4 run: capacity/full?/write/main 3: 4 => ((5 integer)) mem: ((5 integer)): 1111 <= 4 run: capacity/full?/write/main 4: (((reply)) ((5 integer))) mem: ((5 integer)) => 4 run: full?/write/main 4: 4 => ((5 integer)) mem: ((5 integer)): 1080 <= 4 run: full?/write/main 5: (((6 boolean)) <- ((less-than)) ((4 integer)) ((5 integer))) mem: ((4 integer)) => 1 mem: ((5 integer)) => 4 run: full?/write/main 5: t => ((6 boolean)) mem: ((6 boolean)): 1081 <= t run: full?/write/main 6: (((jump-if)) ((6 boolean)) ((1 offset))) mem: ((6 boolean)) => t run: full?/write/main 8: (((7 integer)) <- ((get)) ((1 channel)) ((0 offset))) mem: ((1076 integer) (raw)) => 0 run: full?/write/main 8: 0 => ((7 integer)) mem: ((7 integer)): 1082 <= 0 run: full?/write/main 9: (((8 boolean)) <- ((equal)) ((7 integer)) ((4 integer))) mem: ((7 integer)) => 0 mem: ((4 integer)) => 1 run: full?/write/main 9: nil => ((8 boolean)) mem: ((8 boolean)): 1083 <= nil run: full?/write/main 10: (((reply)) ((8 boolean))) mem: ((8 boolean)) => nil run: write/main 3: nil => ((4 boolean)) mem: ((4 boolean)): 1048 <= nil run: write/main 4: (((jump-unless)) ((4 boolean)) ((2 offset))) mem: ((4 boolean)) => nil run: write/main 7: (((6 tagged-value-array-address)) <- ((get)) ((1 channel-address) (deref)) ((2 offset))) mem: ((1033 tagged-value-array-address) (raw)) => 1034 run: write/main 7: 1034 => ((6 tagged-value-array-address)) mem: ((6 tagged-value-array-address)): 1050 <= 1034 run: write/main 8: (((7 integer-address)) <- ((get-address)) ((1 channel-address) (deref)) ((1 offset))) run: write/main 8: 1032 => ((7 integer-address)) mem: ((7 integer-address)): 1051 <= 1032 run: write/main 9: (((8 tagged-value-address)) <- ((index-address)) ((6 tagged-value-array-address) (deref)) ((7 integer-address) (deref))) mem: ((7 integer-address) (deref)) => 0 array-len: ((1034 tagged-value-array) (raw)) mem: ((1034 integer) (raw)) => 4 run: write/main 9: 1035 => ((8 tagged-value-address)) mem: ((8 tagged-value-address)): 1052 <= 1035 run: write/main 10: (((8 tagged-value-address) (deref)) <- ((copy)) ((2 tagged-value))) mem: ((2 tagged-value)) => #(tagged record (integer 34 . nil)) run: write/main 10: #(tagged record (integer 34 . nil)) => ((8 tagged-value-address) (deref)) mem: ((8 tagged-value-address) (deref)): 1035 <= integer mem: ((8 tagged-value-address) (deref)): 1036 <= 34 run: write/main 11: (((7 integer-address) (deref)) <- ((add)) ((7 integer-address) (deref)) ((1 literal))) mem: ((7 integer-address) (deref)) => 0 run: write/main 11: 1 => ((7 integer-address) (deref)) mem: ((7 integer-address) (deref)): 1032 <= 1 run: write/main 12: (((9 integer)) <- ((length)) ((6 tagged-value-array-address) (deref))) array-len: ((6 tagged-value-array-address) (deref)) mem: ((1034 integer) (raw)) => 4 run: write/main 12: 4 => ((9 integer)) mem: ((9 integer)): 1053 <= 4 run: write/main 13: (((10 boolean)) <- ((less-than)) ((7 integer-address) (deref)) ((9 integer))) mem: ((7 integer-address) (deref)) => 1 mem: ((9 integer)) => 4 run: write/main 13: t => ((10 boolean)) mem: ((10 boolean)): 1054 <= t run: write/main 14: (((jump-if)) ((10 boolean)) ((1 offset))) mem: ((10 boolean)) => t run: write/main 16: (((reply)) ((1 channel-address) (deref) (same-as-arg 0))) mem: ((1 channel-address) (deref) (same-as-arg 0)) => #(tagged record (0 1 1034 . nil)) run: main 3: #(tagged record (0 1 1034 . nil)) => ((1 channel-address) (deref)) mem: ((1 channel-address) (deref)): 1031 <= 0 mem: ((1 channel-address) (deref)): 1032 <= 1 mem: ((1 channel-address) (deref)): 1033 <= 1034 run: main 4: (((5 integer)) <- ((get)) ((1 channel-address) (deref)) ((0 offset))) mem: ((1031 integer) (raw)) => 0 run: main 4: 0 => ((5 integer)) mem: ((5 integer)): 5 <= 0 run: main 5: (((6 integer)) <- ((get)) ((1 channel-address) (deref)) ((1 offset))) mem: ((1032 integer) (raw)) => 1 run: main 5: 1 => ((6 integer)) mem: ((6 integer)): 6 <= 1 schedule: done with routine nil