# COA_exp **Repository Path**: themql/COA_exp ## Basic Information - **Project Name**: COA_exp - **Description**: 计算机组成原理与系统结构实验(Computer Organization and Architecture experiment) - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-04-29 - **Last Updated**: 2023-09-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 实现指令 ### R型 | 字段 | OP | rs | rt | rd | shamt | func | 功能描述 | | ------------- | ------- | --- | ----- | ----- | ----- | ------- | ------------------ | | 位数 | 6 | 5 | 5 | 5 | 5 | 6 | | | 汇编助记符 | 编码 | | | | | | | | add rd,rs,rt | 000_000 | rs | rt | rd | 00000 | 100_000 | rs + rt -> rd | | sub rd,rs,rt | 000_000 | rs | rt | rd | 00000 | 100_010 | rs - rt -> rd | | and rd,rs,rt | 000_000 | rs | rt | rd | 00000 | 100_100 | rs & rt -> rd | | or rd,rs,rt | 000_000 | | | | 00000 | 100_101 | rs \| rt -> rd | | xor rd,rs,rt | 000_000 | | | | 00000 | 100_110 | rs ^ rt -> td | | nor rd,rs,rt | 000_000 | | | | 00000 | 100_111 | ~ (rs \| rt) -> rd | | sltu rd,rs,rt | 000_000 | | | | 00000 | 101_011 | (rs < rt) ?1 :0 | | sllv rd,rt,rs | 000_000 | | | | 00000 | 000_100 | rt << rs -> rd | | jr rs | 000_000 | rs | 00000 | 00000 | 00000 | 001_000 | rs -> PC | ### I型 | 字段 | OP | rs | rt | imm | 功能描述 | | ---------------- | ------- | --- | --- | ------ | ------------------------------------- | | 位数 | 6 | 5 | 5 | 16 | | | 汇编助记符 | 编码 | | | | | | addi rt,rs,imm | 001_000 | rs | rt | imm | rs + imm -> rt | | andi rt,rs,imm | 001_100 | | | | rs & imm -> rt | | xori rt,rs,imm | 001_110 | | | | rs ^ imm -> rt | | sltiu rt,rs,imm | 001_011 | | | | (rs < imm) ?1 :0 | | beq rs,rt,label | 000_100 | rs | rt | offset | (rs == rt) ?PC + 4 + offset * 4 -> PC | | bne rs,rt,label | 000_101 | rs | rt | offset | (rs != rt) ?PC + 4 + offset * 4 -> PC | | lw rt,offset(rs) | 100_011 | rs | rt | offset | (rs + offset) -> rt | | sw rt,offset | 101_011 | rs | rt | offset | rt -> (rs + offset) | ### J型 | 字段 | OP | address | 功能描述 | | --------- | ------- | ------- | ------------------------------------------------------------------------------------------- | | 位数 | 6 | 26 | | | 汇编助记符 | 编码 | | | | j label | 000_010 | address | {(PC + 4)[31 -: 4], address, 2'b00} -> PC | | jal label | 000_011 | address | (PC + 4) -> \$31(单周期实现)/ (PC + 8) -> \$31(流水线实现), {(PC + 4)[31 -: 4], address, 2'b00} -> PC | ## 汇编转机器码 安装好工具链(mips-2013.05-65-mips-sde-elf),使用如下脚本生成mif文件 https://github.com/Ellen7ions/bin2mem Q:为什么和书里给的机器码有点不一样? A:MIPS标准指令系统考虑到流水线延迟,引入分支延迟槽,就是位于分支指令后面的一条指令,不管分支发生与否其总是被执行。所以本实验用编译器生成的机器码,每条跳转指令后都有一条空指令(00000000)。