Skip to content

Instantly share code, notes, and snippets.

@castleberrysam
Last active April 25, 2017 20:54
Show Gist options
  • Save castleberrysam/96c41a0968f51478909dd6d4e35d1bd4 to your computer and use it in GitHub Desktop.
Save castleberrysam/96c41a0968f51478909dd6d4e35d1bd4 to your computer and use it in GitHub Desktop.
16 registers
R0-R15
R0: program counter
R1: stack pointer
R15: link register
PUSH R 0000rrrr
CALL R, C 1001rrrr cccccccc cccccccc
POP R 0001rrrr
LFUN C, R, R 0010rrrr rrrrcccc
LFUN C, R, C 1010xxxx rrrrcccc cccccccc cccccccc
ADD R, R 00110xxx rrrrrrrr
ADDC R, R 00111xxx rrrrrrrr
ADD R, C 0111rrrr cccccccc cccccccc
SUB R, R 01000xxx rrrrrrrr
SUBC R, R 01001xxx rrrrrrrr
ROT R, R 01010xxx rrrrrrrr
ROTC R, R 01011xxx rrrrrrrr
ROT R, C 01100xxx rrrrcccc
ROTC R, C 01101xxx rrrrcccc
MOV R, C 1000rrrr cccccccc cccccccc
MOV R, [R + C] 1110xxxx rrrrrrrr cccccccc cccccccc
MOV [R + C], R 1111xxxx rrrrrrrr cccccccc cccccccc
BEZ R, R + C 1011xxxx rrrrrrrr cccccccc cccccccc
BNEZ R, R + C 1100xxxx rrrrrrrr cccccccc cccccccc
BGEZ R, R + C 1101xxxx rrrrrrrr cccccccc cccccccc
formats:
reg: oooorrrr
reg-imm4: ooooxxxx rrrrcccc
reg-imm4-flag: oooofxxx rrrrcccc
reg-imm16: oooorrrr cccccccc cccccccc
reg-imm4-imm16: ooooxxxx rrrrcccc cccccccc cccccccc
reg-reg: ooooxxxx rrrrrrrr
reg-reg-flag: oooofxxx rrrrrrrr
reg-reg-imm4: oooorrrr rrrrcccc
reg-reg-imm16: ooooxxxx rrrrrrrr cccccccc cccccccc
nop = rot r0, 0 = 0x6000
carry logic:
ADDC is like ADD but adds the value of the carry bit to the operands.
The carry bit is set for both ADD and ADDC if the addition carries out of the 16th bit.
SUBC is like SUB but subtracts the inverted value of the carry bit from the operands.
The carry bit is cleared for both SUB and SUBC if the subtraction borrows out of the 17th bit.
ROTC is like a shift where the bits that are shifted in are set to the value of the carry bit.
The carry can be cleared using ADD R, 0 and set using SUB R, 0.
memory mappings:
Address ranges are inclusive on both indices.
0xffff - 0xfffc : r : gpio input pins
0xfffb - 0xfff8 : rw : gpio output pins
0xfff7 - 0xfff0 : r : uart input buffer
0xffef - 0xffe8 : w : uart output buffer
0xffe6 : rw : uart input count
0xffe4 : rw : uart output count
Mappings not marked r give undefined data when read.
Mappings not marked w have no effect when written to.
Most gpio pins are just mapped to header pins on the Mimas board,
however the following assignments are of note:
The 3 least significant bits of the input pins are connected to push buttons.
The 8 least significant bits of the output pins are connected to LEDs.
The UART in the CPU is connected through TX and RX pins to header pins on the Mimas board.
It implements an RS232 serial port that programs running on the CPU can use.
To read from the UART:
1. read uart input count register.
2. if the input count is nonzero, the input data is available starting at the least
significant bytes of the uart input buffer.
3. after data has been processed, write to the input count register to clear it and
make room for more data to be placed in the buffer.
To write to the UART:
1. read uart output count register.
2. if the output count is nonzero, wait until it becomes zero (do not write to the buffer).
3. write output data into the output buffer starting at the most significant bytes and
moving backwards. The data should be written such that the final ordering of the data
in the buffer is the same as the original ordering before writing to the buffer.
4. write the number of bytes of data written into the output buffer (max 8) to the output
count register.
Currently the baud rate of the serial port is 1M baud.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment