From a0d3cac4e69101669681a4d8af6dc3e8bd2c9a6a Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 15 Sep 2019 00:01:26 -0700 Subject: 5659 --- html/examples/ex7.subx.html | 205 +++++++++++++++++++++----------------------- 1 file changed, 98 insertions(+), 107 deletions(-) (limited to 'html/examples/ex7.subx.html') diff --git a/html/examples/ex7.subx.html b/html/examples/ex7.subx.html index 01a85887..762bf7ec 100644 --- a/html/examples/ex7.subx.html +++ b/html/examples/ex7.subx.html @@ -55,113 +55,104 @@ if ('onhashchange' in window) { https://github.com/akkartik/mu/blob/master/examples/ex7.subx
-  1 # Example showing file syscalls.
-  2 #
-  3 # Create a file, open it for writing, write a character to it, close it, open
-  4 # it for reading, read a character from it, close it, delete it, and return
-  5 # the character read.
-  6 #
-  7 # To run:
-  8 #   $ ./subx translate examples/ex7.subx -o examples/ex7
-  9 #   $ ./subx run examples/ex7
- 10 # Expected result:
- 11 #   $ echo $?
- 12 #   97
- 13 
- 14 == code 0x09000000
- 15 #   instruction                     effective address                                                   register    displacement    immediate
- 16 # . op          subop               mod             rm32          base        index         scale       r32
- 17 # . 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
- 18 
- 19 Entry:
- 20     # syscall(creat, Filename)
- 21     bb/copy-to-ebx  Filename/imm32
- 22     b9/copy-to-ecx  0x180/imm32/fixed-perms
- 23     b8/copy-to-eax  8/imm32/creat
- 24     cd/syscall  0x80/imm8
- 25 
- 26     # stream = syscall(open, Filename, O_WRONLY, 0)  # we can't use 'fd' because it looks like a hex byte
- 27     bb/copy-to-ebx  Filename/imm32
- 28     b9/copy-to-ecx  1/imm32/wronly
- 29     ba/copy-to-edx  0x180/imm32/fixed-perms
- 30     b8/copy-to-eax  5/imm32/open
- 31     cd/syscall  0x80/imm8
- 32     # save stream
- 33     bb/copy-to-ebx  Stream/imm32
- 34     89/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           0/r32/eax   .               .                 # copy eax to *ebx
- 35 
- 36     # syscall(write, Stream, "a", 1)
- 37     # . load stream
- 38     bb/copy-to-ebx  Stream/imm32
- 39     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
- 40     # .
- 41     b9/copy-to-ecx  A/imm32
- 42     ba/copy-to-edx  1/imm32/size
- 43     b8/copy-to-eax  4/imm32/write
- 44     cd/syscall  0x80/imm8
- 45 
- 46     # syscall(close, Stream)
- 47     # . load stream
- 48     bb/copy-to-ebx  Stream/imm32
- 49     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
- 50     # .
- 51     b8/copy-to-eax  6/imm32/close
- 52     cd/syscall  0x80/imm8
- 53 
- 54     # stream = syscall(open, Filename, O_RDONLY, 0)
- 55     bb/copy-to-ebx  Filename/imm32
- 56     b9/copy-to-ecx  0/imm32/rdonly
- 57     ba/copy-to-edx  0x180/imm32/fixed-perms
- 58     b8/copy-to-eax  5/imm32/open
- 59     cd/syscall  0x80/imm8
- 60     # . save Stream
- 61     bb/copy-to-ebx  Stream/imm32
- 62     89/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           0/r32/eax   .               .                 # copy eax to *ebx
- 63 
- 64     # syscall(read, Stream, B, 1)
- 65     # . load stream
- 66     bb/copy-to-ebx  Stream/imm32
- 67     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
- 68     # .
- 69     b9/copy-to-ecx  B/imm32
- 70     ba/copy-to-edx  1/imm32/size
- 71     b8/copy-to-eax  3/imm32/read
- 72     cd/syscall  0x80/imm8
- 73 
- 74     # syscall(close, Stream)
- 75     # . load stream
- 76     bb/copy-to-ebx  Stream/imm32
- 77     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
- 78     #
- 79     b8/copy-to-eax  6/imm32/close
- 80     cd/syscall  0x80/imm8
- 81 
- 82     # syscall(unlink, filename)
- 83     bb/copy-to-ebx  Filename/imm32
- 84     b8/copy-to-eax  0xa/imm32/unlink
- 85     cd/syscall  0x80/imm8
- 86 
- 87     # syscall(exit, b)
- 88     # . load b
- 89     bb/copy-to-ebx  B/imm32
- 90     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
- 91     #
- 92     b8/copy-to-eax  1/imm32/exit
- 93     cd/syscall  0x80/imm8
- 94 
- 95 == data 0x0a000000
- 96 
- 97 Stream:
- 98     0/imm32
- 99 A:
-100     61/imm32/A
-101 B:
-102     0/imm32
-103 Filename:
-104     2e 66 6f 6f 00 00 00 00
-105 #   .  f  o  o  null
-106 
-107 # . . vim:nowrap:textwidth=0
+ 1 # Example showing file syscalls.
+ 2 #
+ 3 # Create a file, open it for writing, write a character to it, close it, open
+ 4 # it for reading, read a character from it, close it, delete it, and return
+ 5 # the character read.
+ 6 #
+ 7 # To run:
+ 8 #   $ ./subx translate init.linux examples/ex7.subx -o examples/ex7
+ 9 #   $ ./subx run examples/ex7
+10 # Expected result:
+11 #   $ echo $?
+12 #   97
+13 
+14 == code
+15 #   instruction                     effective address                                                   register    displacement    immediate
+16 # . op          subop               mod             rm32          base        index         scale       r32
+17 # . 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
+18 
+19 Entry:
+20     # creat(Filename)
+21     bb/copy-to-ebx  Filename/imm32
+22     b9/copy-to-ecx  0x180/imm32/fixed-perms
+23     e8/call  syscall_creat/disp32
+24 
+25     # stream = open(Filename, O_WRONLY, 0)  # we can't use 'fd' because it looks like a hex byte
+26     bb/copy-to-ebx  Filename/imm32
+27     b9/copy-to-ecx  1/imm32/wronly
+28     ba/copy-to-edx  0x180/imm32/fixed-perms
+29     e8/call  syscall_open/disp32
+30     # save stream
+31     bb/copy-to-ebx  Stream/imm32
+32     89/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           0/r32/eax   .               .                 # copy eax to *ebx
+33 
+34     # write(Stream, "a", 1)
+35     # . load stream
+36     bb/copy-to-ebx  Stream/imm32
+37     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
+38     # .
+39     b9/copy-to-ecx  A/imm32
+40     ba/copy-to-edx  1/imm32/size
+41     e8/call  syscall_write/disp32
+42 
+43     # close(Stream)
+44     # . load stream
+45     bb/copy-to-ebx  Stream/imm32
+46     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
+47     # .
+48     e8/call  syscall_close/disp32
+49 
+50     # stream = open(Filename, O_RDONLY, 0)
+51     bb/copy-to-ebx  Filename/imm32
+52     b9/copy-to-ecx  0/imm32/rdonly
+53     ba/copy-to-edx  0x180/imm32/fixed-perms
+54     e8/call  syscall_open/disp32
+55     # . save Stream
+56     bb/copy-to-ebx  Stream/imm32
+57     89/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           0/r32/eax   .               .                 # copy eax to *ebx
+58 
+59     # read(Stream, B, 1)
+60     # . load stream
+61     bb/copy-to-ebx  Stream/imm32
+62     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
+63     # .
+64     b9/copy-to-ecx  B/imm32
+65     ba/copy-to-edx  1/imm32/size
+66     e8/call  syscall_read/disp32
+67 
+68     # close(Stream)
+69     # . load stream
+70     bb/copy-to-ebx  Stream/imm32
+71     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
+72     #
+73     e8/call  syscall_close/disp32
+74 
+75     # unlink(filename)
+76     bb/copy-to-ebx  Filename/imm32
+77     e8/call  syscall_unlink/disp32
+78 
+79     # exit(b)
+80     # . load b
+81     bb/copy-to-ebx  B/imm32
+82     8b/copy                         0/mod/indirect  3/rm32/ebx    .           .             .           3/r32/ebx   .               .                 # copy *ebx to ebx
+83     #
+84     e8/call  syscall_exit/disp32
+85 
+86 == data
+87 
+88 Stream:
+89     0/imm32
+90 A:
+91     61/imm32/A
+92 B:
+93     0/imm32
+94 Filename:
+95     2e 66 6f 6f 00 00 00 00
+96 #   .  f  o  o  null
+97 
+98 # . . vim:nowrap:textwidth=0
 
-- cgit 1.4.1-2-gfad0