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