the pc isn't any more kept seperated from the
address to the input => reduced instructions
vm:
;r0 ... lut address (can be overwritten)
vm:
;r0 ... lut address (can be overwritten)
- ;r1 ... addr to input
- ;r2 ... pc
+ ;r1 ... address to input, every byte is a new input
+ ; includes pc implicitly
;r3 ... effective stack address
;r3 ... effective stack address
- ;r4 ... effective input addr
- ;set pc to -1
- ldis r2, 0xFFFF
+ ;decrement address to input by 1
+ subi r1, r1, 1
;load base address of stack
ldil r3, stack@lo
ldih r3, stack@hi
vm_default:
vm_loop:
;load base address of stack
ldil r3, stack@lo
ldih r3, stack@hi
vm_default:
vm_loop:
- ;increment pc
- addi r2, r2, 1
- ;generate effective input addr
- add r4, r1, r2
+ ;increment input address
+ addi r1, r1, 1
;we need to multiply input by 4 to get correct address offset
lls r0, r5, 2
;calc position in jumptable
;we need to multiply input by 4 to get correct address offset
lls r0, r5, 2
;calc position in jumptable
;73
vm_imm:
;load new high byte
;73
vm_imm:
;load new high byte
;shift high byte
lls r6, r6, 8
;load 2nd byte
;shift high byte
lls r6, r6, 8
;load 2nd byte
;add to high byte
add r6, r6, r7
;shift
lls r6, r6, 8
;load
;add to high byte
add r6, r6, r7
;shift
lls r6, r6, 8
;load
;add
add r6, r6, r7
;shift
lls r6, r6, 8
;load
;add
add r6, r6, r7
;shift
lls r6, r6, 8
;load
;add
add r6, r6, r7
;store result to stack
stw r6, 0(r3)
;pc+4
;add
add r6, r6, r7
;store result to stack
stw r6, 0(r3)
;pc+4
;increment sp
addi r3, r3, 4
br+ vm_loop
;increment sp
addi r3, r3, 4
br+ vm_loop
;compare to 0
cmpi r6,0
;increment pc if == 0
;compare to 0
cmpi r6,0
;increment pc if == 0
breq+ vm_loop
;if != 0
;set r6 to 0 (to clear upper bytes)
ldis r6, 0
;load pc+1 input
breq+ vm_loop
;if != 0
;set r6 to 0 (to clear upper bytes)
ldis r6, 0
;load pc+1 input
;compare input with neg. max of 8 bit
cmpi r6, 0x80
brlt- vm_possign
;compare input with neg. max of 8 bit
cmpi r6, 0x80
brlt- vm_possign
add r6, r6, r7
vm_possign:
;pc += data
add r6, r6, r7
vm_possign:
;pc += data