diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-12-02 14:41:21 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-12-02 14:41:21 -0800 |
commit | c98d4b1c6ae2d103acc7b4f15e4dc6336f30de17 (patch) | |
tree | 46da18e339b2d87fc14b9f064cf1addf04a5ae64 /subx | |
parent | f75f333f52d42908ebf427f04fa6033f285ea5e5 (diff) | |
download | mu-c98d4b1c6ae2d103acc7b4f15e4dc6336f30de17.tar.gz |
4818
Diffstat (limited to 'subx')
-rw-r--r-- | subx/052kernel_string_equal.subx | 4 | ||||
-rw-r--r-- | subx/053new_segment.subx | 2 | ||||
-rw-r--r-- | subx/054string_equal.subx | 16 | ||||
-rw-r--r-- | subx/055trace.subx | 20 | ||||
-rw-r--r-- | subx/058read.subx | 6 | ||||
-rw-r--r-- | subx/059read-byte.subx | 2 | ||||
-rw-r--r-- | subx/060write-stream.subx | 8 | ||||
-rw-r--r-- | subx/apps/crenshaw2-1.subx | 13 | ||||
-rw-r--r-- | subx/apps/crenshaw2-1b.subx | 12 | ||||
-rw-r--r-- | subx/examples/ex11.subx | 4 |
10 files changed, 44 insertions, 43 deletions
diff --git a/subx/052kernel_string_equal.subx b/subx/052kernel_string_equal.subx index e288c5ee..3ed0fd5d 100644 --- a/subx/052kernel_string_equal.subx +++ b/subx/052kernel_string_equal.subx @@ -40,9 +40,9 @@ kernel-string-equal: # s : null-terminated ascii string, benchmark : length-pre 57/push-EDI # pseudocode: - # initialize n = b.length + # initialize n = b->length # initialize s1 = s - # initialize s2 = b.data + # initialize s2 = b->data # i = 0 # for (i = 0; i < n; ++n) # c1 = *s1 diff --git a/subx/053new_segment.subx b/subx/053new_segment.subx index d12c94a0..efbfc1a3 100644 --- a/subx/053new_segment.subx +++ b/subx/053new_segment.subx @@ -27,7 +27,7 @@ new-segment: # len : int -> address 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP 53/push-EBX - # copy len to _mmap-new-segment.len + # copy len to _mmap-new-segment->len # TODO: compute _mmap-new-segment+4 before runtime 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . 0/r32/EAX 8/disp8 . # copy *(EBP+8) to EAX bb/copy-to-EBX _mmap-new-segment/imm32 diff --git a/subx/054string_equal.subx b/subx/054string_equal.subx index 69227074..8c531e6b 100644 --- a/subx/054string_equal.subx +++ b/subx/054string_equal.subx @@ -23,14 +23,14 @@ string-equal: # s : string, benchmark : string -> EAX : boolean 53/push-EBX 56/push-ESI # pseudocode: - # if s.length != b.length return false - # for i = 0; i < s.length; ++i + # if s->length != b->length return false + # for i = 0; i < s->length; ++i # if s[i] != b[i] return false # return true # registers: # i: ECX - # s.length: EDX - # b.length: EBX + # s->length: EDX + # b->length: EBX # b[i]: EBX # s[i]: EAX # @@ -38,10 +38,10 @@ string-equal: # s : string, benchmark : string -> EAX : boolean 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . 0/r32/EAX 8/disp8 . # copy *(EBP+8) to EAX # var benchmark/EBX : (address array byte) 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . 3/r32/EBX 0xc/disp8 . # copy *(EBP+12) to EBX - # if s.length != b.length return false - # EDX = s.length + # if s->length != b->length return false + # EDX = s->length 8b/copy 0/mod/indirect 0/rm32/EAX . . . 2/r32/EDX . . # copy *EAX to EDX - # compare s.length and b.length + # compare s->length and b->length 39/compare 0/mod/indirect 3/rm32/EBX . . . 2/r32/EDX . . # compare *EBX with EDX 75/jump-if-not-equal $string-equal:false/disp8 $string-equal:lengths: @@ -52,7 +52,7 @@ $string-equal:lengths: # EAX = &s[i] 40/inc-EAX $string-equal:loop: - # if i >= s.length return true + # if i >= s->length return true 39/compare 3/mod/direct 1/rm32/ECX . . . 2/r32/EDX . . # compare ECX with EDX 7d/jump-if-greater-or-equal $string-equal:true/disp8 # if b[i] != s[i] return false diff --git a/subx/055trace.subx b/subx/055trace.subx index 02bdc0fd..37c91249 100644 --- a/subx/055trace.subx +++ b/subx/055trace.subx @@ -62,7 +62,7 @@ initialize-trace-stream: 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # copy EAX to *Trace-stream 89/copy 0/mod/indirect 5/rm32/.disp32 . . 0/r32/EAX Trace-stream/disp32 # copy EAX to *Trace-stream - # Trace-stream.length = 0x1000/N - 12 + # Trace-stream->length = 0x1000/N - 12 c7 0/copy 1/mod/*+disp8 0/rm32/EAX . . . . 8/disp8 0xff4/imm32 # copy 0xff4 to *(EAX+8) c3/return @@ -191,11 +191,11 @@ test-trace-single: e8/call trace/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # check-ints-equal(*_test-trace-stream.data, 41/A 62/b 0a/newline 00, msg) + # check-ints-equal(*_test-trace-stream->data, 41/A 62/b 0a/newline 00, msg) # . . push args 68/push "F - test-trace-single"/imm32 68/push 0x0a6241/imm32/Ab-newline - # . . push *_test-trace-stream.data + # . . push *_test-trace-stream->data b8/copy-to-EAX _test-trace-stream/imm32 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 . # push *(EAX+12) # . . call @@ -229,11 +229,11 @@ test-trace-appends: e8/call trace/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # check-ints-equal(*_test-trace-stream.data, 43/C 0a/newline 44/D 0a/newline, msg) + # check-ints-equal(*_test-trace-stream->data, 43/C 0a/newline 44/D 0a/newline, msg) # . . push args 68/push "F - test-trace-appends"/imm32 68/push 0x0a440a43/imm32/C-newline-D-newline - # . . push *_test-trace-stream.data + # . . push *_test-trace-stream->data b8/copy-to-EAX _test-trace-stream/imm32 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 . # push *(EAX+12) # . . call @@ -259,11 +259,11 @@ test-trace-empty-line: e8/call trace/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # check-ints-equal(*_test-trace-stream.data, 0, msg) + # check-ints-equal(*_test-trace-stream->data, 0, msg) # . . push args 68/push "F - test-trace-empty-line"/imm32 68/push 0/imm32 - # . . push *_test-trace-stream.data + # . . push *_test-trace-stream->data b8/copy-to-EAX _test-trace-stream/imm32 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 . # push *(EAX+12) # . . call @@ -282,13 +282,13 @@ _append-3: # out : address, outend : address, s : (array byte) -> num_bytes_app 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP # . save registers 51/push-ECX - # _append-4(out, outend, &s.data[0], &s.data[s.length]) -> num_bytes_appended/EAX - # . . push &s.data[s.length] + # _append-4(out, outend, &s->data[0], &s->data[s->length]) -> num_bytes_appended/EAX + # . . push &s->data[s->length] 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0/r32/EAX 0x10/disp8 . # copy *(EBP+16) to EAX 8b/copy 0/mod/indirect 0/rm32/EAX . . . 1/r32/ECX . . # copy *EAX to ECX 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/EAX 1/index/ECX . 1/r32/ECX 4/disp8 . # copy EAX+ECX+4 to ECX 51/push-ECX - # . . push &s.data[0] + # . . push &s->data[0] 8d/copy-address 1/mod/*+disp8 0/rm32/EAX . . . 1/r32/ECX 4/disp8 . # copy EAX+4 to ECX 51/push-ECX # . . push outend diff --git a/subx/058read.subx b/subx/058read.subx index df301ca8..291df30b 100644 --- a/subx/058read.subx +++ b/subx/058read.subx @@ -101,7 +101,7 @@ $read:fake: 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x10/imm32 # add to ESP # s->write += EAX 01/add 0/mod/indirect 7/rm32/EDI . . . 0/r32/EAX . . # add EAX to *EDI - # f.read += EAX + # f->read += EAX 01/add 1/mod/*+disp8 6/rm32/ESI . . . 0/r32/EAX 4/disp8 . # add EAX to *(ESI+4) # . restore registers 5f/pop-to-EDI @@ -114,7 +114,7 @@ $read:end: # - helpers -# idea: a clear-if-empty method on streams that clears only if f.read == f.write +# idea: a clear-if-empty method on streams that clears only if f->read == f->write # Unclear how I'd use it, though. Callers seem to need the check anyway. # Maybe a better helper would be 'empty-stream?' @@ -285,7 +285,7 @@ test-read-is-stateful: # . . push args 68/push "F - test-read-is-stateful"/imm32 68/push 0x00004443/imm32/C-D - # . push *_test-stream-buffer->data + # . . push *_test-stream-buffer->data b8/copy-to-EAX _test-stream-buffer/imm32 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 . # push *(EAX+12) # . . call diff --git a/subx/059read-byte.subx b/subx/059read-byte.subx index b020442b..b00d482c 100644 --- a/subx/059read-byte.subx +++ b/subx/059read-byte.subx @@ -41,7 +41,7 @@ Stdin: # return next byte value in EAX, with top 3 bytes cleared. # On EOF, return 0xffffffff. -read-byte: # f : (address buffered-file) -> byte/EAX +read-byte: # f : (address buffered-file) -> byte-or-eof/EAX # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP diff --git a/subx/060write-stream.subx b/subx/060write-stream.subx index 59616a01..73b48e36 100644 --- a/subx/060write-stream.subx +++ b/subx/060write-stream.subx @@ -150,11 +150,11 @@ test-write-stream-single: e8/call write-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # check-ints-equal(*_test-stream.data, 41/A 62/b 00 00, msg) + # check-ints-equal(*_test-stream->data, 41/A 62/b 00 00, msg) # . . push args 68/push "F - test-write-stream-single"/imm32 68/push 0x006241/imm32/Ab - # push *_test-stream.data + # . . push *_test-stream->data b8/copy-to-EAX _test-stream/imm32 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 . # push *(EAX+12) # . . call @@ -214,11 +214,11 @@ test-write-stream-appends: e8/call write-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # check-ints-equal(*_test-stream.data, 43/C 44/D 00 00, msg) + # check-ints-equal(*_test-stream->data, 43/C 44/D 00 00, msg) # . . push args 68/push "F - test-write-stream-appends"/imm32 68/push 0x00004443/imm32/C-D - # push *_test-stream.data + # . . push *_test-stream->data b8/copy-to-EAX _test-stream/imm32 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 . # push *(EAX+12) # . . call diff --git a/subx/apps/crenshaw2-1.subx b/subx/apps/crenshaw2-1.subx index c523634a..3688ef34 100644 --- a/subx/apps/crenshaw2-1.subx +++ b/subx/apps/crenshaw2-1.subx @@ -88,6 +88,7 @@ compile: # in : (address buffered-file), out : fd or (address stream), err : fd # . save registers 50/push-EAX 51/push-ECX + # prime the pump # . Look = get-char(in) # . . push args ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 8/disp8 . # push *(EBP+8) @@ -198,11 +199,11 @@ compile: # in : (address buffered-file), out : fd or (address stream), err : fd get-num: # in : (address buffered-file), out : (address stream), err : fd or (address stream), ed : (address exit-descriptor) -> <void> # pseudocode: # if !is-digit?(Look) expected(ed, err, "integer") - # if out.write >= out.length + # if out->write >= out->length # write(err, "Error: too many digits in number\n") # stop(ed, 1) - # out.data[out.write] = LSB(Look) - # ++out.write + # out->data[out->write] = LSB(Look) + # ++out->write # Look = get-char(in) # # registers: @@ -303,7 +304,7 @@ test-get-num-reads-single-digit: # This test uses exit-descriptors. Use EBP for setting up local variables. 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP - # setup + # clear all streams # . clear-stream(_test-stream) # . . push args 68/push _test-stream/imm32 @@ -374,7 +375,7 @@ test-get-num-reads-single-digit: # registers except ESP may be clobbered at this point # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x10/imm32 # add to ESP - # check-ints-equal(*_test-output-stream.data, '3') + # check-ints-equal(*_test-output-stream->data, '3') # . . push args 68/push "F - test-get-num-reads-single-digit"/imm32 68/push 0x33/imm32 @@ -394,7 +395,7 @@ test-get-num-aborts-on-non-digit-in-Look: # This test uses exit-descriptors. Use EBP for setting up local variables. 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP - # setup + # clear all streams # . clear-stream(_test-stream) # . . push args 68/push _test-stream/imm32 diff --git a/subx/apps/crenshaw2-1b.subx b/subx/apps/crenshaw2-1b.subx index 1baf90c3..d6fc6dee 100644 --- a/subx/apps/crenshaw2-1b.subx +++ b/subx/apps/crenshaw2-1b.subx @@ -201,11 +201,11 @@ get-num: # in : (address buffered-file), out : (address stream), err : fd or (a # pseudocode: # if !is-digit?(Look) expected(ed, err, "integer") # do - # if out.write >= out.length + # if out->write >= out->length # write(err, "Error: too many digits in number\n") # stop(ed, 1) - # out.data[out.write] = LSB(Look) - # ++out.write + # out->data[out->write] = LSB(Look) + # ++out->write # Look = get-char(in) # while is-digit?(Look) # This is complicated because I don't want to hard-code the error strategy in @@ -392,7 +392,7 @@ test-get-num-reads-single-digit: # registers except ESP may be clobbered at this point # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x10/imm32 # add to ESP - # check-ints-equal(*_test-output-stream.data, '3') + # check-ints-equal(*_test-output-stream->data, '3') # . . push args 68/push "F - test-get-num-reads-single-digit"/imm32 68/push 0x33/imm32 @@ -568,7 +568,7 @@ test-get-num-reads-multiple-digits: # registers except ESP may be clobbered at this point # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x10/imm32 # add to ESP - # check-ints-equal(*_test-output-stream.data, '3456') + # check-ints-equal(*_test-output-stream->data, '3456') # . . push args 68/push "F - test-get-num-reads-multiple-digits"/imm32 68/push 0x36353433/imm32 @@ -659,7 +659,7 @@ test-get-num-reads-multiple-digits-followed-by-nondigit: # registers except ESP may be clobbered at this point # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x10/imm32 # add to ESP - # check-ints-equal(*_test-output-stream.data, '3456') + # check-ints-equal(*_test-output-stream->data, '3456') # . . push args 68/push "F - test-get-num-reads-multiple-digits-followed-by-nondigit"/imm32 68/push 0x36353433/imm32 diff --git a/subx/examples/ex11.subx b/subx/examples/ex11.subx index e2628c39..245452fb 100644 --- a/subx/examples/ex11.subx +++ b/subx/examples/ex11.subx @@ -40,9 +40,9 @@ kernel-string-equal: # s : null-terminated ascii string, benchmark : length-pre 57/push-EDI # pseudocode: - # initialize n = b.length + # initialize n = b->length # initialize s1 = s - # initialize s2 = b.data + # initialize s2 = b->data # i = 0 # for (i = 0; i < n; ++n) # c1 = *s1 |