计算机组成原理上机实验5 单周期CPU
2018-05-04
14664 字
49 分钟

实验目的

实验平台

实验过程(分析)

  1. 模块化设计,主要有以下几个模块

    a) alu模块——算术逻辑单元

    b) regfile模块——寄存器文件

    c) mux模块——选择器

    d) IP核生成的IMem模块和DMem模块——存放数据段和代码段

    e) nextpclogic模块——计算下一个PC

    f) control模块——控制regfile、IMem、DMem、nextpclogic和alu

    g) top模块——实例化前几个模块,连接各个信号

  2. alu模块使用case语句判断8种操作类型。

  3. regfile模块用组合逻辑读,时序逻辑写。

  4. IMem和DMem是异步读,同步写,且由指定coe文件初始化,coe文件的内容是16进制文本,由Mars编译一个汇编代码生成。

  5. nextpclogic模块通过组合逻辑计算出nextPC的值。

  6. control模块根据输入的操作符Op对各控制变量进行赋值,根据ALUOp对ALUControl进行赋值。

  7. top模块实例化前几个模块,连接各个信号。

  8. bgtz的实现:bgtz是伪指令(类似地有la和li),不是MIPS指令集的指令,编译时会进行处理,转换为几条指令实现。

这里我用以下三条指令

 slt $t6,$zero,$t1 # if $t1 > 0, that $t6 = 1, else $t6 = 0

 addi $t7,$zero,1 # set $t7 = 1

 beq $t6,$t7,loop # jump if $t6 = 1, that is to say, $t1 > 0

实现

bgtz $t1, loop # repeat if not finished yet.
  1. 完整的数据通路

10、分析结果

.data

fibs: .word 0 : 20 # "array" of 20 words to contain fib values

size: .word 20 # size of "array"

temp: .word 3  3

.text

   la $t0, fibs # load address of array

   la $t5, size # load address of size variable

   lw $t5, 0($t5) # load array size

   la $t3, temp # load

   lw $t3, 0($t3)

   la $t4, temp

   lw $t4, 4($t4)

   sw $t3, 0($t0) # F[0] = $t3

   sw $t4, 4($t0) # F[1] = $t4

   addi $t1, $t5,  -2 # Counter for loop, will execute (size-2) times

loop: lw $t3, 0($t0) # Get value from array F[n]

   lw $t4, 4($t0) # Get value from array F[n+1]

   add $t2, $t3, $t4 # $t2 = F[n] + F[n+1]

   sw $t2, 8($t0) # Store F[n+2] = F[n] + F[n+1] in array

   addi $t0, $t0,  4 # increment address of Fib. number source

   addi $t1, $t1,  -1 # decrement loop counter

   slt $t6,$zero,$t1 # if $t1 > 0, that $t6 = 1, else $t6 = 0

   addi $t7,$zero,1 # set $t7 = 1

   beq $t6,$t7,loop # jump if $t6 = 1, that is to say, $t1 > 0

out: 

   j out

实验结果

    MEMORY_INITIALIZATION_RADIX=16;
    
    MEMORY_INITIALIZATION_VECTOR=
    
    20080000,
    
    200d0050,
    
    8dad0000,
    
    200b0054,
    
    8d6b0000,
    
    200c0054,
    
    8d8c0004,
    
    ad0b0000,
    
    ad0c0004,
    
    21a9fffe,
    
    8d0b0000,
    
    8d0c0004,
    
    016c5020,
    
    ad0a0008,
    
    21080004,
    
    2129ffff,
    
    1d20fff9,
    
    08000011,

DMem内容为

    MEMORY_INITIALIZATION_RADIX=16;
    
    MEMORY_INITIALIZATION_VECTOR=
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000000
    
    00000014
    
    00000003
    
    00000003

仿真得DMem和reg数据为

DMem

Regfile

可见运行结果符合分析。

附录: