.fill 42, 0
prog_eof:
-.fill 1, 0xE701FFFC;ldw r0, 0-4(r3)
-.fill 1, 0xEB00000A;ret+
+.ifill pop r0
+.ifill ret+
prog_mul:
-.fill 1, 0xE1998020;subi r3, r3, 4
-.fill 1, 0xe7318000;ldw r6, 0(r3)
-.fill 1, 0xe739fffc;ldw r7, 0-4(r3)
-.fill 1, 0xed400004;ldis r8, 0
-.fill 1, 0xe1038000;mov r0, r7
-.fill 1, 0xe2800008;andx r0, 1
-.fill 1, 0x00443001;adddnz r8, r8, r6
-.fill 1, 0x01bb8008;subinz r7, r7, 1
-.fill 1, 0x113b8000;addizs r7, r7, 0
+.ifill pop r6
+.ifill pop r7
+.ifill ldis r8, 0;0xed400004
+.ifill mov r0, r7;0xe1038000
+.ifill andx r0, 1;0xe2800008
+.ifill adddnz r8, r8, r6;0x00443001
+.ifill subinz r7, r7, 1;0x01bb8008
+.ifill addizs r7, r7, 0;0x113b8000
;loop:
-.fill 1, 0x00443001;adddnz r8, r8, r6
-.fill 1, 0x00443001;adddnz r8, r8, r6
-.fill 1, 0xe1bb8010;subi r7, r7, 2
-.fill 1, 0x0b7ffe83;brnz+ loop
-.fill 1, 0xe7c1fffc;stw r8, 0-4(r3)
+.ifill adddnz r8, r8, r6;0x00443001
+.ifill adddnz r8, r8, r6;0x00443001
+.ifill subi r7, r7, 2;0xe1bb8010
+.fill 0x0b7ffe83;brnz+ loop
+.ifill push r8
prog_consts:
-.fill 1, 0xed300004;ldis r6, CONST
-.fill 1, 0xe7b18000;stw r6, 0(r3)
-.fill 1, 0xe1198020;addi r3, r3, 4
+.fill 0xed300004;ldis r6, CONST
+.ifill push r6
prog_add:
-.fill 1, 0xe1998020;subi r3, r3, 4
-.fill 1, 0xe7318000;ldw r6, 0(r3)
-.fill 1, 0xe739fffc;ldw r7, 0-4(r3)
-.fill 1, 0xe03bb000;add r7, r7, r6
-.fill 1, 0xe7b9fffc;stw r7, 0-4(r3)
+.ifill pop r6
+.ifill pop r7
+.ifill add r7, r7, r6;0xe03bb000
+.ifill push r7
prog_sub:
-.fill 1, 0xe1998020;subi r3, r3, 4
-.fill 1, 0xe7318000;ldw r6, 0(r3)
-.fill 1, 0xe739fffc;ldw r7, 0-4(r3)
-.fill 1, 0xe0bbb000;sub r7, r7, r6
-.fill 1, 0xe7b9fffc;stw r7, 0-4(r3)
+.ifill pop r6
+.ifill pop r7
+.ifill sub r7, r7, r6;0xe0bbb000
+.ifill push r7
prog_lessthan:
-.fill 1, 0xe1998020;subi r3, r3, 4
-.fill 1, 0xe7318000;ldw r6, 0(r3)
-.fill 1, 0xe739fffc;ldw r7, 0-4(r3)
-.fill 1, 0xed400004;ldis r8, 0
-.fill 1, 0xec3b0000;cmp r7, r6
-.fill 1, 0xbd4007fc;ldislt r8, 0xFF
-.fill 1, 0xe7c1fffc;stw r8, 0-4(r3)
+.ifill pop r6
+.ifill pop r7
+.ifill cmp r7, r6;0xec3b0000
+.ifill pushlt r14
+.ifill pushge r15
prog_dup:
-.fill 1, 0xe731fffc;ldw r6, 0-4(r3)
-.fill 1, 0xe7b18000;stw r6, 0(r3)
-.fill 1, 0xe1198020;addi r3, r3, 4
+.ifill fetch r6
+.ifill push r6
prog_jmp:
-.fill 1, 0xe1998020;subi r3, r3, 4
-.fill 1, 0xe7318000;ldw r6, 0(r3)
-.fill 1, 0xecb00000;cmpi r6,0
+.ifill pop r6
+.ifill cmpi r6,0;0xecb00000
;static calced
-.fill 1, 0xbb000103;breq- vm_next
-.fill 1, 0xeb000003;br+ #CONST
+.fill 1, 0x1b000103;breq- vm_next
+.fill 1, 0xeb000003;br+ CONST
prog_imm:
.fill 1, 0xed400000;ldil r6, CONST
.fill 1, 0xed400002;ldih r6, CONST
-.fill 1, 0xe7b18000;stw r6, 0(r3)
-.fill 1, 0xe1198020;addi r3, r3, 4
+.ifill push r6
prog_pop:
-.fill 1, 0xe1998020;subi r3, r3, 4
+.ifill disc r6
prog_xch:
-.fill 1, 0xe731fffc;ldw r6, 0-4(r3)
-.fill 1, 0xe739fff8;ldw r7, 0-8(r3)
-.fill 1, 0xe7b1fff8;stw r6, 0-8(r3)
-.fill 1, 0xe7b9fffc;stw r7, 0-4(r3)
+.ifill pop r6
+.ifill pop r7
+.ifill push r6
+.ifill push r7
prog_not:
-.fill 1, 0xe731fffc;ldw r6, 0-4(r3)
-.fill 1, 0xe4b7fffa;not r6
-.fill 1, 0xe7b1fffc;stw r6, 0-4(r3)
+.ifill pop r6
+.ifill not r6;0xe4b7fffa
+.ifill push r6
.text
main:
ldih r3, instrtable@hi
;set address to defer table
- ldil r9, instrtable@lo
- ldih r9, instrtable@hi
+ ldil r9, defertable@lo
+ ldih r9, defertable@hi
;call jit compiler
call+ jit
;set address to stack
- ldil r3, stack@lo
- ldih r3, stack@hi
+ ;ldil r3, stack@lo
+ ;ldih r3, stack@hi
+
+ ;make r15 a 0-register
+ ldis r15, 0
+ ;make r14 a 8-bit -1-register
+ ldis r14, 0xFF
;call jit'ed prog
call+ prog_start
;r9 ... address to actual entry in defer table
;r10... address to defer table
+ ;load address of program
+ ldil r13, prog_dup@lo
+ ldih r13, prog_dup@hi
+
+ ;load address of program
+ ldil r14, prog_mul@lo
+ ldih r14, prog_mul@hi
+
+ ldil r15, prog_consts@lo
+ ldih r15, prog_consts@hi
+
;backup defer table address
mov r10, r9
;decrement address to input by 1
ldil r7, prog_jmp@lo
ldih r7, prog_jmp@hi
;load branch template
- ldw r7, 16(r7)
+ ldw r7, 12(r7)
;if actual and base are equal, no entry
cmp r9, r10
;generate branch
sub r11, r6, r8
+ lrs r11, r11, 2
;set the upper 16 bit 0
andx r11, 0xFFFF
;shift to the position of imm in br
;case *
;42
vm_mul:
- ;load address of program
- ldil r4, prog_mul@lo
- ldih r4, prog_mul@hi
-
;program instruction (14)
- ldw r0, 0(r4)
+ ldw r0, 0(r14)
stx r0, 0(r2)
- ldw r0, 4(r4)
+ ldw r0, 4(r14)
stx r0, 4(r2)
- ldw r0, 8(r4)
+ ldw r0, 8(r14)
stx r0, 8(r2)
- ldw r0, 12(r4)
+ ldw r0, 12(r14)
stx r0, 12(r2)
- ldw r0, 16(r4)
+ ldw r0, 16(r14)
stx r0, 16(r2)
- ldw r0, 20(r4)
+ ldw r0, 20(r14)
stx r0, 20(r2)
- ldw r0, 24(r4)
+ ldw r0, 24(r14)
stx r0, 24(r2)
- ldw r0, 28(r4)
+ ldw r0, 28(r14)
stx r0, 28(r2)
- ldw r0, 32(r4)
+ ldw r0, 32(r14)
stx r0, 32(r2)
- ldw r0, 36(r4)
+ ldw r0, 36(r14)
stx r0, 36(r2)
- ldw r0, 40(r4)
+ ldw r0, 40(r14)
stx r0, 40(r2)
- ldw r0, 44(r4)
+ ldw r0, 44(r14)
stx r0, 44(r2)
- ldw r0, 48(r4)
+ ldw r0, 48(r14)
stx r0, 48(r2)
- ldw r0, 52(r4)
- stx r0, 52(r2)
;increment address
- addi r2, r2, 56
+ addi r2, r2, 52
br+ vm_loop
stx r0, 8(r2)
ldw r0, 12(r4)
stx r0, 12(r2)
- ldw r0, 16(r4)
- stx r0, 16(r2)
;increment address
- addi r2, r2, 20
+ addi r2, r2, 16
br+ vm_loop
stx r0, 8(r2)
ldw r0, 12(r4)
stx r0, 12(r2)
- ldw r0, 16(r4)
- stx r0, 16(r2)
;increment address
- addi r2, r2, 20
+ addi r2, r2, 16
br+ vm_loop
;case 0 1 2 3 4 5 6 7 8 9
;48-57
vm_consts:
- ;load address of program
- ldil r4, prog_consts@lo
- ldih r4, prog_consts@hi
-
;program instruction (3)
- ldw r0, 0(r4)
+ ldw r0, 0(r15)
;the first instr. loads r6 with the number
;thus we shall emulate this
;store this 'dynamic' instruction
stx r0, 0(r2)
- ldw r0, 4(r4)
+ ldw r0, 4(r15)
stx r0, 4(r2)
- ldw r0, 8(r4)
- stx r0, 8(r2)
;increment address
- addi r2, r2, 12
+ addi r2, r2, 8
br+ vm_loop
ldil r4, prog_lessthan@lo
ldih r4, prog_lessthan@hi
- ;program instruction (7)
+ ;program instruction (6)
ldw r0, 0(r4)
stx r0, 0(r2)
ldw r0, 4(r4)
stx r0, 12(r2)
ldw r0, 16(r4)
stx r0, 16(r2)
- ldw r0, 20(r4)
- stx r0, 20(r2)
- ldw r0, 24(r4)
- stx r0, 24(r2)
;increment address
- addi r2, r2, 28
+ addi r2, r2, 20
br+ vm_loop
;case D
;68
vm_dup:
- ;load address of program
- ldil r4, prog_dup@lo
- ldih r4, prog_dup@hi
;program instruction (3)
- ldw r0, 0(r4)
+ ldw r0, 0(r13)
stx r0, 0(r2)
- ldw r0, 4(r4)
+ ldw r0, 4(r13)
stx r0, 4(r2)
- ldw r0, 8(r4)
- stx r0, 8(r2)
;increment address
- addi r2, r2, 12
+ addi r2, r2, 8
br+ vm_loop
ldw r0, 8(r4)
stx r0, 8(r2)
- ldw r0, 12(r4)
- stx r0, 12(r2)
;increment address
- addi r2, r2, 16
+ addi r2, r2, 12
;pc+4
addi r1, r1, 4
ldil r4, prog_jmp@lo
ldih r4, prog_jmp@hi
- ;program instruction (3)
- ;decrement sp
- ;subi r3, r3, 4
+ ;program instruction (2)
+ ;pop r6
ldw r0, 0(r4)
stx r0, 0(r2)
- ;load sp
- ;ldw r6, 0(r3)
- ldw r0, 4(r4)
- stx r0, 4(r2)
;compare to 0
;cmpi r6,0
- ldw r0, 8(r4)
- stx r0, 8(r2)
+ ldw r0, 4(r4)
+ stx r0, 4(r2)
;breq+ vm_next
;is statically known
- ldw r0, 12(r4)
- stx r0, 12(r2)
+ ldw r0, 8(r4)
+ stx r0, 8(r2)
- ;r8 has now the current base
- ldw r8, 0(r3)
;we add the offset to this instruction
- addi r8, r8, 12
+ addi r8, r2, 12
;we know calculate the jump destination
ldis r7, 0xFF00
;r6 is now the 'real' negativ number
or r6, r6, r7
+ ;todo: testing showed (at least once) we are off by 2 instr.
+ ;addi r6, r6, 2
;multiply by to get the offset
lls r6, r6, 2
;generate address in table
add r6, r3, r6
;r0 now has the target address
+ ;todo: 0-4?
ldw r0, 0(r6)
;we calc the offset
- sub r8, r0, r2
+ sub r8, r0, r8
;we shift 2 bits out, because rel. br takes instr.
;count and not address amount ...
lrs r8, r8, 2
;shift to the position of imm in br
lls r8, r8, 7
;load template br
- ldw r0, 16(r4)
+ ldw r0, 12(r4)
or r0, r0, r8
- stx r0, 16(r2)
+ stx r0, 12(r2)
;increment address
- addi r2, r2, 20
+ addi r2, r2, 16
br+ vm_loop
stw r8, 4(r9)
;todo: check if -1 is needed
- subi r6, r6, 1
+ ;subi r6, r6, 1
;multiply with 2 to get offset right
lls r6, r6, 2
;add to current base