windowsでiverilog その163

# 概要　
windowsでiverilogやってみた。
自作cpu、見つけたので、調査してみた。

# 参考にしたページ

https://github.com/kkinos/zktc


# zktcのcpu仕様
レジスタ16ビット
x0-x7
pc　プログラムカウンタ
sp　スタックポインタ
psr　ステータス
TLR
THR
PPC
PPSR

命令セット

|Opcode	Function	|Instruction	|Mnemonic	|Operation	|Assembly|
|:-|:-|:-|:-|:-|
|00000	00001	|move data	|MOV	|x[rd] = x[rs]	|mov rd, rs
|00000	00010	|add			|ADD	|x[rd] = x[rd] + x[rs]	|add rd, rs
|00000	00011	|sub			|SUB	|x[rd] = x[rd] - x[rs]	|sub rd, rs
|00000	00100	|and			|AND	|x[rd] = x[rd] & x[rs]	|and rd, rs
|00000	00101	|or			|OR	|x[rd] = x[rd] or x[rs]	|or rd, rs
|00000	00110	|xor			|XOR	|x[rd] = x[rd] ^ x[rs]	|xor rd, rs
|00000	00111	|shift left logical	|SLL	|x[rd] = x[rd] << x[rs]	|sll rd, rs
|00000	01000	|shift right logical	|SRL	|x[rd] = x[rd] >>u x[rs]	|srl rd, rs
|00000	01001	|shift right arithmetic	|SRA	|x[rd] = x[rd] >>s x[rs]	|sra rd, rs
|00001	|add immediate	|ADDI	|x[rd] = x[rs] + imm	|addi rd, rs, imm
|00010	|sub immediate	|SUBI	|x[rd] = x[rs] - imm	|subi rd, rs, imm
|00011	|branch if equal	|BEQ	|if(x[rd] == x[rs]) PC += sext(imm)	|beq rd, rs, imm
|00100	|branch if not equal	|BNQ	|if(x[rd] != x[rs]) PC += sext(imm)	|bnq rd, rs, imm
|00101	|branch if less than	|BLT	|if(x[rd] <s x[rs]) PC += sext(imm)	|blt rd, rs, imm
|00110	|branch if greater than or equal	|BGE	|if(x[rd] >=s x[rs]) PC += sext(imm)	|bge rd, rs, imm
|00111	|BLT unsigned	|BLTU	|if(x[rd] <u x[rs]) PC += sext(imm)	|bltu rd, rs, imm
|01000	|BGE unsigned	|BGEU	|if(x[rd] >=u x[rs]) PC += sext(imm)	|bgeu rd, rs, imm
|01001	|jump and link register	|JALR	|x[rd] = PC + 2, PC = x[rs] + sext(imm)	|jalr rd, rs, imm
|01010	|load half word	|LH	|x[rd] = sext(M[x[rs] + sext(imm)][7:0])	|lh rd, rs, imm
|01011	|load half word unsigned	|LHU	|x[rd] = {8'b0, M[x[rs] + sext(imm)][7:0]}	|lhu rd, rs, imm
|01100	|load word	|LW	|x[rd] = M[x[rs] + sext(imm)]	|lw rd, rs, imm
|01101	|store half word	|SH	|M[x[rs] + sext(imm)] = x[rd][7:0]	|sh rd, rs, imm
|01110	|store word	|SW	|M[x[rs] + sext(imm)] = x[rd]	|sw rd, rs, imm
|10000	|jump and link	|JAL	|x[rd] = PC + 2, PC += sext(imm)	|jal rd, imm
|10001	|load immediate low 8 bit	|LIL	|x[rd] = {8'b0, imm}	|lil rd, imm
|10010	|load immediate high 8 bit	|LIH	|x[rd] = {imm ,8'b0}	|lih rd, imm
|11110	00001	|push	|PUSH	|SP -= 2, M[SP] = x[rd]	|push rd
|11110	00010	|pop	|POP	|x[rd] = M[SP], SP += 2	|pop rd
|11110	00011	|read PC	|RPC	|x[rd] = PC + 2	|rpc rd
|11110	00100	|read SP	|RSP	|x[rd] = SP	|rsp rd
|11110	00101	|read PSR	|RPSR	|x[rd] = PSR	|rpsr rd
|11110	00110	|read TLR	|RTLR	|x[rd] = TLR	|rtlr rd
|11110	00111	|read THR	|RTHR	|x[rd] = THR	|rthr rd
|11110	01000	|read PPC	|RPPC	|x[rd] = PPC	|rppc rd
|11110	01001	|read PPSR	|RPPSR	|x[rd] = PPSR	|rppsr rd
|11110	01010	|write SP	|WSP	|SP = x[rd]	|wsp rd
|11110	01011	|write PSR	|WPSR	|PSR = x[rd]	|wpsr rd
|11110	01100	|write TLR	|WTLR	|TLR = x[rd]	|wtlr rd
|11110	01101	|write THR	|WTHR	|THR = x[rd]	|wthr rd
|11110	01110	|write PPC	|WPPC	|WPPC = x[rd]	|wppc rd
|11110	01111	|write PPSR	|WPPSR	|WPPSR = x[rd]	|wppsr rd
|11111	00001	|copy PPC to PC and copy PPSR to PSR	|RFI	|PC = PPC, PSR = PPSR	|rfi
|11111	00010	|read TR	|RTR	|{THR, TLR} = TR	|rtr
|11111	00011	|write TR	|WTR	|TR = {THR, TLR}	|wtr


以上。