Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. package;
  2. import js.Lib;
  3. import vm.Assembler;
  4. import vm.Machine;
  5.  
  6. class Main
  7. {
  8.  
  9.  
  10. /**
  11. * Microcontroller spec:
  12. * 512 "bytes" of memory (16 bit ints)
  13. * 442 : cycle counter
  14. * 443 : accumulator
  15. * 444 : register X
  16. * 445 : register Y
  17. * 446 : program counter
  18. * 447 : stack pointer
  19. * 448-512 : stack (64 bytes)
  20. *
  21. * Read/Write pins by memory address(es) (hardware specific)
  22. * Interrupt handlers are bound by labelled instructions prefixed with IRQ (hardware specific)
  23. */
  24.  
  25. /**
  26. * Syntax:
  27. * INSTRUCTION ARG0 ... ARGN
  28. * ;Comment
  29. * alias word value
  30. * label:
  31. * int values only
  32. * int value prefix with # is a memory address
  33. * int value prefix with @ is a relative program counter offset
  34. * A, X and Y reference registers
  35. * A is accumulator, used for results
  36. */
  37.  
  38. static function main()
  39. {
  40. //Test program printing 5 ones, 10 2s, one -1, and handling one interrupt
  41. var src = "
  42. start:
  43. LDA 0
  44. LDX 5
  45. LDY iteration1
  46. JSR whileloop
  47. LDA 0
  48. LDX 10
  49. LDY iteration2
  50. JSR whileloop
  51. JMP end
  52. whileloop:
  53. ADD 1
  54. BGT A X @3
  55. JSR Y
  56. JMP @-3
  57. TAX
  58. RTS
  59. iteration1:
  60. TRC 1
  61. RTS
  62. iteration2:
  63. TRC 2
  64. RTS
  65. end:
  66. TRC -1
  67. BRK
  68. IRQ0:
  69. TRC Interrupt
  70. RTI
  71. ";
  72.  
  73. var a = new Machine("Alpha");
  74. a.load(Assembler.assemble(src));
  75. while (a.isRunning()){
  76. if (a.cycleCount == 8)
  77. a.interrupt(0);
  78. a.next();
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement