Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- import js.Lib;
- import vm.Assembler;
- import vm.Machine;
- class Main
- {
- /**
- * Microcontroller spec:
- * 512 "bytes" of memory (16 bit ints)
- * 442 : cycle counter
- * 443 : accumulator
- * 444 : register X
- * 445 : register Y
- * 446 : program counter
- * 447 : stack pointer
- * 448-512 : stack (64 bytes)
- *
- * Read/Write pins by memory address(es) (hardware specific)
- * Interrupt handlers are bound by labelled instructions prefixed with IRQ (hardware specific)
- */
- /**
- * Syntax:
- * INSTRUCTION ARG0 ... ARGN
- * ;Comment
- * alias word value
- * label:
- * int values only
- * int value prefix with # is a memory address
- * int value prefix with @ is a relative program counter offset
- * A, X and Y reference registers
- * A is accumulator, used for results
- */
- static function main()
- {
- //Test program printing 5 ones, 10 2s, one -1, and handling one interrupt
- var src = "
- start:
- LDA 0
- LDX 5
- LDY iteration1
- JSR whileloop
- LDA 0
- LDX 10
- LDY iteration2
- JSR whileloop
- JMP end
- whileloop:
- ADD 1
- BGT A X @3
- JSR Y
- JMP @-3
- TAX
- RTS
- iteration1:
- TRC 1
- RTS
- iteration2:
- TRC 2
- RTS
- end:
- TRC -1
- BRK
- IRQ0:
- TRC Interrupt
- RTI
- ";
- var a = new Machine("Alpha");
- a.load(Assembler.assemble(src));
- while (a.isRunning()){
- if (a.cycleCount == 8)
- a.interrupt(0);
- a.next();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement