about summary refs log tree commit diff stats
path: root/examples
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-09-11 19:04:49 -0700
committerKartik Agaram <vc@akkartik.com>2019-09-11 19:53:23 -0700
commitecfbbfb5b58aaba9f9265cb13b9fb4a914bdcf37 (patch)
tree486cd5f4ee75323b5c733912c7a58501d65b0325 /examples
parent4d53de8afa0d44e29d3caeb01ccdd02bc2e4cd70 (diff)
downloadmu-ecfbbfb5b58aaba9f9265cb13b9fb4a914bdcf37.tar.gz
5647 - experimental support for swapping OS
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/ex1bin128 -> 197 bytes
-rw-r--r--examples/ex1.subx9
-rwxr-xr-xexamples/ex10bin195 -> 264 bytes
-rw-r--r--examples/ex10.subx9
-rwxr-xr-xexamples/ex11bin1111 -> 1178 bytes
-rw-r--r--examples/ex11.subx12
-rwxr-xr-xexamples/ex12bin167 -> 234 bytes
-rw-r--r--examples/ex12.subx14
-rwxr-xr-xexamples/ex2bin129 -> 198 bytes
-rw-r--r--examples/ex2.subx9
-rwxr-xr-xexamples/ex3bin146 -> 215 bytes
-rw-r--r--examples/ex3.subx9
-rwxr-xr-xexamples/ex4bin171 -> 236 bytes
-rw-r--r--examples/ex4.subx19
-rwxr-xr-xexamples/ex5bin171 -> 238 bytes
-rw-r--r--examples/ex5.subx14
-rwxr-xr-xexamples/ex6bin165 -> 232 bytes
-rw-r--r--examples/ex6.subx16
-rwxr-xr-xexamples/ex7bin313 -> 366 bytes
-rw-r--r--examples/ex7.subx49
-rwxr-xr-xexamples/ex8bin165 -> 234 bytes
-rw-r--r--examples/ex8.subx7
-rwxr-xr-xexamples/ex9bin159 -> 228 bytes
-rw-r--r--examples/ex9.subx9
24 files changed, 69 insertions, 107 deletions
diff --git a/examples/ex1 b/examples/ex1
index aeb62302..5f17bc66 100755
--- a/examples/ex1
+++ b/examples/ex1
Binary files differdiff --git a/examples/ex1.subx b/examples/ex1.subx
index fae025c0..89ac8bce 100644
--- a/examples/ex1.subx
+++ b/examples/ex1.subx
@@ -8,14 +8,11 @@
 #   $ echo $?
 #   42
 
-== code 0x09000000
+== code
 
 Entry:
-# syscall(exit, 42)
+# exit(42)
 bb/copy-to-ebx  2a/imm32  # 42 in hex
-b8/copy-to-eax  1/imm32/exit
-cd/syscall  0x80/imm8
-
-== data 0x0a000000
+e8/call  syscall_exit/disp32
 
 # . . vim:nowrap:textwidth=0
diff --git a/examples/ex10 b/examples/ex10
index d8ad528e..cb8973fe 100755
--- a/examples/ex10
+++ b/examples/ex10
Binary files differdiff --git a/examples/ex10.subx b/examples/ex10.subx
index c32c44ea..36a21bbe 100644
--- a/examples/ex10.subx
+++ b/examples/ex10.subx
@@ -7,7 +7,7 @@
 #   $ echo $?
 #   0  # false
 
-== code 0x09000000
+== code
 #   instruction                     effective address                                                   register    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
@@ -27,10 +27,9 @@ Entry:  # return argv-equal(argv[1], argv[2])
     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
     # . . call
     e8/call argv-equal/disp32
-    # syscall(exit, eax)
+    # exit(eax)
     89/copy                         3/mod/direct    3/rm32/ebx    .           .             .           0/r32/eax   .               .                 # copy eax to ebx
-    b8/copy-to-eax  1/imm32/exit
-    cd/syscall  0x80/imm8
+    e8/call  syscall_exit/disp32
 
 # compare two null-terminated ascii strings
 # reason for the name: the only place we should have null-terminated ascii strings is from commandline args
@@ -67,6 +66,4 @@ $argv-equal:false:
     b8/copy-to-eax  0/imm32
     c3/return
 
-== data 0x0a000000
-
 # . . vim:nowrap:textwidth=0
diff --git a/examples/ex11 b/examples/ex11
index 0ffafb6f..1cb1aa5c 100755
--- a/examples/ex11
+++ b/examples/ex11
Binary files differdiff --git a/examples/ex11.subx b/examples/ex11.subx
index ff0977df..a6a24cfc 100644
--- a/examples/ex11.subx
+++ b/examples/ex11.subx
@@ -14,17 +14,16 @@
 # because checking for it would require the function being tested! Breakage
 # would cause tests to not run, rather than to fail as we'd like.)
 
-== code 0x09000000
+== code
 #   instruction                     effective address                                                   register    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
 
 Entry:  # run all tests
     e8/call  run-tests/disp32  # 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.
-    # syscall(exit, eax)
+    # exit(eax)
     89/copy                         3/mod/direct    3/rm32/ebx    .           .             .           0/r32/eax   .               .                 # copy eax to ebx
-    b8/copy-to-eax  1/imm32/exit
-    cd/syscall  0x80/imm8
+    e8/call  syscall_exit/disp32
 
 # compare a null-terminated ascii string with a more idiomatic length-prefixed byte array
 # reason for the name: the only place we should have null-terminated ascii strings is from commandline args
@@ -327,8 +326,7 @@ write-stderr:  # s : (address array byte) -> <void>
     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           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
+    e8/call  syscall_write/disp32
     # . restore registers
     5b/pop-to-ebx
     5a/pop-to-edx
@@ -339,7 +337,7 @@ write-stderr:  # s : (address array byte) -> <void>
     5d/pop-to-ebp
     c3/return
 
-== data 0x0a000000
+== data
 
 Newline:
     # size
diff --git a/examples/ex12 b/examples/ex12
index c13a86ed..80e5deeb 100755
--- a/examples/ex12
+++ b/examples/ex12
Binary files differdiff --git a/examples/ex12.subx b/examples/ex12.subx
index 571d42d8..dafa0071 100644
--- a/examples/ex12.subx
+++ b/examples/ex12.subx
@@ -6,26 +6,24 @@
 #   $ ./subx run examples/ex12
 # You shouldn't get a segmentation fault.
 
-== code 0x09000000
+== code
 #   instruction                     effective address                                                   register    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
 
 Entry:
-    # syscall(mmap, 0x1000)
+    # mmap(Mmap-new-segment->len)
     bb/copy-to-ebx  Mmap-new-segment/imm32
-    b8/copy-to-eax  0x5a/imm32/mmap
-    cd/syscall  0x80/imm8
+    e8/call  syscall_mmap/disp32
 
     # write to *eax to check that we have access to the newly-allocated segment
     c7          0/subop/copy        0/mod/direct    0/rm32/eax    .           .             .           .           .               0x34/imm32        # copy to *eax
 
-    # syscall(exit, eax)
+    # exit(eax)
     89/copy                         3/mod/direct    3/rm32/ebx    .           .             .           0/r32/eax   .               .                 # copy eax to ebx
-    b8/copy-to-eax  1/imm32/exit
-    cd/syscall  0x80/imm8
+    e8/call  syscall_exit/disp32
 
-== data 0x0a000000
+== data
 
 # various constants used here were found in the Linux sources (search for file mman-common.h)
 Mmap-new-segment:  # type mmap_arg_struct
diff --git a/examples/ex2 b/examples/ex2
index 55a87a3f..5e0c1be1 100755
--- a/examples/ex2
+++ b/examples/ex2
Binary files differdiff --git a/examples/ex2.subx b/examples/ex2.subx
index 83b48aad..f99704de 100644
--- a/examples/ex2.subx
+++ b/examples/ex2.subx
@@ -7,17 +7,14 @@
 #   $ echo $?
 #   2
 
-== code 0x09000000
+== code
 
 Entry:
 # ebx = 1
 bb/copy-to-ebx  1/imm32
 # increment ebx
 43/increment-ebx
-# syscall(exit, ebx)
-b8/copy-to-eax  1/imm32/exit
-cd/syscall  0x80/imm8
-
-== data 0x0a000000
+# exit(ebx)
+e8/call  syscall_exit/disp32
 
 # . . vim:nowrap:textwidth=0
diff --git a/examples/ex3 b/examples/ex3
index d85aba8e..af787c11 100755
--- a/examples/ex3
+++ b/examples/ex3
Binary files differdiff --git a/examples/ex3.subx b/examples/ex3.subx
index 84789f3a..21acfd66 100644
--- a/examples/ex3.subx
+++ b/examples/ex3.subx
@@ -7,7 +7,7 @@
 #   $ echo $?
 #   55
 
-== code 0x09000000
+== code
 #   instruction                     effective address                                                   register    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
@@ -30,10 +30,7 @@ $loop:
     eb/jump  $loop/disp8
 
 $exit:
-    # syscall(exit, ebx)
-    b8/copy-to-eax  1/imm32/exit
-    cd/syscall  0x80/imm8
-
-== data 0x0a000000
+    # exit(ebx)
+    e8/call  syscall_exit/disp32
 
 # . . vim:nowrap:textwidth=0
diff --git a/examples/ex4 b/examples/ex4
index 66fb61e6..35ade1ee 100755
--- a/examples/ex4
+++ b/examples/ex4
Binary files differdiff --git a/examples/ex4.subx b/examples/ex4.subx
index a8e0efaa..4ef72749 100644
--- a/examples/ex4.subx
+++ b/examples/ex4.subx
@@ -4,16 +4,16 @@
 #   $ ./subx translate examples/ex4.subx -o examples/ex4
 #   $ ./subx run examples/ex4
 
-== data 0x0a000000
+== data
 
 # the global variable we save to
 X:
     0/imm32  # space for read() to write to
 
-== code 0x09000000
+== code
 
 Entry:
-# syscall(read, stdin, X, 1)
+# read(stdin, X, 1)
 # . fd = 0 (stdin)
 bb/copy-to-ebx  0/imm32
 # . data = X (location to write result to)
@@ -21,10 +21,9 @@ b9/copy-to-ecx  X/imm32
 # . size = 1 character
 ba/copy-to-edx  1/imm32
 # . syscall
-b8/copy-to-eax  3/imm32/read
-cd/syscall  0x80/imm8
+e8/call  syscall_read/disp32
 
-# syscall(write, stdout, X, 1)
+# write(stdout, X, 1)
 # . fd = 1 (stdout)
 bb/copy-to-ebx  1/imm32
 # . initialize X (location to read from)
@@ -32,11 +31,9 @@ b9/copy-to-ecx  X/imm32
 # . size = 1 character
 ba/copy-to-edx  1/imm32
 # . syscall
-b8/copy-to-eax  4/imm32/write
-cd/syscall  0x80/imm8
+e8/call  syscall_write/disp32
 
-# syscall(exit, ebx)
-b8/copy-to-eax  1/imm32/exit
-cd/syscall  0x80/imm8
+# exit(ebx)
+e8/call  syscall_exit/disp32
 
 # . . vim:nowrap:textwidth=0
diff --git a/examples/ex5 b/examples/ex5
index 37689c98..805cadc3 100755
--- a/examples/ex5
+++ b/examples/ex5
Binary files differdiff --git a/examples/ex5.subx b/examples/ex5.subx
index ad9ad29b..0ea9c5ee 100644
--- a/examples/ex5.subx
+++ b/examples/ex5.subx
@@ -4,7 +4,7 @@
 #   $ ./subx translate examples/ex5.subx -o examples/ex5
 #   $ ./subx run examples/ex5
 
-== code 0x09000000
+== code
 #   instruction                     effective address                                                   register    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
@@ -14,7 +14,7 @@ Entry:
     # allocate x on the stack
     81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # subtract from esp
 
-    # syscall(read, stdin, x, 1)
+    # read(stdin, x, 1)
     # . fd = 0 (stdin)
     bb/copy-to-ebx  0/imm32
     # . data = x (location to write result to)
@@ -22,8 +22,7 @@ Entry:
     # . size = 1 character
     ba/copy-to-edx  1/imm32
     # . syscall
-    b8/copy-to-eax  3/imm32/read
-    cd/syscall  0x80/imm8
+    e8/call  syscall_read/disp32
 
     # syscall(write, stdout, x, 1)
     # . fd = 1 (stdout)
@@ -36,10 +35,7 @@ Entry:
     b8/copy-to-eax  4/imm32/write
     cd/syscall  0x80/imm8
 
-    # syscall(exit, ebx)
-    b8/copy-to-eax  1/imm32/exit
-    cd/syscall  0x80/imm8
-
-== data 0x0a000000
+    # exit(ebx)
+    e8/call  syscall_exit/disp32
 
 # . . vim:nowrap:textwidth=0
diff --git a/examples/ex6 b/examples/ex6
index aa84591c..06fdfd7b 100755
--- a/examples/ex6
+++ b/examples/ex6
Binary files differdiff --git a/examples/ex6.subx b/examples/ex6.subx
index 396fa947..9955b201 100644
--- a/examples/ex6.subx
+++ b/examples/ex6.subx
@@ -5,13 +5,13 @@
 #   $ ./subx run examples/ex6
 #   Hello, world!
 
-== code 0x09000000
-#   instruction                     effective address                                                   register    displacement    immediate
+== code
+
 # . 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
 
 Entry:
-    # syscall(write, stdout, X, Size)
+    # write(stdout, X, Size)
     # . fd = 1 (stdout)
     bb/copy-to-ebx  1/imm32
     # . initialize X (location to write result to)
@@ -19,14 +19,12 @@ Entry:
     # . initialize Size
     8b/copy                         0/mod/indirect  5/rm32/.disp32            .             .           2/r32/edx   Size/disp32     .                 # copy *Size to edx
     # . syscall
-    b8/copy-to-eax  4/imm32/write
-    cd/syscall  0x80/imm8
+    e8/call  syscall_write/disp32
 
-    # syscall(exit, ebx)
-    b8/copy-to-eax  1/imm32/exit
-    cd/syscall  0x80/imm8
+    # exit(ebx)
+    e8/call  syscall_exit/disp32
 
-== data 0x0a000000
+== data
 
 Size:  # size of string
     0x0e/imm32  # 14
diff --git a/examples/ex7 b/examples/ex7
index 28c5bda9..0a535d45 100755
--- a/examples/ex7
+++ b/examples/ex7
Binary files differdiff --git a/examples/ex7.subx b/examples/ex7.subx
index ffef013d..cf684f86 100644
--- a/examples/ex7.subx
+++ b/examples/ex7.subx
@@ -11,88 +11,79 @@
 #   $ echo $?
 #   97
 
-== code 0x09000000
+== code
 #   instruction                     effective address                                                   register    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
 
 Entry:
-    # syscall(creat, Filename)
+    # creat(Filename)
     bb/copy-to-ebx  Filename/imm32
     b9/copy-to-ecx  0x180/imm32/fixed-perms
-    b8/copy-to-eax  8/imm32/creat
-    cd/syscall  0x80/imm8
+    e8/call  syscall_creat/disp32
 
-    # stream = syscall(open, Filename, O_WRONLY, 0)  # we can't use 'fd' because it looks like a hex byte
+    # stream = open(Filename, O_WRONLY, 0)  # we can't use 'fd' because it looks like a hex byte
     bb/copy-to-ebx  Filename/imm32
     b9/copy-to-ecx  1/imm32/wronly
     ba/copy-to-edx  0x180/imm32/fixed-perms
-    b8/copy-to-eax  5/imm32/open
-    cd/syscall  0x80/imm8
+    e8/call  syscall_open/disp32
     # save stream
     bb/copy-to-ebx  Stream/imm32
     89/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           0/r32/eax   .               .                 # copy eax to *ebx
 
-    # syscall(write, Stream, "a", 1)
+    # write(Stream, "a", 1)
     # . load stream
     bb/copy-to-ebx  Stream/imm32
     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
     # .
     b9/copy-to-ecx  A/imm32
     ba/copy-to-edx  1/imm32/size
-    b8/copy-to-eax  4/imm32/write
-    cd/syscall  0x80/imm8
+    e8/call  syscall_write/disp32
 
-    # syscall(close, Stream)
+    # close(Stream)
     # . load stream
     bb/copy-to-ebx  Stream/imm32
     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
     # .
-    b8/copy-to-eax  6/imm32/close
-    cd/syscall  0x80/imm8
+    e8/call  syscall_close/disp32
 
-    # stream = syscall(open, Filename, O_RDONLY, 0)
+    # stream = open(Filename, O_RDONLY, 0)
     bb/copy-to-ebx  Filename/imm32
     b9/copy-to-ecx  0/imm32/rdonly
     ba/copy-to-edx  0x180/imm32/fixed-perms
-    b8/copy-to-eax  5/imm32/open
-    cd/syscall  0x80/imm8
+    e8/call  syscall_open/disp32
     # . save Stream
     bb/copy-to-ebx  Stream/imm32
     89/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           0/r32/eax   .               .                 # copy eax to *ebx
 
-    # syscall(read, Stream, B, 1)
+    # read(Stream, B, 1)
     # . load stream
     bb/copy-to-ebx  Stream/imm32
     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
     # .
     b9/copy-to-ecx  B/imm32
     ba/copy-to-edx  1/imm32/size
-    b8/copy-to-eax  3/imm32/read
-    cd/syscall  0x80/imm8
+    e8/call  syscall_read/disp32
 
-    # syscall(close, Stream)
+    # close(Stream)
     # . load stream
     bb/copy-to-ebx  Stream/imm32
     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
     #
-    b8/copy-to-eax  6/imm32/close
-    cd/syscall  0x80/imm8
+    e8/call  syscall_close/disp32
 
-    # syscall(unlink, filename)
+    # unlink(filename)
     bb/copy-to-ebx  Filename/imm32
-    b8/copy-to-eax  0xa/imm32/unlink
-    cd/syscall  0x80/imm8
+    e8/call  syscall_unlink/disp32
 
-    # syscall(exit, b)
+    # exit(b)
     # . load b
     bb/copy-to-ebx  B/imm32
     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
     #
-    b8/copy-to-eax  1/imm32/exit
-    cd/syscall  0x80/imm8
+    e8/call  syscall_exit/disp32
 
-== data 0x0a000000
+== data
 
 Stream:
     0/imm32
diff --git a/examples/ex8 b/examples/ex8
index 5be0e1e6..78f1773d 100755
--- a/examples/ex8
+++ b/examples/ex8
Binary files differdiff --git a/examples/ex8.subx b/examples/ex8.subx
index 56dc1556..25191d85 100644
--- a/examples/ex8.subx
+++ b/examples/ex8.subx
@@ -14,7 +14,7 @@
 #   ...
 # Locals start from esp-4 downwards.
 
-== code 0x09000000
+== code
 #   instruction                     effective address                                                   register    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
@@ -32,8 +32,7 @@ Entry:
 
     # exit(eax)
     89/copy                         3/mod/direct    3/rm32/ebx    .           .             .           0/r32/eax   .               .                 # copy eax to ebx
-    b8/copy-to-eax  1/imm32/exit
-    cd/syscall  0x80/imm8
+    e8/call  syscall_exit/disp32
 
 ascii-length:  # s : (address array byte) -> n/eax
     # edx = s
@@ -56,6 +55,6 @@ $ascii-length:end:
     # return eax
     c3/return
 
-== data 0x0a000000
+== data
 
 # . . vim:nowrap:textwidth=0
diff --git a/examples/ex9 b/examples/ex9
index fce7629c..5140cf68 100755
--- a/examples/ex9
+++ b/examples/ex9
Binary files differdiff --git a/examples/ex9.subx b/examples/ex9.subx
index 8793e941..9a6105de 100644
--- a/examples/ex9.subx
+++ b/examples/ex9.subx
@@ -17,7 +17,7 @@
 #   ...
 # Locals start from esp-4 downwards.
 
-== code 0x09000000
+== code
 #   instruction                     effective address                                                   register    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
@@ -34,10 +34,9 @@ Entry:
     e8/call  ascii-difference/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-    # syscall(exit, eax)
+    # exit(eax)
     89/copy                         3/mod/direct    3/rm32/ebx    .           .             .           0/r32/eax   .               .                 # copy eax to ebx
-    b8/copy-to-eax  1/imm32/exit
-    cd/syscall  0x80/imm8
+    e8/call  syscall_exit/disp32
 
 ascii-difference:  # (s1, s2) : null-terminated ascii strings
     # a = first letter of s1 (ecx)
@@ -50,6 +49,4 @@ ascii-difference:  # (s1, s2) : null-terminated ascii strings
     29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # subtract ecx from eax
     c3/return
 
-== data 0x0a000000
-
 # . . vim:nowrap:textwidth=0