about summary refs log tree commit diff stats
path: root/subx/examples/ex10.subx
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2018-09-24 18:48:41 -0700
committerKartik Agaram <vc@akkartik.com>2018-09-24 22:55:37 -0700
commitc5d9a32fe6add8c986942261dd22377f911d1ca0 (patch)
treeb963fff418cc486cd3a7c1bf1b5d1c036a938045 /subx/examples/ex10.subx
parent9353569934e08c4ba531da5b64aeb4ae08ac2aae (diff)
downloadmu-c5d9a32fe6add8c986942261dd22377f911d1ca0.tar.gz
4516
More calling convention tweaks.

Use EBP to get consistently at parameters and locals.
Always put the first function argument closest to EBP.
Diffstat (limited to 'subx/examples/ex10.subx')
-rw-r--r--subx/examples/ex10.subx19
1 files changed, 9 insertions, 10 deletions
diff --git a/subx/examples/ex10.subx b/subx/examples/ex10.subx
index 81f4f2ae..92e9f1f4 100644
--- a/subx/examples/ex10.subx
+++ b/subx/examples/ex10.subx
@@ -18,14 +18,13 @@
 #         argv[0]: *(ESP+4)
 #         argv[1]: *(ESP+8)
 #         ...
-  # s1 = argv[1] (EAX)
-  8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none  .           0/r32/EAX   8/disp8         .                 # copy *(ESP+8) to EAX
-  # s2 = argv[2] (EBX)
-  8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none  .           3/r32/EBX   0xc/disp8       .                 # copy *(ESP+12) to EBX
-  # call argv_equal(s1, s2)
-    # push args
-  50/push-EAX
-  53/push-EBX
+  # prolog
+  89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
+  # call argv_equal(argv[1], argv[2])
+    # push argv[2]
+  ff          6/subop/push        1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           .           0xc/disp8       .                 # push *(EBP+12)
+    # push argv[1]
+  ff          6/subop/push        1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           .           0x8/disp8       .                 # push *(EBP+8)
     # call
   e8/call argv_equal/disp32
   # exit(EAX)
@@ -38,8 +37,8 @@ $exit:
 # reason for the name: the only place we should have null-terminated ascii strings is from commandline args
 argv_equal:  # (s1, s2) : null-terminated ascii strings -> EAX : boolean
   # initialize s1 (ECX) and s2 (EDX)
-  8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none  .           1/r32/ECX   8/disp8         .                 # copy *(ESP+8) to ECX
-  8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none  .           2/r32/EDX   4/disp8         .                 # copy *(ESP+4) to EDX
+  8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none  .           1/r32/ECX   4/disp8         .                 # copy *(ESP+4) to ECX
+  8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none  .           2/r32/EDX   8/disp8         .                 # copy *(ESP+8) to EDX
   # while (true)
 $argv_loop:
     # c1/EAX, c2/EBX = *s1, *s2