1*4b169a6bSchristos== architecture == 2*4b169a6bSchristos- three storage regions 3*4b169a6bSchristos - memory with 15-bit address space storing 16-bit values 4*4b169a6bSchristos - eight registers 5*4b169a6bSchristos - an unbounded stack which holds individual 16-bit values 6*4b169a6bSchristos- all numbers are unsigned integers 0..32767 (15-bit) 7*4b169a6bSchristos- all math is modulo 32768; 32758 + 15 => 5 8*4b169a6bSchristos 9*4b169a6bSchristos== binary format == 10*4b169a6bSchristos- each number is stored as a 16-bit little-endian pair (low byte, high byte) 11*4b169a6bSchristos- numbers 0..32767 mean a literal value 12*4b169a6bSchristos- numbers 32768..32775 instead mean registers 0..7 13*4b169a6bSchristos- numbers 32776..65535 are invalid 14*4b169a6bSchristos- programs are loaded into memory starting at address 0 15*4b169a6bSchristos- address 0 is the first 16-bit value, address 1 is the second 16-bit value, etc 16*4b169a6bSchristos 17*4b169a6bSchristos== execution == 18*4b169a6bSchristos- After an operation is executed, the next instruction to read is immediately after the last argument of the current operation. 19*4b169a6bSchristos If a jump was performed, the next operation is instead the exact destination of the jump. 20*4b169a6bSchristos- Encountering a register as an operation argument should be taken as reading from the register or setting into the register as appropriate. 21*4b169a6bSchristos 22*4b169a6bSchristos== hints == 23*4b169a6bSchristos- Start with operations 0, 19, and 21. 24*4b169a6bSchristos- Here's a code for the challenge website: jTTockJlJiOC 25*4b169a6bSchristos- The program "9,32768,32769,4,19,32768" occupies six memory addresses and should: 26*4b169a6bSchristos - Store into register 0 the sum of 4 and the value contained in register 1. 27*4b169a6bSchristos - Output to the terminal the character with the ascii code contained in register 0. 28*4b169a6bSchristos 29*4b169a6bSchristos== opcode listing == 30*4b169a6bSchristoshalt: 0 31*4b169a6bSchristos stop execution and terminate the program 32*4b169a6bSchristosset: 1 a b 33*4b169a6bSchristos set register <a> to the value of <b> 34*4b169a6bSchristospush: 2 a 35*4b169a6bSchristos push <a> onto the stack 36*4b169a6bSchristospop: 3 a 37*4b169a6bSchristos remove the top element from the stack and write it into <a>; empty stack = error 38*4b169a6bSchristoseq: 4 a b c 39*4b169a6bSchristos set <a> to 1 if <b> is equal to <c>; set it to 0 otherwise 40*4b169a6bSchristosgt: 5 a b c 41*4b169a6bSchristos set <a> to 1 if <b> is greater than <c>; set it to 0 otherwise 42*4b169a6bSchristosjmp: 6 a 43*4b169a6bSchristos jump to <a> 44*4b169a6bSchristosjt: 7 a b 45*4b169a6bSchristos if <a> is nonzero, jump to <b> 46*4b169a6bSchristosjf: 8 a b 47*4b169a6bSchristos if <a> is zero, jump to <b> 48*4b169a6bSchristosadd: 9 a b c 49*4b169a6bSchristos assign into <a> the sum of <b> and <c> (modulo 32768) 50*4b169a6bSchristosmult: 10 a b c 51*4b169a6bSchristos store into <a> the product of <b> and <c> (modulo 32768) 52*4b169a6bSchristosmod: 11 a b c 53*4b169a6bSchristos store into <a> the remainder of <b> divided by <c> 54*4b169a6bSchristosand: 12 a b c 55*4b169a6bSchristos stores into <a> the bitwise and of <b> and <c> 56*4b169a6bSchristosor: 13 a b c 57*4b169a6bSchristos stores into <a> the bitwise or of <b> and <c> 58*4b169a6bSchristosnot: 14 a b 59*4b169a6bSchristos stores 15-bit bitwise inverse of <b> in <a> 60*4b169a6bSchristosrmem: 15 a b 61*4b169a6bSchristos read memory at address <b> and write it to <a> 62*4b169a6bSchristoswmem: 16 a b 63*4b169a6bSchristos write the value from <b> into memory at address <a> 64*4b169a6bSchristoscall: 17 a 65*4b169a6bSchristos write the address of the next instruction to the stack and jump to <a> 66*4b169a6bSchristosret: 18 67*4b169a6bSchristos remove the top element from the stack and jump to it; empty stack = halt 68*4b169a6bSchristosout: 19 a 69*4b169a6bSchristos write the character represented by ascii code <a> to the terminal 70*4b169a6bSchristosin: 20 a 71*4b169a6bSchristos 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 72*4b169a6bSchristosnoop: 21 73*4b169a6bSchristos no operation 74