.fill 42, 0
prog_eof:
-.ifill ldw r0, 0-4(r3);0xE701FFFC
+.ifill pop r0
.ifill ret+
prog_mul:
-.ifill subi r3, r3, 4;0xE1998020
-.ifill ldw r6, 0(r3);0xe7318000
-.ifill ldw r7, 0-4(r3);0xe739fffc
+.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 subi r7, r7, 2;0xe1bb8010
.fill 0x0b7ffe83;brnz+ loop
-.ifill stw r8, 0-4(r3);0xe7c1fffc
+.ifill push r8
prog_consts:
.fill 0xed300004;ldis r6, CONST
-.ifill stw r6, 0(r3);0xe7b18000
-.ifill addi r3, r3, 4;0xe1198020
+.ifill push r6
prog_add:
-.ifill subi r3, r3, 4;0xe1998020
-.ifill ldw r6, 0(r3);0xe7318000
-.ifill ldw r7, 0-4(r3);0xe739fffc
+.ifill pop r6
+.ifill pop r7
.ifill add r7, r7, r6;0xe03bb000
-.ifill stw r7, 0-4(r3);0xe7b9fffc
+.ifill push r7
prog_sub:
-.ifill subi r3, r3, 4;0xe1998020
-.ifill ldw r6, 0(r3);0xe7318000
-.ifill ldw r7, 0-4(r3);0xe739fffc
+.ifill pop r6
+.ifill pop r7
.ifill sub r7, r7, r6;0xe0bbb000
-.ifill stw r7, 0-4(r3);0xe7b9fffc
+.ifill push r7
prog_lessthan:
-.ifill subi r3, r3, 4;0xe1998020
-.ifill ldw r6, 0(r3);0xe7318000
-.ifill ldw r7, 0-4(r3);0xe739fffc
-.ifill ldis r8, 0;0xed400004
+.ifill pop r6
+.ifill pop r7
.ifill cmp r7, r6;0xec3b0000
-.ifill ldislt r8, 0xFF;0xbd4007fc
-.ifill stw r8, 0-4(r3);0xe7c1fffc
+.ifill pushlt r14
+.ifill pushge r15
prog_dup:
-.ifill ldw r6, 0-4(r3);0xe731fffc
-.ifill stw r6, 0(r3);0xe7b18000
-.ifill addi r3, r3, 4;0xe1198020
+.ifill fetch r6
+.ifill push r6
prog_jmp:
-.ifill subi r3, r3, 4;0xe1998020
-.ifill ldw r6, 0(r3);0xe7318000
+.ifill pop r6
.ifill cmpi r6,0;0xecb00000
;static calced
.fill 1, 0x1b000103;breq- vm_next
prog_imm:
.fill 1, 0xed400000;ldil r6, CONST
.fill 1, 0xed400002;ldih r6, CONST
-.ifill stw r6, 0(r3);0xe7b18000
-.ifill addi r3, r3, 4;0xe1198020
+.ifill push r6
prog_pop:
-.ifill subi r3, r3, 4;0xe1998020
+.ifill disc r6
prog_xch:
-.ifill ldw r6, 0-4(r3);0xe731fffc
-.ifill ldw r7, 0-8(r3);0xe739fff8
-.ifill stw r6, 0-8(r3);0xe7b1fff8
-.ifill stw r7, 0-4(r3);0xe7b9fffc
+.ifill pop r6
+.ifill pop r7
+.ifill push r6
+.ifill push r7
prog_not:
-.ifill ldw r6, 0-4(r3);0xe731fffc
+.ifill pop r6
.ifill not r6;0xe4b7fffa
-.ifill stw r6, 0-4(r3);0xe7b1fffc
+.ifill push r6
.text
main:
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
;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-4(r3)
;we add the offset to this instruction
- addi r8, r2, 16
+ addi r8, r2, 12
;we know calculate the jump destination
;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