16 bit machine 64k memory - $0000 -> $FFFF 5 registers - A (8bits), B (8bits), D (16bits -> holds concatenated value of A and B), X(16bits), Y(16bits)
4k of memory reserved for screen output(? do I need this? probably not really) $A000 - $AFA0
80x25 screen
For loading data into registers, storing data in memory and ending execution.
Mnemonic | Description | Example | What will this example do? |
---|---|---|---|
LDA $01 |
Assigns a value to our A register | LDA #$2A | Assigns the hex value $2A to the A register |
LDX $02 |
Assigns a value to our X register | LDX #16000 | Assigns the number 16,000 to the X register |
STA $03 |
Stores the value of the A register to a memory location | STA ,X | Stores the value of the A register to the memory location pointed to by the X register |
END $04 |
Terminates the B32 program | END START | Terminate the program and tell our assembler that execution of our program should start at the START label |
Comparisons are assigned to a comparison flag result which is set out as follows.
1 byte | |||||||
---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
nothing | nothing | nothing | nothing | Greater Than | Less Than | Not Equal | Equal |
Mnemonic | Description | Example | What will this example do? |
---|---|---|---|
CMPA $05 |
Compares the value of the ‘A’ register | CMPA #$20 | Compares the value of the ‘A’ |
CMPB $06 |
Compares the value of the ‘B’ register | CMPB #$20 | Compares the value of the ‘B’ register with $20 and sets our internal “compare registers” appropriately |
CMPX $07 |
Compares the value of the ‘X’ register | CMPX #$A057 | Compares the value of the ‘X’ register with $A057 and sets our internal “compare registers” appropriately |
CMPY $08 |
Compares the value of the ‘Y’ register | CMPY #$A057 | Compares the value of the ‘Y’ register with $A057 and sets our internal “compare registers” appropriately |
CMPD $09 |
Compares the value of the ‘D’ register | CMPD #$A057 | Compares the value of the ‘D’ register with $A057 and sets our internal “compare registers” appropriately |
Mnemonic | Description | Example | What will this example do? |
---|---|---|---|
JMP $0A |
Jumps to a specific location in memory and resumes execution | JMP #$3000 | Jumps to memory location $3000 and resumes execution at this location |
JEQ $0B |
Jumps to a specific location in memory ONLY if the result of the last compare was equal | CMPA #$6A JEQ #$3000 |
Compares the value of the ‘A’ register to $6A and if it’s equal, the program jumps to memory location #$3000 and resumes execution |
JNE $0C |
Jumps to a specific location in memory ONLY if the result of the last compare was NOT equal | CMPA #$6A JNE #$3000 |
Compares the value of the ‘A’ register to $6A and if it’s NOT equal, the program jumps to memory location #$3000 and resumes execution |
JGT $0D |
Jumps to a specific location in memory ONLY if the result of the last compare was greater than the value | CMPA #$6A JGT #$3000 |
Compares the value of the ‘A’ register to $6A and if ‘A’ is greater than $6A, the program jumps to memory location #$3000 and resumes execution |
JLT $0E |
Jumps to a specific location in memory ONLY if the result of the last compare was less than the value | CMPA #$6A JLT #$3000 |
Compares the value of the ‘A’ register to $6A and if ‘A’ is less than $6A, the program jumps to memory location #$3000 and resumes execution |
Mnemonic | Description | Example | What will this example do? |
---|---|---|---|
INCA $0F |
Increment the value in the ‘A’ register by 1 | INCA | Increment the value of the ‘A’register by 1 |
INCB $10 |
Increment the value in the ‘B’ register by 1 | INCB | Increment the value of the ‘B’ register by 1 |
INCX $11 |
Increment the value in the ‘X’ register by 1 | INCX | Increment the value of the ‘X’ register by 1 |
INCY $12 |
Increment the value in the ‘Y’ register by 1 | INCY | Increment the value of the ‘Y’ register by 1 |
INCD $13 |
Increment the value in the ‘D’ register by 1 | INCD | Increment the value of the ‘D’ register by 1 |
DECA $14 |
Decrement the value in the ‘A’ register by 1 | DECA | Decrement the value of the ‘A’ register by 1 |
DECB $15 |
Decrement the value in the ‘B’ register by 1 | DECB | Decrement the value of the ‘B’ register by 1 |
DECX $16 |
Decrement the value in the ‘X’ register by 1 | DECX | Decrement the value of the ‘X’ register by 1 |
DECY $17 |
Decrement the value in the ‘Y’ register by 1 | DECY | Decrement the value of the ‘Y’ register by 1 |
DECD $18 |
Decrement the value in the ‘D’ register by 1 | DECD | Decrement the value of the ‘D’ register by 1 |
ROLA $19 |
Rotate ‘A’ register to the left | ROLA | Rotates ‘A’ register to the left |
ROLB $1A |
Rotate ‘B’ register to the left | ROLB | Rotates ‘B’ register to the left |
RORA $1B |
Rotate ‘A’ register to the right | RORA | Rotates ‘A’ register to the right |
RORB $1C |
Rotate ‘B’ register to the right | RORB | Rotates ‘B’ register to the right |
ADCA $1D |
Adds 1 to the value in ‘A’ register, IF carry flag is set | ADCA | Adds 1 to the value in ‘A’ register, IF carry flag is set |
ADCB $1E |
Adds 1 to the value in ‘B’ register, IF carry flag is set | ADCB | Adds 1 to the value in ‘B’ register, IF carry flag is set |
ADDA $1F |
Adds a value to the ‘A’ register | ADDA #$30 | Adds $30 to the value in ‘A’ register, storing the value in ‘A’ register |
ADDB $20 |
Adds a value to the ‘B’ register | ADDB #$30 | Adds $30 to the value in ‘B’ register, storing the value in ‘B’ register |
ADDAB $21 |
Adds the value of the ‘A’ register to the value of the ‘B’ register and stores the result in the ‘D’ register | ADDAB | Adds the value of the ‘A’ register with the value of the ‘B’ register, storing the result in the ‘D’ register |
LDB $22 |
Loads a value into the ‘B’ register | LDB #$A0 | Places $A0 in the ‘B’ register |
LDY $23 |
Loads a value into the ‘Y’ register | LDY #$89FF | Places $89FF in the ‘Y’ register |
Flags are used to store state in the machine.
The comparison flag is set out as follows:
1 byte | |||||||
---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
nothing | nothing | nothing | nothing | Greater Than | Less Than | Not Equal | Equal |
It is used to store the result of a comparison operation.
This is a single bit. It is flipped when a mathematical operation overflows.
A single bit. Used to "carry" bits from a bit shift operation
The flag byte in this machine looks like:
1 byte | |||||||
---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
nothing | nothing | nothing | nothing | nothing | nothing | Carry | Overflow |
The compare flag is stored in a separate byte.
Data | Length | Description |
---|---|---|
“B32” | 3 Bytes | Our magic header number |
<Starting Address> | 2 Bytes | This is a 16-bit integer that tells our virtual machine where, in memory, to place our program. |
<Execution Address> | 2 Bytes | This is a 16-bit integer that tells our virtual machine where to begin execution of our program. |
<ByteCode> | ?? Bytes | This will be the start of our bytecode, which can be any length. |
Our assembler expects input in the format:
[Optional Label:]
<white space><mnemonic><white space><operand>[Optional white space]<newline>