about summary refs log tree commit diff stats
path: root/subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-07-26 12:19:02 -0700
committerKartik Agaram <vc@akkartik.com>2018-07-26 12:19:02 -0700
commit6e51c60c699f795f14e49744a10f91d9609b044e (patch)
tree56b7b3372929abb8850a99141341395d50518c47 /subx
parent7da8da495fbe9422f13198a83193d4b5477bf8f6 (diff)
downloadmu-6e51c60c699f795f14e49744a10f91d9609b044e.tar.gz
4424
Clean up format of example programs.
Diffstat (limited to 'subx')
-rw-r--r--subx/ex1.1.subx12
-rw-r--r--subx/ex1.2.subx12
-rw-r--r--subx/ex2.subx14
-rw-r--r--subx/ex3.subx24
-rw-r--r--subx/ex4.subx30
-rw-r--r--subx/ex5.subx37
-rw-r--r--subx/ex6.subx12
7 files changed, 70 insertions, 71 deletions
diff --git a/subx/ex1.1.subx b/subx/ex1.1.subx
index 220af79e..51152f47 100644
--- a/subx/ex1.1.subx
+++ b/subx/ex1.1.subx
@@ -6,12 +6,12 @@
 #   $ subx run ex1
 
 == 0x08048054  # code segment, after leaving room for ELF header
-# opcode        ModR/M                    SIB                   displacement    immediate
-# instruction   mod, reg, Reg/Mem bits    scale, index, base
-# 1-3 bytes     0/1 byte                  0/1 byte              0/1/2/4 bytes   0/1/2/4 bytes
-  bb                                                                            2a 00 00 00   # copy 0x2a (42) to EBX
+# instruction                     effective address                                           operand     displacement    immediate
+# op          subop               mod             rm32          base      index     scale     r32
+# 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
+  bb                                                                                                                      2a 00 00 00       # copy 0x2a (42) to EBX
   # exit(EBX)
-  b8                                                                            01 00 00 00   # copy 1 to EAX
-  cd                                                                            80            # int 80h
+  b8                                                                                                                      01 00 00 00       # copy 1 to EAX
+  cd                                                                                                                      80                # int 80h
 
 # vim:ft=subx
diff --git a/subx/ex1.2.subx b/subx/ex1.2.subx
index 81f2bfe2..1dac17e5 100644
--- a/subx/ex1.2.subx
+++ b/subx/ex1.2.subx
@@ -6,12 +6,12 @@
 #   $ subx run ex1
 
 == 0x08048054  # code segment, after leaving room for ELF header
-# opcode        ModR/M                    SIB                   displacement    immediate
-# instruction   mod, reg, Reg/Mem bits    scale, index, base
-# 1-3 bytes     0/1 byte                  0/1 byte              0/1/2/4 bytes   0/1/2/4 bytes
-  bb                                                                            42/imm32      # copy 0x2a (42) to EBX
+# instruction                     effective address                                           operand     displacement    immediate
+# op          subop               mod             rm32          base      index     scale     r32
+# 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
+  bb                                                                                                                      42/imm32          # copy 0x2a (42) to EBX
   # exit(EBX)
-  b8                                                                            1/imm32       # copy 1 to EAX
-  cd                                                                            128/imm8      # int 80h
+  b8                                                                                                                      1/imm32           # copy 1 to EAX
+  cd                                                                                                                      128/imm8          # int 80h
 
 # vim:ft=subx
diff --git a/subx/ex2.subx b/subx/ex2.subx
index 21c0ec54..19c9bb93 100644
--- a/subx/ex2.subx
+++ b/subx/ex2.subx
@@ -8,13 +8,13 @@
 #   2
 
 == 0x08048054  # code segment, after leaving room for ELF header
-# instruction             effective address                                         operand displacement    immediate
-# op          subop       mod           rm32          base      index     scale     r32
-# 1-3 bytes                                                                                 0/1/2/4 bytes   0/1/2/4 bytes
-  bb                                                                                                        1/imm32       # copy 1 to EBX
-  81          0/add/subop 3/mod/direct  3/ebx/rm32                                                          1/imm32       # add 1 to EBX
+# instruction                     effective address                                           operand     displacement    immediate
+# op          subop               mod             rm32          base      index     scale     r32
+# 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
+  bb                                                                                                                      1/imm32           # copy 1 to EBX
+  81          0/add/subop         3/mod/direct    3/ebx/rm32                                                              1/imm32           # add 1 to EBX
   # exit(EBX)
-  b8                                                                                                        1/imm32       # copy 1 to EAX
-  cd                                                                                                        128/imm8      # int 80h
+  b8                                                                                                                      1/imm32           # copy 1 to EAX
+  cd                                                                                                                      128/imm8          # int 80h
 
 # vim:ft=subx
diff --git a/subx/ex3.subx b/subx/ex3.subx
index 9b5391a8..f9df8703 100644
--- a/subx/ex3.subx
+++ b/subx/ex3.subx
@@ -8,29 +8,29 @@
 #   55
 
 == 0x08048054  # code segment, after leaving room for ELF header
-# instruction                     effective address                                         operand     displacement    immediate
-# op          subop               mod           rm32          base      index     scale     r32
-# 1-3 bytes                                                                                             0/1/2/4 bytes   0/1/2/4 bytes
+# instruction                     effective address                                           operand     displacement    immediate
+# op          subop               mod             rm32          base      index     scale     r32
+# 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
   # result: EBX = 0
 # 0: e_entry = 0x08048054
-  bb                                                                                                                    0/imm32       # copy 0 to EBX
+  bb                                                                                                                      0/imm32           # copy 0 to EBX
   # counter: ECX = 1
-  b9                                                                                                                    1/imm32       # copy 1 to ECX
+  b9                                                                                                                      1/imm32           # copy 1 to ECX
 
 # 10: loop: 0x0804805e
   # while (ECX <= 10)
-  81            7/subop/compare   3/mod/direct  1/rm32/ecx                                                              10/imm32      # compare ECX, 10/imm
-  7f                                                                                                    10/disp8                      # jump-if-greater exit
+  81            7/subop/compare   3/mod/direct    1/rm32/ecx                                                              10/imm32          # compare ECX, 10/imm
+  7f                                                                                                      10/disp8                          # jump-if-greater exit
   # EBX += ECX
-  01                              3/mod/direct  3/rm32/ebx                                  1/r32/ecx                                 # add ECX to EBX
+  01                              3/mod/direct    3/rm32/ebx                                  1/r32/ecx                                     # add ECX to EBX
   # ECX++
-  81            0/subop/add       3/mod/direct  1/rm32/ecx                                                              1/imm32       # add 1 to ECX
+  81            0/subop/add       3/mod/direct    1/rm32/ecx                                                              1/imm32           # add 1 to ECX
   # loop
-  eb                                                                                                    -18/disp8                     # jump loop
+  eb                                                                                                      -18/disp8                         # jump loop
 
 # 28: exit: 0x08048070
   # exit(EBX)
-  b8                                                                                                                    1/imm32       # copy 1 to EAX
-  cd                                                                                                                    0x80/imm8     # int 80h
+  b8                                                                                                                      1/imm32           # copy 1 to EAX
+  cd                                                                                                                      0x80/imm8         # int 80h
 
 # vim:ft=subx:nowrap
diff --git a/subx/ex4.subx b/subx/ex4.subx
index 2d841a81..81c65dae 100644
--- a/subx/ex4.subx
+++ b/subx/ex4.subx
@@ -5,37 +5,37 @@
 #   $ subx run ex4
 
 == 0x08048074  # code segment, after leaving room for ELF header and segment headers
-# instruction                     effective address                                         operand     displacement    immediate
-# op          subop               mod           rm32          base      index     scale     r32
-# 1-3 bytes                                                                                             0/1/2/4 bytes   0/1/2/4 bytes
+# instruction                     effective address                                           operand     displacement    immediate
+# op          subop               mod             rm32          base      index     scale     r32
+# 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
 
   ## read(stdin, x, 1)
   # fd = 0 (stdin)
-  bb                                                                                                                    0/imm32       # copy 0 to EBX
+  bb                                                                                                                      0/imm32           # copy 0 to EBX
   # set location to write to
-  b9                                                                                                                    0x080490a7/imm32  # copy to ECX
+  b9                                                                                                                      0x080490a7/imm32  # copy to ECX
   # size = 1 character
-  ba                                                                                                                    1/imm32       # copy 1 to EDX
+  ba                                                                                                                      1/imm32           # copy 1 to EDX
   # syscall = read
-  b8                                                                                                                    3/imm32       # copy 3 to EAX
+  b8                                                                                                                      3/imm32           # copy 3 to EAX
   # call
-  cd                                                                                                                    128/imm8      # int 80h
+  cd                                                                                                                      128/imm8          # int 80h
 
   ## write(stdout, x, 1)
   # fd = 1 (stdout)
-  bb                                                                                                                    1/imm32       # copy 1 to EBX
+  bb                                                                                                                      1/imm32           # copy 1 to EBX
   # set location to write to
-  b9                                                                                                                    0x080490a7/imm32  # copy to ECX
+  b9                                                                                                                      0x080490a7/imm32  # copy to ECX
   # size = 1 character
-  ba                                                                                                                    1/imm32       # copy 1 to EDX
+  ba                                                                                                                      1/imm32           # copy 1 to EDX
   # syscall = write
-  b8                                                                                                                    4/imm32       # copy 4 to EAX
+  b8                                                                                                                      4/imm32           # copy 4 to EAX
   # call
-  cd                                                                                                                    128/imm8      # int 80h
+  cd                                                                                                                      128/imm8          # int 80h
 
   ## exit(EBX)
-  b8                                                                                                                    1/imm32       # copy 1 to EAX
-  cd                                                                                                                    128/imm8      # int 80h
+  b8                                                                                                                      1/imm32           # copy 1 to EAX
+  cd                                                                                                                      128/imm8          # int 80h
 
 == 0x080490a7
 00 00 00 00  # space for read() to write to
diff --git a/subx/ex5.subx b/subx/ex5.subx
index b74af463..65ca4807 100644
--- a/subx/ex5.subx
+++ b/subx/ex5.subx
@@ -5,44 +5,43 @@
 #   $ subx run ex5
 
 == 0x08048054  # code segment, after leaving room for ELF header and segment headers
-# instruction                     effective address                                         operand     displacement    immediate
-# op          subop               mod           rm32          base      index     scale     r32
-# 1-3 bytes                                                                                             0/1/2/4 bytes   0/1/2/4 bytes
+# instruction                     effective address                                           operand     displacement    immediate
+# op          subop               mod             rm32          base      index     scale     r32
+# 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
 
 ## function main
   # prolog
-  55                                                                                                                                  # push EBP
-  89                              3/mod/direct  5/rm32/EBP                                  4/r32/ESP                                 # copy ESP to EBP
+  55                                                                                                                                        # push EBP
+  89                              3/mod/direct    5/rm32/EBP                                  4/r32/ESP                                     # copy ESP to EBP
   # allocate x on the stack
-  81            5/subop/subtract  3/mod/direct  4/rm32/ESP                                                              4/imm32       # subtract 4 bytes from ESP
+  81            5/subop/subtract  3/mod/direct    4/rm32/ESP                                                              4/imm32           # subtract 4 bytes from ESP
 
   ## read(stdin, x, 1)
   # fd = 0 (stdin)
-  bb                                                                                                                    0/imm32       # copy 0 to EBX
+  bb                                                                                                                      0/imm32           # copy 0 to EBX
   # set location to read character to
-  89                              3/mod/direct  1/rm32/ECX                                  5/r32/EBP                                 # copy EBP to ECX
+  89                              3/mod/direct    1/rm32/ECX                                  5/r32/EBP                                     # copy EBP to ECX
   # size = 1 character
-  ba                                                                                                                    1/imm32       # copy 1 to EDX
+  ba                                                                                                                      1/imm32           # copy 1 to EDX
   # syscall = read
-  b8                                                                                                                    3/imm32       # copy 3 to EAX
+  b8                                                                                                                      3/imm32           # copy 3 to EAX
   # call
-  cd                                                                                                                    0x80/imm8     # int 80h
+  cd                                                                                                                      0x80/imm8         # int 80h
 
   ## write(stdout, x, 1)
   # fd = 1 (stdout)
-  bb                                                                                                                    1/imm32       # copy 1 to EBX
+  bb                                                                                                                      1/imm32           # copy 1 to EBX
   # set location of character to write out
-  89                              3/mod/direct  1/rm32/ECX                                  5/r32/EBP                                 # copy EBP to ECX
-                # ModR/M: 11 (direct mode) 101 (src EBP) 001 (dest ECX)
+  89                              3/mod/direct    1/rm32/ECX                                  5/r32/EBP                                     # copy EBP to ECX
   # size = 1 character
-  ba                                                                                                                    1/imm32       # copy 1 to EDX
+  ba                                                                                                                      1/imm32           # copy 1 to EDX
   # syscall = write
-  b8                                                                                                                    4/imm32       # copy 4 to EAX
+  b8                                                                                                                      4/imm32           # copy 4 to EAX
   # call
-  cd                                                                                                                    0x80/imm8     # int 80h
+  cd                                                                                                                      0x80/imm8         # int 80h
 
   ## exit(EBX)
-  b8                                                                                                                    1/imm32       # copy 1 to EAX
-  cd                                                                                                                    0x80/imm8     # int 80h
+  b8                                                                                                                      1/imm32           # copy 1 to EAX
+  cd                                                                                                                      0x80/imm8         # int 80h
 
 # vim:ft=subx:nowrap
diff --git a/subx/ex6.subx b/subx/ex6.subx
index 5e4f34f5..68dcb8be 100644
--- a/subx/ex6.subx
+++ b/subx/ex6.subx
@@ -6,9 +6,9 @@
 #   Hello, world!
 
 == 0x08048074  # code segment, after leaving room for ELF header and segment headers
-# instruction                     effective address                                         operand     displacement    immediate
+# instruction                     effective address                                           operand     displacement    immediate
 # op          subop               mod             rm32          base      index     scale     r32
-# 1-3 bytes                                                                                               0/1/2/4 bytes   0/1/2/4 bytes
+# 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
 
   ## write(stdout, x, 1)
   # fd = 1 (stdout)
@@ -19,13 +19,13 @@
   ba                                                                                                                      0x08049093/imm32  # copy to EDX
   8b                              0/mod/indirect  2/rm32/edx                                  2/r32/edx                                     # copy *EDX to EDX
   # syscall = write
-  b8                                                                                                                      4/imm32       # copy 4 to EAX
+  b8                                                                                                                      4/imm32           # copy 4 to EAX
   # call
-  cd                                                                                                                      0x80/imm8     # int 80h
+  cd                                                                                                                      0x80/imm8         # int 80h
 
   ## exit(EBX)
-  b8                                                                                                                      1/imm32       # copy 1 to EAX
-  cd                                                                                                                      0x80/imm8     # int 80h
+  b8                                                                                                                      1/imm32           # copy 1 to EAX
+  cd                                                                                                                      0x80/imm8         # int 80h
 
 == 0x08049093
 # size of string