πΎ Archived View for thingvellir.net βΊ log βΊ 2023-03-07.gmi captured on 2024-06-16 at 12:19:41. Gemini links have been rewritten to link to archived content
β¬ οΈ Previous capture (2023-04-19)
-=-=-=-=-=-=-
This is another yet-unnamed fantasy CPU instruction set inspired by RISC-V, MIPS, and Professor Bruce Jacob's RiSC-16. It has fixed-length 16 bit instructions, 7 general purpose registers, and a zero register.
The eight registers directly available contain 16 bit, two's-compliment integers. The zero register always returns 0, and all writes to it are ignored. Whether an instruction's immediate value is interpreted as signed or unsigned depends on the opcode.
A fault will be triggered if the program counter or a SW/LW is not word-aligned.
F E D C B A 9 8 7 6 5 4 3 2 1 0 Bit βββββΌββββββββββββΌββββββββββββΌββββββββββββΌββββββββββββββββββββ€ β 0 β rs2 β rs1 β rd β opcode β RRR Type βββββ΄ββββββββββββ΄ββββββββββββ΄ββββββββββββ΄ββββββββββββββββββββ
F E D C B A 9 8 7 6 5 4 3 2 1 0 Bit βββββββββββββββββΌββββββββββββΌββββββββββββΌββββββββββββββββββββ€ β imm5 β rs1 β rd β opcode β RRI Type βββββββββββββββββ΄ββββββββββββ΄ββββββββββββ΄ββββββββββββββββββββ
F E D C B A 9 8 7 6 5 4 3 2 1 0 Bit βββββββββββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββ€ β imm8 β rd β opcode β RI Type βββββββββββββββββββββββββββββ΄ββββββββββββ΄ββββββββββββββββββββ
βββββββ¬βββ¬ββββ¬ββββββ β00000β00βRRRβ ADDβ rd := rs1 + rs2 βββββββΌβββΌββββΌββββββ€ β00001β01βRRRβ SUBβ rd := rs1 - rs2 βββββββΌβββΌββββΌββββββ€ β00010β02βRRRβ SLLβ rd := rs1 << rs2 βββββββΌβββΌββββΌββββββ€ β00011β03βRRRβ SRLβ rd := rs1 >>> rs2 βββββββΌβββΌββββΌββββββ€ β00100β04βRRRβ SRAβ rd := rs1 >> rs2 βββββββΌβββΌββββΌββββββ€ β00101β05βRRIβ ADIβ rd := rs1 + (signed)imm5 βββββββΌβββΌββββΌββββββ€ β00110β06βRI β LUIβ rd := imm8 << 8 βββββββΌβββΌββββΌββββββ€ β00111β07βRI β LLIβ rd := (rd & 0xFF00) | imm8 βββββββ΄βββ΄ββββ΄ββββββ
βββββββ¬βββ¬ββββ¬ββββββ β01000β08βRRIβ SWβ *(u16)(rd + imm5) := rs1 βββββββΌβββΌββββΌββββββ€ β01001β09βRRIβ LWβ rd := *(u16)(rs1 + imm5) βββββββΌβββΌββββΌββββββ€ β01010β0AβRRIβ SBβ *(u8)(rd + imm5) := rs1 & 0xFF βββββββΌβββΌββββΌββββββ€ β01011β0BβRRIβ LBβ rd := *(i8)(rs1 + imm5) βββββββΌβββΌββββΌββββββ€ β01100β0CβRRIβ LBUβ rd := *(u8)(rs1 + imm5) βββββββΌβββΌββββΌββββββ€ β01101β0Dβ β β β01110β0Eβ β β Reserved β01111β0Fβ β β βββββββ΄βββ΄ββββ΄ββββββ
βββββββ¬βββ¬ββββ¬ββββββ β10000β10βRRRβ ANDβ rd := rs1 & rs2 βββββββΌβββΌββββΌββββββ€ β10001β11βRRRβ ORβ rd := rs1 | rs2 βββββββΌβββΌββββΌββββββ€ β10010β12βRRRβ XORβ rd := rs1 ^ rs2 βββββββ΄βββ΄ββββ΄ββββββ
βββββββ¬βββ¬ββββ¬ββββββ β10011β13βRRRβ EQβ rd := rs1 == rs2 βββββββΌβββΌββββΌββββββ€ β10100β14βRRRβ GTβ rd := (signed)rs1 > (signed)rs2 βββββββΌβββΌββββΌββββββ€ β10101β15βRRRβ GEβ rd := (signed)rs1 >= (signed)rs2 βββββββΌβββΌββββΌββββββ€ β10110β16βRRRβ GTUβ rd := (unsigned)rs1 > (unsigned)rs2 βββββββΌβββΌββββΌββββββ€ β10111β17βRRRβ GEUβ rd := (unsigned)rs1 >= (unsigned)rs2 βββββββ΄βββ΄ββββ΄ββββββ
βββββββ¬βββ¬ββββ¬ββββββ β11000β18βRRRβ JLRβ rd := pc + 2; pc := rs1 + (signed)rs2 βββββββΌβββΌββββΌββββββ€ β11001β19βRI β BNSβ if rd == 0 then pc := pc + (signed)(imm8 * 2) βββββββΌβββΌββββΌββββββ€ β11010β1AβRI β BSβ if rd != 0 then pc := pc + (signed)(imm8 * 2) βββββββΌβββΌββββΌββββββ€ β11011β1Bβ β β Reserved βββββββ΄βββ΄ββββ΄ββββββ
βββββββ¬βββ¬ββββ¬ββββββ β11100β1CβRI β SFβ csr[imm8] := rd βββββββΌβββΌββββΌββββββ€ β11101β1DβRI β LFβ rd := csr[imm8] βββββββΌβββΌββββΌββββββ€ β11110β1EβRI β SYCβ System call βββββββΌβββΌββββΌββββββ€ β11111β1FβRI β BRKβ Break to debugger/environment βββββββ΄βββ΄ββββ΄ββββββ
; routine that prints 'hello, world\n' to an imaginary uart .org $0100 Start: li r1, Hello add r2, r0, 13 add r3, r0, 4 ; the imaginary uart's address @Loop: lbu r4, r1, 0 sb r1, r4, 0 adi r1, r1, 1 adi r2, r2, -1 eq r4, r2, r0 bns r4, @Loop brk $00 .org $0200 Hello: .ascii "hello, world" .byte $0a
βββββ¬ββββββββββββββββββββ βnopβ add r0, r0, r0β βββββΌββββββββββββββββββββ€ βnotβ sub A, B, r0β βββββΌββββββββββββββββββββ€ βli βlui A, IMM & 0xFF00β β βlli A, IMM & 0x00FFβ βββββ΄ββββββββββββββββββββ