Sample Solutions For KySMet Encoding And Assembler
There are actually three different sample solutions here.
There is also an Implementor's Notes document to go with
either the first or third version:
Latex source and
PDF .
The First Version
An Alternative...
Here's another way to do this... but avoiding having the second
word missing an opcode field. The trick is that an opcode (15)
is reserved to mean "continuation of address in previous call,
jump, or jumpf." This is not hard to implement because the
continuation actually works a lot like lu8 . Is it
better than the first encoding? It depends on how you implement
things... probably not.
The following is the AIK
code for the sample solution.
Sample Solution For KySMet Encoding And Assembler
trap := 0:4 0:12
ret := 0:4 1:12
pushen := 0:4 2:12
popen := 0:4 4:12
allen := 0:4 8:12
call .addr := { 1:4 0:4 .addr:16
15:4 15:4 (.addr>>8):16 }
jump .addr := { 1:4 1:4 .addr:16
15:4 15:4 (.addr>>8):16 }
jumpf $.d,.addr := { 14:4 .d:4 .addr:16
15:4 15:4 (.addr>>8):16 }
lnot $.d,$.s := 2:4 .d:4 .s:4 0:4
neg $.d,$.s := 2:4 .d:4 .s:4 1:4
left $.d,$.s := 2:4 .d:4 .s:4 2:4
right $.d,$.s := 2:4 .d:4 .s:4 3:4
gor $.d,$.s := 2:4 .d:4 .s:4 4:4
load $.d,$.s := 2:4 .d:4 .s:4 8:4
store $.d,$.s := 2:4 .d:4 .s:4 9:4
add $.d,$.s,$.t := 4:4 .d:4 .s:4 .t:4
slt $.d,$.s,$.t := 5:4 .d:4 .s:4 .t:4
sra $.d,$.s,$.t := 6:4 .d:4 .s:4 .t:4
mul $.d,$.s,$.t := 7:4 .d:4 .s:4 .t:4
and $.d,$.s,$.t := 8:4 .d:4 .s:4 .t:4
or $.d,$.s,$.t := 9:4 .d:4 .s:4 .t:4
xor $.d,$.s,$.t := 10:4 .d:4 .s:4 .t:4
sll $.d,$.s,$.t := 11:4 .d:4 .s:4 .t:4
li8 $.d,.i8 := 12:4 .d:4 .i8:8
lu8 $.d,.i8 := 13:4 .d:4 .i8:8
li $.d,.i16 ?((.i16>-129)&&(.i16<128)) := {
12:4 .d:4 .i16:8 }
li $.d,.i16 := { 12:4 .d:4 .i16:8
13:4 .d:4 (.i16>>8):8 }
.const {zero IPROC NPROC sp fp rv u0 u1
u2 u3 u4 u5 u6 u7 u8 u9 }
.segment .text 16 0x10000 0 .VMEM
.segment .data 16 0x10000 0 .VMEM
.const 0 .lowfirst ; defaults to wrong endian
Sample Assembly Language Input
.text
.origin 0x0000
start: add $u0,$zero,$IPROC
allen
and $u1,$NPROC,$sp
call place
gor $u2,$fp
jump place
jumpf $rv,place
left $u3,$u0
li8 $u4,42
lnot $u5,$u1
load $u6,$u2
lu8 $u7,42
mul $u8,$u3,$u4
neg $u9,$u5
or $u0,$u6,$u7
popen
.data
fluff: .word 42
.text ; continue where we left off
pushen
ret
right $u1,$u8
sll $u2,$u9,$zero
slt $u3,$IPROC,$NPROC
sra $u4,$sp,$fp
store $rv,$u0
trap
xor $u5,$u1,$u2
place:
li $u6,-129 ; li8 lu8
li $u7,-128 ; li8
.data
fluffy: .word place2
.text ; continue where we left off
li $u8,127 ; li8
li $u9,128 ; li8 lu8
place2:
Another Alternative
Finally, let's go back to my first encoding, but
use .alias to show groupings.
The following is the AIK
code for the sample solution.
Sample Solution For KySMet Encoding And Assembler
.noarg := 0:4 .this:12
.alias .noarg trap ret pushen 4 popen 8 allen
call .addr := 1:4 0:4 0:4 0:4 .addr:16
jump .addr := 1:4 0:4 0:4 1:4 .addr:16
jumpf $.d,.addr := 1:4 .d:4 0:4 3:4 .addr:16
.twoarg $.d,$.s := 2:4 .d:4 .s:4 .this:4
.alias .twoarg lnot neg left right gor 8 load store
.twearg $.d,$.s,$.t := .this:4 .d:4 .s:4 .t:4
.alias .twearg 4 add slt sra mul and or xor sll
li8 $.d,.i8 := 12:4 .d:4 .i8:8
lu8 $.d,.i8 := 13:4 .d:4 .i8:8
li $.d,.i16 ?((.i16>-129)&&(.i16<128)) := {
12:4 .d:4 .i16:8 }
li $.d,.i16 := { 12:4 .d:4 .i16:8
13:4 .d:4 (.i16>>8):8 }
.const {zero IPROC NPROC sp fp rv u0 u1
u2 u3 u4 u5 u6 u7 u8 u9 }
.segment .text 16 0x10000 0 .VMEM
.segment .data 16 0x10000 0 .VMEM
.const 0 .lowfirst ; defaults to wrong endian
Sample Assembly Language Input
.text
.origin 0x0000
start: add $u0,$zero,$IPROC
allen
and $u1,$NPROC,$sp
call place
gor $u2,$fp
jump place
jumpf $rv,place
left $u3,$u0
li8 $u4,42
lnot $u5,$u1
load $u6,$u2
lu8 $u7,42
mul $u8,$u3,$u4
neg $u9,$u5
or $u0,$u6,$u7
popen
.data
fluff: .word 42
.text ; continue where we left off
pushen
ret
right $u1,$u8
sll $u2,$u9,$zero
slt $u3,$IPROC,$NPROC
sra $u4,$sp,$fp
store $rv,$u0
trap
xor $u5,$u1,$u2
place:
li $u6,-129 ; li8 lu8
li $u7,-128 ; li8
.data
fluffy: .word place2
.text ; continue where we left off
li $u8,127 ; li8
li $u9,128 ; li8 lu8
place2:
Advanced Computer Architecture.