about summary refs log tree commit diff stats
path: root/subx/examples
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-09-01 23:03:50 -0700
committerKartik Agaram <vc@akkartik.com>2018-09-01 23:03:50 -0700
commita6517ed821ff39fa56eb3b975799d22497d78a48 (patch)
treeb934f09748be6c9dce80d4caf926d0f8dd2c9916 /subx/examples
parentf39c01128dfc6e46828cbab992d4b9e0ba1cb1e5 (diff)
downloadmu-a6517ed821ff39fa56eb3b975799d22497d78a48.tar.gz
4535 - support for global variable names
Diffstat (limited to 'subx/examples')
-rw-r--r--subx/examples/ex4.subx7
-rw-r--r--subx/examples/ex6.subx12
-rwxr-xr-xsubx/examples/ex7bin313 -> 313 bytes
-rw-r--r--subx/examples/ex7.subx72
4 files changed, 48 insertions, 43 deletions
diff --git a/subx/examples/ex4.subx b/subx/examples/ex4.subx
index 2f5b0e73..89b3bdc9 100644
--- a/subx/examples/ex4.subx
+++ b/subx/examples/ex4.subx
@@ -13,7 +13,7 @@
   # fd = 0 (stdin)
   bb/copy                                                                                                                         0/imm32           # copy 0 to EBX
   # initialize x (location to write result to)
-  b9/copy                                                                                                                         0x080490a7/imm32  # copy to ECX
+  b9/copy                                                                                                                         x/imm32           # copy to ECX
   # size = 1 character
   ba/copy                                                                                                                         1/imm32           # copy 1 to EDX
   # read(fd, x, size)
@@ -24,7 +24,7 @@
   # fd = 1 (stdout)
   bb/copy                                                                                                                         1/imm32           # copy 1 to EBX
   # initialize x (location to read from)
-  b9/copy                                                                                                                         0x080490a7/imm32  # copy to ECX
+  b9/copy                                                                                                                         x/imm32           # copy to ECX
   # size = 1 character
   ba/copy                                                                                                                         1/imm32           # copy 1 to EDX
   # write(fd, x, size)
@@ -35,7 +35,8 @@
   b8/copy                                                                                                                         1/imm32           # copy 1 to EAX
   cd/syscall                                                                                                                      0x80/imm8         # int 80h
 
-== 0x080490a7  # data segment
+== data
+x:
 00 00 00 00  # space for read() to write to
 
 # vim:ft=subx:nowrap
diff --git a/subx/examples/ex6.subx b/subx/examples/ex6.subx
index 3d05f00a..48dbb7a3 100644
--- a/subx/examples/ex6.subx
+++ b/subx/examples/ex6.subx
@@ -14,9 +14,9 @@
   # fd = 1 (stdout)
   bb/copy                                                                                                                         1/imm32           # copy 1 to EBX
   # initialize x (location to write result to)
-  b9/copy                                                                                                                         0x08049097/imm32  # copy to ECX
+  b9/copy                                                                                                                         x/imm32           # copy to ECX
   # initialize size
-  ba/copy                                                                                                                         0x08049093/imm32  # copy to EDX
+  ba/copy                                                                                                                         size/imm32        # copy to EDX
   8b/copy                         0/mod/indirect  2/rm32/EDX                                          2/r32/EDX                                     # copy *EDX to EDX
   # write(fd, x, size)
   b8/copy                                                                                                                         4/imm32           # copy 4 to EAX
@@ -26,10 +26,10 @@
   b8/copy                                                                                                                         1/imm32           # copy 1 to EAX
   cd/syscall                                                                                                                      0x80/imm8         # int 80h
 
-== 0x08049093  # data segment
-# size of string
-0e 00 00 00
-# string
+== data
+size:  # size of string
+  0e 00 00 00  # 14
+x:  # string to print
   48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21 0a       00
 # h  e  l  l  o  ,  ␣  w  o  r  l  d  !  newline  null
 
diff --git a/subx/examples/ex7 b/subx/examples/ex7
index d756271e..39f6f98d 100755
--- a/subx/examples/ex7
+++ b/subx/examples/ex7
Binary files differdiff --git a/subx/examples/ex7.subx b/subx/examples/ex7.subx
index 17a38e29..6e0294d9 100644
--- a/subx/examples/ex7.subx
+++ b/subx/examples/ex7.subx
@@ -16,84 +16,88 @@
 # 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
 
   ## creat(filename)
-  bb/copy                         .               .             .           .             .           .           .               0x08049131/imm32/fname  # copy to EBX
-  b9/copy                         .               .             .           .             .           .           .               0x180/imm32/fixed-perms # copy 0 to ECX
+  bb/copy                         .               .             .           .             .           .           .               filename/imm32          # copy to EBX
+  b9/copy                         .               .             .           .             .           .           .               0x180/imm32/fixed-perms # copy to ECX
   b8/copy                         .               .             .           .             .           .           .               8/imm32/creat           # copy 8 to EAX
   cd/syscall                      .               .             .           .             .           .           .               0x80/imm8               # int 80h
 
-  ## fd = open(filename, O_WRONLY, 0)
-  bb/copy                         .               .             .           .             .           .           .               0x08049131/imm32/fname  # copy to EBX
+  ## stream = open(filename, O_WRONLY, 0)  # we can't use 'fd' because it looks like a hex byte
+  bb/copy                         .               .             .           .             .           .           .               filename/imm32          # copy to EBX
   b9/copy                         .               .             .           .             .           .           .               1/imm32/wronly          # copy 1 to ECX
   ba/copy                         .               .             .           .             .           .           .               0x180/imm32/fixed-perms # copy 0 to EDX
   b8/copy                         .               .             .           .             .           .           .               5/imm32/open            # copy 5 to EAX
   cd/syscall                      .               .             .           .             .           .           .               0x80/imm8               # int 80h
-  # save fd
-  bb/copy                         .               .             .           .             .           .           .               0x08049125/imm32/fd     # copy to EBX
+  # save stream
+  bb/copy                         .               .             .           .             .           .           .               stream/imm32            # copy to EBX
   89/copy                         0/mod/indirect  3/rm32/EBX                                          0/r32/EAX                                           # copy EAX to *EBX
 
-  ## write(fd, "a", 1)
-  # load fd
-  bb/copy                         .               .             .           .             .           .           .               0x08049125/imm32/fd     # copy to EBX
+  ## write(stream, "a", 1)
+  # load stream
+  bb/copy                         .               .             .           .             .           .           .               stream/imm32            # copy to EBX
   8b/copy                         0/mod/indirect  3/rm32/EBX                                          3/r32/EBX                                           # copy *EBX to EBX
   #
-  b9/copy                         .               .             .           .             .           .           .               0x08049129/imm32/a      # copy to ECX
+  b9/copy                         .               .             .           .             .           .           .               a/imm32                 # copy to ECX
   ba/copy                         .               .             .           .             .           .           .               1/imm32/size            # copy 1 to EDX
   b8/copy                         .               .             .           .             .           .           .               4/imm32/write           # copy 4 to EAX
   cd/syscall                      .               .             .           .             .           .           .               0x80/imm8               # int 80h
 
-  ## close(fd)
-  # load fd
-  bb/copy                         .               .             .           .             .           .           .               0x08049125/imm32/fd     # copy to EBX
+  ## close(stream)
+  # load stream
+  bb/copy                         .               .             .           .             .           .           .               stream/imm32            # copy to EBX
   8b/copy                         0/mod/indirect  3/rm32/EBX                                          3/r32/EBX                                           # copy *EBX to EBX
   #
   b8/copy                         .               .             .           .             .           .           .               6/imm32/close           # copy 6 to EAX
   cd/syscall                      .               .             .           .             .           .           .               0x80/imm8               # int 80h
 
-  ## fd = open(filename, O_RDONLY, 0)
-  bb/copy                         .               .             .           .             .           .           .               0x08049131/imm32/fname  # copy to EBX
+  ## stream = open(filename, O_RDONLY, 0)
+  bb/copy                         .               .             .           .             .           .           .               filename/imm32          # copy to EBX
   b9/copy                         .               .             .           .             .           .           .               0/imm32/rdonly          # copy 0 to ECX
-  ba/copy                         .               .             .           .             .           .           .               0x180/imm32/fixed-perms # copy 0 to EDX
+  ba/copy                         .               .             .           .             .           .           .               0x180/imm32/fixed-perms # copy to EDX
   b8/copy                         .               .             .           .             .           .           .               5/imm32/open            # copy 5 to EAX
   cd/syscall                      .               .             .           .             .           .           .               0x80/imm8               # int 80h
-  # save fd
-  bb/copy                         .               .             .           .             .           .           .               0x08049125/imm32/fd     # copy to EBX
+  # save stream
+  bb/copy                         .               .             .           .             .           .           .               stream/imm32            # copy to EBX
   89/copy                         0/mod/indirect  3/rm32/EBX                                          0/r32/EAX                                           # copy EAX to *EBX
 
-  ## read(fd, b, 1)
-  # load fd
-  bb/copy                         .               .             .           .             .           .           .               0x08049125/imm32/fd     # copy to EBX
+  ## read(stream, b, 1)
+  # load stream
+  bb/copy                         .               .             .           .             .           .           .               stream/imm32            # copy to EBX
   8b/copy                         0/mod/indirect  3/rm32/EBX                                          3/r32/EBX                                           # copy *EBX to EBX
   #
-  b9/copy                         .               .             .           .             .           .           .               0x0804912d/imm32/b      # copy to ECX
+  b9/copy                         .               .             .           .             .           .           .               b/imm32                 # copy to ECX
   ba/copy                         .               .             .           .             .           .           .               1/imm32/size            # copy 1 to EDX
   b8/copy                         .               .             .           .             .           .           .               3/imm32/read            # copy 3 to EAX
   cd/syscall                      .               .             .           .             .           .           .               0x80/imm8               # int 80h
 
-  ## close(fd)
-  # load fd
-  bb/copy                         .               .             .           .             .           .           .               0x08049125/imm32/fd     # copy to EBX
+  ## close(stream)
+  # load stream
+  bb/copy                         .               .             .           .             .           .           .               stream/imm32            # copy to EBX
   8b/copy                         0/mod/indirect  3/rm32/EBX                                          3/r32/EBX                                           # copy *EBX to EBX
   #
-  b8/copy                         .               .             .           .             .           .           .               6/imm32/close           # copy 8 to EAX
+  b8/copy                         .               .             .           .             .           .           .               6/imm32/close           # copy 6 to EAX
   cd/syscall                      .               .             .           .             .           .           .               0x80/imm8               # int 80h
 
   ## unlink(filename)
-  bb/copy                         .               .             .           .             .           .           .               0x08049131/imm32/fname  # copy to EBX
-  b8/copy                         .               .             .           .             .           .           .               0xa/imm32/unlink        # copy 8 to EAX
+  bb/copy                         .               .             .           .             .           .           .               filename/imm32          # copy to EBX
+  b8/copy                         .               .             .           .             .           .           .               0xa/imm32/unlink        # copy 10 to EAX
   cd/syscall                      .               .             .           .             .           .           .               0x80/imm8               # int 80h
 
   ## exit(b)
   # load b
-  bb/copy                         .               .             .           .             .           .           .               0x0804912d/imm32/b      # copy to EBX
+  bb/copy                         .               .             .           .             .           .           .               b/imm32                 # copy to EBX
   8b/copy                         0/mod/indirect  3/rm32/EBX                                          3/r32/EBX                                           # copy *EBX to EBX
   #
   b8/copy                         .               .             .           .             .           .           .               1/imm32/exit            # copy 1 to EAX
   cd/syscall                      .               .             .           .             .           .           .               0x80/imm8               # int 80h
 
-== 0x08049125  # data segment
-00 00 00 00  # fd
-61 00 00 00  # a: string to write to file: 'a'
-00 00 00 00  # b: space for string read from file
-2e 66 6f 6f 00 00 00 00  # filename: '.foo'
+== data
+stream:
+00 00 00 00
+a:
+61 00 00 00
+b:
+00 00 00 00
+filename:
+2e 66 6f 6f 00 00 00 00
 
 # vim:ft=subx:nowrap:tw&