This programming language may be used to instruct a computer to perform a task.
If you know Computer/zero Assembly, please write code for some of the tasks not implemented in Computer/zero Assembly.
There are only 8 instructions to use. The top 3 bits represent the instruction, the bottom 5 are the operand. Operands represent absolute memory addresses only. Therefore, the only way to add or subtract a constant is to embed it in your program code (and doing so will consume an entire extra byte.)
STP don't use their operands, so you can embed arbitrary data inside these instructions to save a little space.
0b000xxxxx. This instruction does nothing.
- LDA x:
0b001xxxxx. Loads the 8-bit value at memory address x into the accumulator.
- STA x:
0b010xxxxx. Stores the 8-bit value in the accumulator into memory address x.
- ADD x:
0b011xxxxx. Adds the value at memory address x to the value in the accumulator, and the result is stored in the accumulator.
- SUB x:
0b100xxxxx. Subtracts the value at memory address x from the value in the accumulator. The result is stored in the accumulator.
- BRZ x:
0b101xxxxx. Branch If Zero. If the accumulator contains the value 0, execution will jump to memory address x. Otherwise, this is the same as a NOP.
- JMP x:
0b110xxxxx. Execution jumps to memory address x.
0b111xxxxx. Execution of code ends.
There are only 32 bytes of memory, and this includes your program code, leaving very little memory to work with. As such, there are no function calls or recursion, since both require a call stack and much more RAM than we have here.
With such little RAM available, the biggest tool we have at our disposal for programming is self-modifying code. The CPU makes no distinction between data and instructions, and as such we can store values into memory before that memory is executed, in order to change what the computer will do. Here's an example:
The above snippet of code never actually
ADDs anything, since that instruction gets overwritten by
SUB 3. And what is
SUB 3 subtracting? It's subtracting the value of
STP, which can be encoded as any number between 0xE0 and 0xFF. Specifically, the encoding of
SUB 3 (i.e. 0b10000011) is decreased by some value between 0xE0 and 0xFF, and since all arithmetic on this CPU is modulo 256 (as is standard for nearly all 8-bit CPUs), there will be roll-over across the FF-00 boundary. Without a hardware carry flag, however, it's difficult to track this overflow.
Pages in category "Computer/zero Assembly"
The following 17 pages are in this category, out of 17 total.