about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--subx/050write.subx (renamed from subx/050write_stderr.subx)18
-rw-r--r--subx/051test.subx22
-rwxr-xr-xsubx/apps/crenshaw2-1bin2529 -> 2554 bytes
-rw-r--r--subx/apps/crenshaw2-1.subx59
-rwxr-xr-xsubx/apps/factorialbin2533 -> 2581 bytes
5 files changed, 38 insertions, 61 deletions
diff --git a/subx/050write_stderr.subx b/subx/050write.subx
index 2225b968..b687aa3d 100644
--- a/subx/050write_stderr.subx
+++ b/subx/050write.subx
@@ -5,12 +5,12 @@
 # 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes
 
 # main:  (manual test if this is the last file loaded)
-  # syscall(exit, 0) -- we don't bother testing write-stderr just yet
+  # syscall(exit, 0) -- can't test these functions just yet
   bb/copy-to-EBX  0/imm32
   b8/copy-to-EAX  1/imm32
   cd/syscall  0x80/imm8
 
-write-stderr:  # s : (address array byte) -> <void>
+_write:  # fd : int, s : (address array byte) -> <void>
   # prolog
   55/push-EBP
   89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
@@ -19,14 +19,14 @@ write-stderr:  # s : (address array byte) -> <void>
   51/push-ECX
   52/push-EDX
   53/push-EBX
-  # syscall(write, 2/stderr, (data) s+4, (size) *s)
-    # fd = 2 (stderr)
-  bb/copy-to-EBX  2/imm32
-    # x = s+4
-  8b/copy                         1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           1/r32/ECX   8/disp8         .                 # copy *(EBP+8) to ECX
+  # syscall(write, fd, (data) s+4, (size) *s)
+    # fd : EBX
+  8b/copy                         1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           3/r32/EBX   8/disp8         .                 # copy *(EBP+8) to EBX
+    # data : ECX = s+4
+  8b/copy                         1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           1/r32/ECX   0xc/disp8       .                 # copy *(EBP+12) to ECX
   81          0/subop/add         3/mod/direct    1/rm32/ECX    .           .             .           .           .               4/imm32           # add to ECX
-    # size = *s
-  8b/copy                         1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           2/r32/EDX   8/disp8         .                 # copy *(EBP+8) to EDX
+    # size : EDX = *s
+  8b/copy                         1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           2/r32/EDX   0xc/disp8       .                 # copy *(EBP+12) to EDX
   8b/copy                         0/mod/indirect  2/rm32/EDX    .           .             .           2/r32/EDX   .               .                 # copy *EDX to EDX
     # syscall
   b8/copy-to-EAX  4/imm32/write
diff --git a/subx/051test.subx b/subx/051test.subx
index bbae6eff..3d5a1de7 100644
--- a/subx/051test.subx
+++ b/subx/051test.subx
@@ -6,7 +6,8 @@
 
 # main:  (manual test if this is the last file loaded)
   # check-ints-equal(34, 34) == 1
-  68/push  34/imm32
+  68/push  "error in check-ints-equal"/imm32
+  68/push  35/imm32
   68/push  34/imm32
   e8/call  check-ints-equal/disp32
   81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
@@ -29,33 +30,36 @@ check-ints-equal:  # (a : int, b : int, msg : (address array byte)) -> boolean
   # if EAX == b/EBX
   39/compare                      3/mod/direct    0/rm32/EAX    .           .             .           3/r32/EBX   .               .                 # compare EAX and EBX
   75/jump-if-unequal  $check-ints-equal:else/disp8
-    # print('.')
+    # _write(2/stderr, '.')
       # push args
   68/push  "."/imm32
+  68/push  2/imm32/stderr
       # call
-  e8/call  write-stderr/disp32
+  e8/call  _write/disp32
       # discard arg
-  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     # return
   eb/jump  $check-ints-equal:end/disp8
   # else:
 $check-ints-equal:else:
   # copy third arg (msg) into ECX
   8b/copy                         1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           1/r32/ECX   0x10/disp8       .                # copy *(EBP+16) to ECX
-    # print(ECX)
+    # _write(2/stderr, ECX)
       # push args
   51/push-ECX
+  68/push  2/imm32/stderr
       # call
-  e8/call  write-stderr/disp32
+  e8/call  _write/disp32
       # discard arg
-  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     # print newline
       # push args
   68/push  Newline/imm32
+  68/push  2/imm32/stderr
       # call
-  e8/call  write-stderr/disp32
+  e8/call  _write/disp32
       # discard arg
-  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     # increment Num-test-failures
   ff          0/subop/increment   0/mod/indirect  5/rm32/.disp32            .             .           .           Num-test-failures/disp32          # increment *Num-test-failures
 $check-ints-equal:end:
diff --git a/subx/apps/crenshaw2-1 b/subx/apps/crenshaw2-1
index 13182906..a924209d 100755
--- a/subx/apps/crenshaw2-1
+++ b/subx/apps/crenshaw2-1
Binary files differdiff --git a/subx/apps/crenshaw2-1.subx b/subx/apps/crenshaw2-1.subx
index 7b4a8deb..2d7921ce 100644
--- a/subx/apps/crenshaw2-1.subx
+++ b/subx/apps/crenshaw2-1.subx
@@ -50,66 +50,39 @@ abort:  # s : (address array byte) -> <void>
 
 # print out "Error: #{s} expected\n" to stderr
 error:  # s : (address array byte) -> <void>
-  # write-stderr("Error: ")
+  # _write(2/stderr, "Error: ")
     # push args
   68/push  "Error: "/imm32
+  68/push  2/imm32/stderr
     # call
-  e8/call  write-stderr/disp32
+  e8/call  _write/disp32
     # discard arg
-  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
-  # write-stderr(s)
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+  # _write(2/stderr, s)
     # push args
   ff          6/subop/push        1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none  .           .           4/disp8         .                 # push *(ESP+4)
+  68/push  2/imm32/stderr
     # call
-  e8/call  write-stderr/disp32
+  e8/call  _write/disp32
     # discard arg
-  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
-  # write-stderr(" expected")
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+  # _write(2/stderr, " expected")
     # push args
   68/push  " expected"/imm32
+  68/push  2/imm32/stderr
     # call
-  e8/call  write-stderr/disp32
+  e8/call  _write/disp32
     # discard arg
-  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
-  # write-stderr("\n")
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+  # _write(2/stderr, "\n")
     # push args
   68/push  Newline/imm32
+  68/push  2/imm32/stderr
     # call
-  e8/call  write-stderr/disp32
+  e8/call  _write/disp32
     # discard arg
-  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
-  # end
-  c3/return
-
-write-stdout:  # s : (address array byte) -> <void>
-  # prolog
-  55/push-EBP
-  89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
-  # save registers
-  50/push-EAX
-  51/push-ECX
-  52/push-EDX
-  53/push-EBX
-  # syscall(write, 1/stdout, (data) s+4, (size) *s)
-    # fd = 1 (stdout)
-  bb/copy-to-EBX  1/imm32
-    # x = s+4
-  8b/copy                         1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           1/r32/ECX   8/disp8         .                 # copy *(EBP+8) to ECX
-  81          0/subop/add         3/mod/direct    1/rm32/ECX    .           .             .           .           .               4/imm32           # add to ECX
-    # size = *s
-  8b/copy                         1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           2/r32/EDX   8/disp8         .                 # copy *(EBP+8) to EDX
-  8b/copy                         0/mod/indirect  2/rm32/EDX    .           .             .           2/r32/EDX   .               .                 # copy *EDX to EDX
-    # syscall
-  b8/copy-to-EAX  4/imm32/write
-  cd/syscall  0x80/imm8
-  # restore registers
-  5b/pop-to-EBX
-  5a/pop-to-EDX
-  59/pop-to-ECX
-  58/pop-to-EAX
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
   # end
-  89/copy                         3/mod/direct    4/rm32/ESP    .           .             .           5/r32/EBP   .               .                 # copy EBP to ESP
-  5d/pop-to-EBP
   c3/return
 
 # vim:nowrap:textwidth=0
diff --git a/subx/apps/factorial b/subx/apps/factorial
index 63196a79..44a3cd30 100755
--- a/subx/apps/factorial
+++ b/subx/apps/factorial
Binary files differ