From c56d803cd8a0e3f28328f91aa1d457905a68641a Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 30 Nov 2018 09:43:49 -0800 Subject: 4796 --- html/subx/examples/ex9.subx.html | 90 ++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 46 deletions(-) (limited to 'html/subx/examples/ex9.subx.html') diff --git a/html/subx/examples/ex9.subx.html b/html/subx/examples/ex9.subx.html index f949f02a..0f683047 100644 --- a/html/subx/examples/ex9.subx.html +++ b/html/subx/examples/ex9.subx.html @@ -15,11 +15,9 @@ body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } +.subxComment { color: #005fff; } .LineNr { color: #444444; } -.Delimiter { color: #800080; } -.Comment { color: #9090ff; } -.Comment a { color:#0000ee; text-decoration:underline; } -.SalientComment { color: #00ffff; } +.CommentedCode { color: #6c6c6c; } --> @@ -54,57 +52,57 @@ if ('onhashchange' in window) {
- 1 ## Example showing arg order on the stack.
- 2 # Show difference between ascii codes of first letter of first arg and first
- 3 # letter of second arg.
- 4 #
- 5 # To run (from the subx directory):
- 6 #   $ subx translate examples/ex9.subx -o examples/ex9
- 7 #   $ subx run examples/ex9 z x
- 8 # Expected result:
- 9 #   $ echo $?
-10 #   2
-11 #
-12 # At the start of a SubX program:
-13 #   argc: *ESP
-14 #   argv[0]: *(ESP+4)
-15 #   argv[1]: *(ESP+8)
-16 #   ...
-17 # Locals start from ESP-4 downwards.
+ 1 ## Example showing arg order on the stack.
+ 2 # Show difference between ascii codes of first letter of first arg and first
+ 3 # letter of second arg.
+ 4 #
+ 5 # To run (from the subx directory):
+ 6 #   $ subx translate examples/ex9.subx -o examples/ex9
+ 7 #   $ subx run examples/ex9 z x
+ 8 # Expected result:
+ 9 #   $ echo $?
+10 #   2
+11 #
+12 # At the start of a SubX program:
+13 #   argc: *ESP
+14 #   argv[0]: *(ESP+4)
+15 #   argv[1]: *(ESP+8)
+16 #   ...
+17 # Locals start from ESP-4 downwards.
 18 
 19 == code
-20 # instruction                     effective address                                                   operand     displacement    immediate
-21 # op          subop               mod             rm32          base        index         scale       r32
-22 # 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
+20 # instruction                     effective address                                                   operand     displacement    immediate
+21 # op          subop               mod             rm32          base        index         scale       r32
+22 # 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
 23 
-24   # prolog
-25   89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
-26   # call ascii-difference(argv[1], argv[2])
-27     # push argv[2]
-28   ff          6/subop/push        1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           .           0xc/disp8       .                 # push *(EBP+12)
-29     # push argv[1]
-30   ff          6/subop/push        1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           .           0x8/disp8       .                 # push *(EBP+8)
-31     # call
+24   # prolog
+25   89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
+26   # call ascii-difference(argv[1], argv[2])
+27     # push argv[2]
+28   ff          6/subop/push        1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           .           0xc/disp8       .                 # push *(EBP+12)
+29     # push argv[1]
+30   ff          6/subop/push        1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           .           0x8/disp8       .                 # push *(EBP+8)
+31     # call
 32   e8/call  ascii-difference/disp32
-33     # discard args
-34   81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
-35   # exit(EAX)
-36   89/copy                         3/mod/direct    3/rm32/EBX    .           .             .           0/r32/EAX   .               .                 # copy EAX to EBX
+33     # discard args
+34   81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+35   # exit(EAX)
+36   89/copy                         3/mod/direct    3/rm32/EBX    .           .             .           0/r32/EAX   .               .                 # copy EAX to EBX
 37   b8/copy-to-EAX  1/imm32/exit
 38   cd/syscall  0x80/imm8
 39 
-40 ascii-difference:  # (s1, s2) : null-terminated ascii strings
-41   # a = first letter of s1 (ECX)
-42   8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none              0/r32/EAX   4/disp8         .                 # copy *(ESP+4) to EAX
-43   8b/copy                         0/mod/indirect  0/rm32/EAX    .           .             .           0/r32/EAX   .               .                 # copy *EAX to EAX
-44   # b = first letter of s2 (EDX)
-45   8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none              1/r32/ECX   8/disp8                           # copy *(ESP+8) to ECX
-46   8b/copy                         0/mod/indirect  1/rm32/ECX    .           .             .           1/r32/ECX   .               .                 # copy *ECX to ECX
-47   # a-b
-48   29/subtract                     3/mod/direct    0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # subtract ECX from EAX
+40 ascii-difference:  # (s1, s2) : null-terminated ascii strings
+41   # a = first letter of s1 (ECX)
+42   8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none              0/r32/EAX   4/disp8         .                 # copy *(ESP+4) to EAX
+43   8b/copy                         0/mod/indirect  0/rm32/EAX    .           .             .           0/r32/EAX   .               .                 # copy *EAX to EAX
+44   # b = first letter of s2 (EDX)
+45   8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none              1/r32/ECX   8/disp8                           # copy *(ESP+8) to ECX
+46   8b/copy                         0/mod/indirect  1/rm32/ECX    .           .             .           1/r32/ECX   .               .                 # copy *ECX to ECX
+47   # a-b
+48   29/subtract                     3/mod/direct    0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # subtract ECX from EAX
 49   c3/return
 50 
-51 # vim:nowrap:textwidth=0
+51 # vim:nowrap:textwidth=0
 
-- cgit 1.4.1-2-gfad0