Advertisement
pushrbx

Synacor Challange

Sep 2nd, 2013
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. == Synacor Challenge ==
  2. In this challenge, your job is to use this architecture spec to create a
  3. virtual machine capable of running the included binary. Along the way,
  4. you will find codes; submit these to the challenge website to track
  5. your progress. Good luck!
  6.  
  7.  
  8. == architecture ==
  9. - three storage regions
  10. - memory with 15-bit address space storing 16-bit values
  11. - eight registers
  12. - an unbounded stack which holds individual 16-bit values
  13. - all numbers are unsigned integers 0..32767 (15-bit)
  14. - all math is modulo 32768; 32758 + 15 => 5
  15.  
  16. == binary format ==
  17. - each number is stored as a 16-bit little-endian pair (low byte, high byte)
  18. - numbers 0..32767 mean a literal value
  19. - numbers 32768..32775 instead mean registers 0..7
  20. - numbers 32776..65535 are invalid
  21. - programs are loaded into memory starting at address 0
  22. - address 0 is the first 16-bit value, address 1 is the second 16-bit value, etc
  23.  
  24. == execution ==
  25. - After an operation is executed, the next instruction to read is immediately after the last argument of the current operation. If a jump was performed, the next operation is instead the exact destination of the jump.
  26. - Encountering a register as an operation argument should be taken as reading from the register or setting into the register as appropriate.
  27.  
  28. == hints ==
  29. - Start with operations 0, 19, and 21.
  30. - Here's a code for the challenge website: DMFwlWpWDCPo
  31. - The program "9,32768,32769,4,19,32768" occupies six memory addresses and should:
  32. - Store into register 0 the sum of 4 and the value contained in register 1.
  33. - Output to the terminal the character with the ascii code contained in register 0.
  34.  
  35. == opcode listing ==
  36. -halt: 0
  37. stop execution and terminate the program
  38. +set: 1 a b
  39. set register <a> to the value of <b>
  40. -push: 2 a
  41. push <a> onto the stack
  42. -pop: 3 a
  43. remove the top element from the stack and write it into <a>; empty stack = error
  44. +eq: 4 a b c
  45. set <a> to 1 if <b> is equal to <c>; set it to 0 otherwise
  46. +gt: 5 a b c
  47. set <a> to 1 if <b> is greater than <c>; set it to 0 otherwise
  48. -jmp: 6 a
  49. jump to <a>
  50. -jt: 7 a b
  51. if <a> is nonzero, jump to <b>
  52. -jf: 8 a b
  53. if <a> is zero, jump to <b>
  54. +add: 9 a b c
  55. assign into <a> the sum of <b> and <c> (modulo 32768)
  56. +mult: 10 a b c
  57. store into <a> the product of <b> and <c> (modulo 32768)
  58. +mod: 11 a b c
  59. store into <a> the remainder of <b> divided by <c>
  60. +and: 12 a b c
  61. stores into <a> the bitwise and of <b> and <c>
  62. +or: 13 a b c
  63. stores into <a> the bitwise or of <b> and <c>
  64. +not: 14 a b
  65. stores 15-bit bitwise inverse of <b> in <a>
  66. -rmem: 15 a b
  67. read memory at address <b> and write it to <a>
  68. -wmem: 16 a b
  69. write the value from <b> into memory at address <a>
  70. -call: 17 a
  71. write the address of the next instruction to the stack and jump to <a>
  72. -ret: 18
  73. remove the top element from the stack and jump to it; empty stack = halt
  74. -out: 19 a
  75. write the character represented by ascii code <a> to the terminal
  76. -in: 20 a
  77. 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
  78. -noop: 21
  79. no operation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement