diff options
Diffstat (limited to 'html/mu_instructions.html')
-rw-r--r-- | html/mu_instructions.html | 156 |
1 files changed, 76 insertions, 80 deletions
diff --git a/html/mu_instructions.html b/html/mu_instructions.html index 6d91ec55..a6b0f37c 100644 --- a/html/mu_instructions.html +++ b/html/mu_instructions.html @@ -14,8 +14,8 @@ pre { font-family: monospace; color: #000000; background-color: #c6c6c6; } body { font-family: monospace; color: #000000; background-color: #c6c6c6; } * { font-size: 1em; } .Comment { color: #005faf; } +.SpecialChar { color: #d70000; } .Constant { color: #008787; } -.Special { color: #d70000; } .PreProc { color: #c000c0; } .SalientComment { color: #0000af; } --> @@ -28,7 +28,7 @@ body { font-family: monospace; color: #000000; background-color: #c6c6c6; } See <a href="http://akkartik.name/akkartik-convivial-20200315.pdf">http://akkartik.name/akkartik-convivial-20200315.pdf</a> for the complete story. In brief: Mu is a statement-oriented language. Blocks consist of flat lists of instructions. Instructions can have inputs after the operation, and -outputs to the left of a '<span class="Special"><-</span>'. Inputs and outputs must be variables. They can't +outputs to the left of a '<span class="SpecialChar"><-</span>'. Inputs and outputs must be variables. They can't include nested expressions. Variables can be literals ('n'), or live in a register ('var/reg') or in memory ('var') at some 'stack-offset' from the 'ebp' register. Outputs must be registers. To modify a variable in memory, pass it in @@ -38,92 +38,92 @@ Conversely, registers that are just read from must not be passed as inputs. The following chart shows all the instruction forms supported by Mu, along with the SubX instruction they're translated to. -var/<span class="Constant">eax</span> <span class="Special"><-</span> increment => <span class="Constant">"40/increment-eax"</span> -var/<span class="Constant">ecx</span> <span class="Special"><-</span> increment => <span class="Constant">"41/increment-ecx"</span> -var/<span class="Constant">edx</span> <span class="Special"><-</span> increment => <span class="Constant">"42/increment-edx"</span> -var/<span class="Constant">ebx</span> <span class="Special"><-</span> increment => <span class="Constant">"43/increment-ebx"</span> -var/<span class="Constant">esi</span> <span class="Special"><-</span> increment => <span class="Constant">"46/increment-esi"</span> -var/<span class="Constant">edi</span> <span class="Special"><-</span> increment => <span class="Constant">"47/increment-edi"</span> +var/<span class="Constant">eax</span> <span class="SpecialChar"><-</span> increment => <span class="Constant">"40/increment-eax"</span> +var/<span class="Constant">ecx</span> <span class="SpecialChar"><-</span> increment => <span class="Constant">"41/increment-ecx"</span> +var/<span class="Constant">edx</span> <span class="SpecialChar"><-</span> increment => <span class="Constant">"42/increment-edx"</span> +var/<span class="Constant">ebx</span> <span class="SpecialChar"><-</span> increment => <span class="Constant">"43/increment-ebx"</span> +var/<span class="Constant">esi</span> <span class="SpecialChar"><-</span> increment => <span class="Constant">"46/increment-esi"</span> +var/<span class="Constant">edi</span> <span class="SpecialChar"><-</span> increment => <span class="Constant">"47/increment-edi"</span> increment var => <span class="Constant">"ff 0/subop/increment *(ebp+"</span> var.stack-offset <span class="Constant">")"</span> increment *var/reg => <span class="Constant">"ff 0/subop/increment *"</span> reg -var/<span class="Constant">eax</span> <span class="Special"><-</span> decrement => <span class="Constant">"48/decrement-eax"</span> -var/<span class="Constant">ecx</span> <span class="Special"><-</span> decrement => <span class="Constant">"49/decrement-ecx"</span> -var/<span class="Constant">edx</span> <span class="Special"><-</span> decrement => <span class="Constant">"4a/decrement-edx"</span> -var/<span class="Constant">ebx</span> <span class="Special"><-</span> decrement => <span class="Constant">"4b/decrement-ebx"</span> -var/<span class="Constant">esi</span> <span class="Special"><-</span> decrement => <span class="Constant">"4e/decrement-esi"</span> -var/<span class="Constant">edi</span> <span class="Special"><-</span> decrement => <span class="Constant">"4f/decrement-edi"</span> +var/<span class="Constant">eax</span> <span class="SpecialChar"><-</span> decrement => <span class="Constant">"48/decrement-eax"</span> +var/<span class="Constant">ecx</span> <span class="SpecialChar"><-</span> decrement => <span class="Constant">"49/decrement-ecx"</span> +var/<span class="Constant">edx</span> <span class="SpecialChar"><-</span> decrement => <span class="Constant">"4a/decrement-edx"</span> +var/<span class="Constant">ebx</span> <span class="SpecialChar"><-</span> decrement => <span class="Constant">"4b/decrement-ebx"</span> +var/<span class="Constant">esi</span> <span class="SpecialChar"><-</span> decrement => <span class="Constant">"4e/decrement-esi"</span> +var/<span class="Constant">edi</span> <span class="SpecialChar"><-</span> decrement => <span class="Constant">"4f/decrement-edi"</span> decrement var => <span class="Constant">"ff 1/subop/decrement *(ebp+"</span> var.stack-offset <span class="Constant">")"</span> decrement *var/reg => <span class="Constant">"ff 1/subop/decrement *"</span> reg -var/reg <span class="Special"><-</span> add var2/reg2 => <span class="Constant">"01/add-to %"</span> reg <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> add var2 => <span class="Constant">"03/add *(ebp+"</span> var2.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> add *var2/reg2 => <span class="Constant">"03/add *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> add var2/reg2 => <span class="Constant">"01/add-to %"</span> reg <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> add var2 => <span class="Constant">"03/add *(ebp+"</span> var2.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> add *var2/reg2 => <span class="Constant">"03/add *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> add-to var1, var2/reg => <span class="Constant">"01/add-to *(ebp+"</span> var1.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/<span class="Constant">eax</span> <span class="Special"><-</span> add n => <span class="Constant">"05/add-to-eax "</span> n <span class="Constant">"/imm32"</span> -var/reg <span class="Special"><-</span> add n => <span class="Constant">"81 0/subop/add %"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> +var/<span class="Constant">eax</span> <span class="SpecialChar"><-</span> add n => <span class="Constant">"05/add-to-eax "</span> n <span class="Constant">"/imm32"</span> +var/reg <span class="SpecialChar"><-</span> add n => <span class="Constant">"81 0/subop/add %"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> add-to var, n => <span class="Constant">"81 0/subop/add *(ebp+"</span> var.stack-offset <span class="Constant">") "</span> n <span class="Constant">"/imm32"</span> add-to *var/reg, n => <span class="Constant">"81 0/subop/add *"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> -var/reg <span class="Special"><-</span> subtract var2/reg2 => <span class="Constant">"29/subtract-from %"</span> reg <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> subtract var2 => <span class="Constant">"2b/subtract *(ebp+"</span> var2.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> subtract *var2/reg2 => <span class="Constant">"2b/subtract *"</span> reg2 <span class="Constant">" "</span> reg1 <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> subtract var2/reg2 => <span class="Constant">"29/subtract-from %"</span> reg <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> subtract var2 => <span class="Constant">"2b/subtract *(ebp+"</span> var2.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> subtract *var2/reg2 => <span class="Constant">"2b/subtract *"</span> reg2 <span class="Constant">" "</span> reg1 <span class="Constant">"/r32"</span> subtract-from var1, var2/reg2 => <span class="Constant">"29/subtract-from *(ebp+"</span> var1.stack-offset <span class="Constant">") "</span> reg2 <span class="Constant">"/r32"</span> -var/<span class="Constant">eax</span> <span class="Special"><-</span> subtract n => <span class="Constant">"2d/subtract-from-eax "</span> n <span class="Constant">"/imm32"</span> -var/reg <span class="Special"><-</span> subtract n => <span class="Constant">"81 5/subop/subtract %"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> +var/<span class="Constant">eax</span> <span class="SpecialChar"><-</span> subtract n => <span class="Constant">"2d/subtract-from-eax "</span> n <span class="Constant">"/imm32"</span> +var/reg <span class="SpecialChar"><-</span> subtract n => <span class="Constant">"81 5/subop/subtract %"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> subtract-from var, n => <span class="Constant">"81 5/subop/subtract *(ebp+"</span> var.stack-offset <span class="Constant">") "</span> n <span class="Constant">"/imm32"</span> subtract-from *var/reg, n => <span class="Constant">"81 5/subop/subtract *"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> -var/reg <span class="Special"><-</span> and var2/reg2 => <span class="Constant">"21/and-with %"</span> reg <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> and var2 => <span class="Constant">"23/and *(ebp+"</span> var2.stack-offset <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> and *var2/reg2 => <span class="Constant">"23/and *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> and var2/reg2 => <span class="Constant">"21/and-with %"</span> reg <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> and var2 => <span class="Constant">"23/and *(ebp+"</span> var2.stack-offset <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> and *var2/reg2 => <span class="Constant">"23/and *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> and-with var1, var2/reg => <span class="Constant">"21/and-with *(ebp+"</span> var1.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/<span class="Constant">eax</span> <span class="Special"><-</span> and n => <span class="Constant">"25/and-with-eax "</span> n <span class="Constant">"/imm32"</span> -var/reg <span class="Special"><-</span> and n => <span class="Constant">"81 4/subop/and %"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> +var/<span class="Constant">eax</span> <span class="SpecialChar"><-</span> and n => <span class="Constant">"25/and-with-eax "</span> n <span class="Constant">"/imm32"</span> +var/reg <span class="SpecialChar"><-</span> and n => <span class="Constant">"81 4/subop/and %"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> and-with var, n => <span class="Constant">"81 4/subop/and *(ebp+"</span> var.stack-offset <span class="Constant">") "</span> n <span class="Constant">"/imm32"</span> and-with *var/reg, n => <span class="Constant">"81 4/subop/and *"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> -var/reg <span class="Special"><-</span> or var2/reg2 => <span class="Constant">"09/or-with %"</span> reg <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> or var2 => <span class="Constant">"0b/or *(ebp+"</span> var2.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> or *var2/reg2 => <span class="Constant">"0b/or *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> or var2/reg2 => <span class="Constant">"09/or-with %"</span> reg <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> or var2 => <span class="Constant">"0b/or *(ebp+"</span> var2.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> or *var2/reg2 => <span class="Constant">"0b/or *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> or-with var1, var2/reg2 => <span class="Constant">"09/or-with *(ebp+"</span> var1.stack-offset <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> -var/<span class="Constant">eax</span> <span class="Special"><-</span> or n => <span class="Constant">"0d/or-with-eax "</span> n <span class="Constant">"/imm32"</span> -var/reg <span class="Special"><-</span> or n => <span class="Constant">"81 1/subop/or %"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> +var/<span class="Constant">eax</span> <span class="SpecialChar"><-</span> or n => <span class="Constant">"0d/or-with-eax "</span> n <span class="Constant">"/imm32"</span> +var/reg <span class="SpecialChar"><-</span> or n => <span class="Constant">"81 1/subop/or %"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> or-with var, n => <span class="Constant">"81 1/subop/or *(ebp+"</span> var.stack-offset <span class="Constant">") "</span> n <span class="Constant">"/imm32"</span> or-with *var/reg, n => <span class="Constant">"81 1/subop/or *"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> -var/reg <span class="Special"><-</span> xor var2/reg2 => <span class="Constant">"31/xor-with %"</span> reg <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> xor var2 => <span class="Constant">"33/xor *(ebp+"</span> var2.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> xor *var2/reg2 => <span class="Constant">"33/xor *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> xor var2/reg2 => <span class="Constant">"31/xor-with %"</span> reg <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> xor var2 => <span class="Constant">"33/xor *(ebp+"</span> var2.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> xor *var2/reg2 => <span class="Constant">"33/xor *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> xor-with var1, var2/reg => <span class="Constant">"31/xor-with *(ebp+"</span> var1.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/<span class="Constant">eax</span> <span class="Special"><-</span> xor n => <span class="Constant">"35/xor-with-eax "</span> n <span class="Constant">"/imm32"</span> -var/reg <span class="Special"><-</span> xor n => <span class="Constant">"81 6/subop/xor %"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> +var/<span class="Constant">eax</span> <span class="SpecialChar"><-</span> xor n => <span class="Constant">"35/xor-with-eax "</span> n <span class="Constant">"/imm32"</span> +var/reg <span class="SpecialChar"><-</span> xor n => <span class="Constant">"81 6/subop/xor %"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> xor-with var, n => <span class="Constant">"81 6/subop/xor *(ebp+"</span> var.stack-offset <span class="Constant">") "</span> n <span class="Constant">"/imm32"</span> xor-with *var/reg, n => <span class="Constant">"81 6/subop/xor *"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> -var/reg <span class="Special"><-</span> shift-left n -var/reg <span class="Special"><-</span> shift-right n -var/reg <span class="Special"><-</span> shift-right-signed n +var/reg <span class="SpecialChar"><-</span> shift-left n +var/reg <span class="SpecialChar"><-</span> shift-right n +var/reg <span class="SpecialChar"><-</span> shift-right-signed n shift-left var, n shift-right var, n shift-right-signed var, n -var/<span class="Constant">eax</span> <span class="Special"><-</span> copy n => <span class="Constant">"b8/copy-to-eax "</span> n <span class="Constant">"/imm32"</span> -var/<span class="Constant">ecx</span> <span class="Special"><-</span> copy n => <span class="Constant">"b9/copy-to-ecx "</span> n <span class="Constant">"/imm32"</span> -var/<span class="Constant">edx</span> <span class="Special"><-</span> copy n => <span class="Constant">"ba/copy-to-edx "</span> n <span class="Constant">"/imm32"</span> -var/<span class="Constant">ebx</span> <span class="Special"><-</span> copy n => <span class="Constant">"bb/copy-to-ebx "</span> n <span class="Constant">"/imm32"</span> -var/<span class="Constant">esi</span> <span class="Special"><-</span> copy n => <span class="Constant">"be/copy-to-esi "</span> n <span class="Constant">"/imm32"</span> -var/<span class="Constant">edi</span> <span class="Special"><-</span> copy n => <span class="Constant">"bf/copy-to-edi "</span> n <span class="Constant">"/imm32"</span> -var/reg <span class="Special"><-</span> copy var2/reg2 => <span class="Constant">"89/<- %"</span> reg <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> +var/<span class="Constant">eax</span> <span class="SpecialChar"><-</span> copy n => <span class="Constant">"b8/copy-to-eax "</span> n <span class="Constant">"/imm32"</span> +var/<span class="Constant">ecx</span> <span class="SpecialChar"><-</span> copy n => <span class="Constant">"b9/copy-to-ecx "</span> n <span class="Constant">"/imm32"</span> +var/<span class="Constant">edx</span> <span class="SpecialChar"><-</span> copy n => <span class="Constant">"ba/copy-to-edx "</span> n <span class="Constant">"/imm32"</span> +var/<span class="Constant">ebx</span> <span class="SpecialChar"><-</span> copy n => <span class="Constant">"bb/copy-to-ebx "</span> n <span class="Constant">"/imm32"</span> +var/<span class="Constant">esi</span> <span class="SpecialChar"><-</span> copy n => <span class="Constant">"be/copy-to-esi "</span> n <span class="Constant">"/imm32"</span> +var/<span class="Constant">edi</span> <span class="SpecialChar"><-</span> copy n => <span class="Constant">"bf/copy-to-edi "</span> n <span class="Constant">"/imm32"</span> +var/reg <span class="SpecialChar"><-</span> copy var2/reg2 => <span class="Constant">"89/<- %"</span> reg <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> copy-to var1, var2/reg => <span class="Constant">"89/<- *(ebp+"</span> var1.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> copy var2 => <span class="Constant">"8b/-> *(ebp+"</span> var2.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> copy *var2/reg2 => <span class="Constant">"8b/-> *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> copy n => <span class="Constant">"c7 0/subop/copy %"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> +var/reg <span class="SpecialChar"><-</span> copy var2 => <span class="Constant">"8b/-> *(ebp+"</span> var2.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> copy *var2/reg2 => <span class="Constant">"8b/-> *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> copy n => <span class="Constant">"c7 0/subop/copy %"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> copy-to var, n => <span class="Constant">"c7 0/subop/copy *(ebp+"</span> var.stack-offset <span class="Constant">") "</span> n <span class="Constant">"/imm32"</span> copy-to *var/reg, n => <span class="Constant">"c7 0/subop/copy *"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> -var/reg <span class="Special"><-</span> copy-byte var2/reg2 => <span class="Constant">"8a/byte-> %"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> copy-byte *var2/reg2 => <span class="Constant">"8a/byte-> *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> copy-byte var2/reg2 => <span class="Constant">"8a/byte-> %"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> copy-byte *var2/reg2 => <span class="Constant">"8a/byte-> *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> copy-byte-to *var1/reg1, var2/reg2 => <span class="Constant">"88/byte<- *"</span> reg1 <span class="Constant">" "</span> reg2 <span class="Constant">"/r32"</span> compare var1, var2/reg2 => <span class="Constant">"39/compare *(ebp+"</span> var1.stack-offset <span class="Constant">") "</span> reg2 <span class="Constant">"/r32"</span> @@ -135,8 +135,8 @@ compare var/reg, n => <span class="Constant">"81 7/subop/ compare var, n => <span class="Constant">"81 7/subop/compare *(ebp+"</span> var.stack-offset <span class="Constant">") "</span> n <span class="Constant">"/imm32"</span> compare *var/reg, n => <span class="Constant">"81 7/subop/compare *"</span> reg <span class="Constant">" "</span> n <span class="Constant">"/imm32"</span> -var/reg <span class="Special"><-</span> multiply var2 => <span class="Constant">"0f af/multiply *(ebp+"</span> var2.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> multiply *var2/reg2 => <span class="Constant">"0f af/multiply *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> multiply var2 => <span class="Constant">"0f af/multiply *(ebp+"</span> var2.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="SpecialChar"><-</span> multiply *var2/reg2 => <span class="Constant">"0f af/multiply *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> <span class="PreProc">break</span> => <span class="Constant">"e9/jump break/disp32"</span> <span class="PreProc">break</span> label => <span class="Constant">"e9/jump "</span> label <span class="Constant">":break/disp32"</span> @@ -198,32 +198,32 @@ be provided in an earlier 'var' declaration. <span class="Comment"># Address operations</span> -var/reg: (addr T) <span class="Special"><-</span> address var2: T +var/reg: (addr T) <span class="SpecialChar"><-</span> address var2: T => <span class="Constant">"8d/copy-address *(ebp+"</span> var2.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> <span class="Comment"># Array operations</span> (TODO: bounds-checking) -var/reg <span class="Special"><-</span> index arr/rega: (addr array T), idx/regi: int +var/reg <span class="SpecialChar"><-</span> index arr/rega: (addr array T), idx/regi: int | if size-of(T) is <span class="Constant">4</span> or <span class="Constant">8</span> => <span class="Constant">"8d/copy-address *("</span> rega <span class="Constant">"+"</span> regi <span class="Constant">"<<"</span> log2(size-of(T)) <span class="Constant">"+4) "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> index arr: (array T sz), idx/regi: int +var/reg <span class="SpecialChar"><-</span> index arr: (array T sz), idx/regi: int => <span class="Constant">"8d/copy-address *(ebp+"</span> regi <span class="Constant">"<<"</span> log2(size-of(T)) <span class="Constant">"+"</span> (arr.stack-offset + <span class="Constant">4</span>) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> index arr/rega: (addr array T), n +var/reg <span class="SpecialChar"><-</span> index arr/rega: (addr array T), n => <span class="Constant">"8d/copy-address *("</span> rega <span class="Constant">"+"</span> (n*size-of(T)+<span class="Constant">4</span>) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> index arr: (array T sz), n +var/reg <span class="SpecialChar"><-</span> index arr: (array T sz), n => <span class="Constant">"8d/copy-address *(ebp+"</span> (arr.stack-offset+<span class="Constant">4</span>+n*size-of(T)) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/reg: (offset T) <span class="Special"><-</span> compute-offset arr: (addr array T), idx/regi: int <span class="Comment"># arr can be in reg or mem</span> +var/reg: (offset T) <span class="SpecialChar"><-</span> compute-offset arr: (addr array T), idx/regi: int <span class="Comment"># arr can be in reg or mem</span> => <span class="Constant">"69/multiply %"</span> regi <span class="Constant">" "</span> size-of(T) <span class="Constant">"/imm32 "</span> reg <span class="Constant">"/r32"</span> -var/reg: (offset T) <span class="Special"><-</span> compute-offset arr: (addr array T), idx: int <span class="Comment"># arr can be in reg or mem</span> +var/reg: (offset T) <span class="SpecialChar"><-</span> compute-offset arr: (addr array T), idx: int <span class="Comment"># arr can be in reg or mem</span> => <span class="Constant">"69/multiply *(ebp+"</span> idx.stack-offset <span class="Constant">") "</span> size-of(T) <span class="Constant">"/imm32 "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> index arr/rega: (addr array T), o/rego: offset +var/reg <span class="SpecialChar"><-</span> index arr/rega: (addr array T), o/rego: offset => <span class="Constant">"8d/copy-address *("</span> rega <span class="Constant">"+"</span> rego <span class="Constant">"+4) "</span> reg <span class="Constant">"/r32"</span> Computing the length of an array is complex. -var/reg <span class="Special"><-</span> length arr/reg2: (addr array T) +var/reg <span class="SpecialChar"><-</span> length arr/reg2: (addr array T) | if T is byte (TODO) => <span class="Constant">"8b/-> *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> | if size-of(T) is <span class="Constant">4</span> or <span class="Constant">8</span> or <span class="Constant">16</span> or <span class="Constant">32</span> or <span class="Constant">64</span> or <span class="Constant">128</span> @@ -256,24 +256,11 @@ var/reg <span class="Special"><-</span> length arr/reg2: (addr array T) If a record (product) type T was defined to have elements a, b, c, ... of types T_a, T_b, T_c, ..., then accessing one of those elements f of type T_f: -var/reg: (addr T_f) <span class="Special"><-</span> get var2/reg2: (addr T), f +var/reg: (addr T_f) <span class="SpecialChar"><-</span> get var2/reg2: (addr T), f => <span class="Constant">"8d/copy-address *("</span> reg2 <span class="Constant">"+"</span> offset(f) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -var/reg: (addr T_f) <span class="Special"><-</span> get var2: T, f +var/reg: (addr T_f) <span class="SpecialChar"><-</span> get var2: T, f => <span class="Constant">"8d/copy-address *(ebp+"</span> var2.stack-offset <span class="Constant">"+"</span> offset(f) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> -<span class="Comment"># Handles for safe access to the heap</span> - -out/reg: (addr T) <span class="Special"><-</span> lookup in: (handle T) - => <span class="Comment"># payload_allocid = in->address->allocid</span> - <span class="Constant">"8b/-> *(epb+"</span> (in.stack-offset+<span class="Constant">4</span>) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> - <span class="Constant">"8b/-> *"</span> reg <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> - <span class="Comment"># if (payload_allocid != handle->allocid) abort</span> - <span class="Constant">"39/compare *(ebp+"</span> in.stack-offset <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> - <span class="Constant">"0f 85/jump-if-!= $lookup:abort/disp32"</span> - <span class="Comment"># return payload</span> - <span class="Constant">"8b/-> *(epb+"</span> (in.stack-offset+<span class="Constant">4</span>) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> - <span class="Constant">"81 0/subop/add %"</span> reg <span class="Constant">" 4/imm32"</span> <span class="Comment"># skip payload->allocid</span> - <span class="Comment"># Allocating memory</span> allocate in: (addr handle T) @@ -282,6 +269,15 @@ allocate in: (addr handle T) populate in: (addr handle array T), num <span class="Comment"># can be literal or variable on stack or register</span> => <span class="Constant">"(allocate-array2 Heap "</span> size-of(T) <span class="Constant">" "</span> num <span class="Constant">" "</span> in <span class="Constant">")"</span> +populate-stream in: (addr handle stream T), num <span class="Comment"># can be literal or variable on stack or register</span> + => <span class="Constant">"(new-stream Heap "</span> size-of(T) <span class="Constant">" "</span> num <span class="Constant">" "</span> in <span class="Constant">")"</span> + +read-from-stream s: (addr stream T), out: (addr T) + => <span class="Constant">"(read-from-stream "</span> s <span class="Constant">" "</span> out <span class="Constant">" "</span> size-of(T) <span class="Constant">")"</span> + +write-to-stream s: (addr stream T), in: (addr T) + => <span class="Constant">"(write-to-stream "</span> s <span class="Constant">" "</span> in <span class="Constant">" "</span> size-of(T) <span class="Constant">")"</span> + vim:ft=mu:nowrap:textwidth=<span class="Constant">0</span> </pre> </body> |