README.arch-spec 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. == architecture ==
  2. - three storage regions
  3. - memory with 15-bit address space storing 16-bit values
  4. - eight registers
  5. - an unbounded stack which holds individual 16-bit values
  6. - all numbers are unsigned integers 0..32767 (15-bit)
  7. - all math is modulo 32768; 32758 + 15 => 5
  8. == binary format ==
  9. - each number is stored as a 16-bit little-endian pair (low byte, high byte)
  10. - numbers 0..32767 mean a literal value
  11. - numbers 32768..32775 instead mean registers 0..7
  12. - numbers 32776..65535 are invalid
  13. - programs are loaded into memory starting at address 0
  14. - address 0 is the first 16-bit value, address 1 is the second 16-bit value, etc
  15. == execution ==
  16. - After an operation is executed, the next instruction to read is immediately after the last argument of the current operation.
  17. If a jump was performed, the next operation is instead the exact destination of the jump.
  18. - Encountering a register as an operation argument should be taken as reading from the register or setting into the register as appropriate.
  19. == hints ==
  20. - Start with operations 0, 19, and 21.
  21. - Here's a code for the challenge website: jTTockJlJiOC
  22. - The program "9,32768,32769,4,19,32768" occupies six memory addresses and should:
  23. - Store into register 0 the sum of 4 and the value contained in register 1.
  24. - Output to the terminal the character with the ascii code contained in register 0.
  25. == opcode listing ==
  26. halt: 0
  27. stop execution and terminate the program
  28. set: 1 a b
  29. set register <a> to the value of <b>
  30. push: 2 a
  31. push <a> onto the stack
  32. pop: 3 a
  33. remove the top element from the stack and write it into <a>; empty stack = error
  34. eq: 4 a b c
  35. set <a> to 1 if <b> is equal to <c>; set it to 0 otherwise
  36. gt: 5 a b c
  37. set <a> to 1 if <b> is greater than <c>; set it to 0 otherwise
  38. jmp: 6 a
  39. jump to <a>
  40. jt: 7 a b
  41. if <a> is nonzero, jump to <b>
  42. jf: 8 a b
  43. if <a> is zero, jump to <b>
  44. add: 9 a b c
  45. assign into <a> the sum of <b> and <c> (modulo 32768)
  46. mult: 10 a b c
  47. store into <a> the product of <b> and <c> (modulo 32768)
  48. mod: 11 a b c
  49. store into <a> the remainder of <b> divided by <c>
  50. and: 12 a b c
  51. stores into <a> the bitwise and of <b> and <c>
  52. or: 13 a b c
  53. stores into <a> the bitwise or of <b> and <c>
  54. not: 14 a b
  55. stores 15-bit bitwise inverse of <b> in <a>
  56. rmem: 15 a b
  57. read memory at address <b> and write it to <a>
  58. wmem: 16 a b
  59. write the value from <b> into memory at address <a>
  60. call: 17 a
  61. write the address of the next instruction to the stack and jump to <a>
  62. ret: 18
  63. remove the top element from the stack and jump to it; empty stack = halt
  64. out: 19 a
  65. write the character represented by ascii code <a> to the terminal
  66. in: 20 a
  67. read a character from the terminal and write its ascii code to <a>; it can be assumed that once input starts, it will continue until a newline is encountered; this means that you can safely read whole lines from the keyboard and trust that they will be fully read
  68. noop: 21
  69. no operation