院
系:
计算机科学学院
专
年
业: 计算机科学与技术 级:
课程名称:
计算机系统结构
学
姓
号:
名:
指导教师:
年
月
日
1
年级
班级
学号
专业
班级
姓名
题目
名称
用 DLX 汇编语言编写矩阵乘程序 Matrix.s(元素数据为浮点数)
题目
内容
对矩阵乘程序 Matrix.s 做如下分析:1.观察程序中出现的数据相关、控制相关和结构相关现象, 并指出程序中出现上述现象的指令;2.指出转移指令在转移成功和不成功时的流水线开销;3.分别 在使用定向技术和不使用定向技术的两种情况下,输入同样的数据,利用 Statistics 窗口中的统计 数字(总的周期数和暂停数),计算定向技术带来的加速比。4.通过 DLX 模拟器中的 configuration 窗口,将浮点运算的延迟改为 8 个时钟周期,重复观察并回答上述的 1,2,3 的问题。
实
验
结
果
与
分
析
实验结果截图如下:
1.程序最后的运行结果截图如下:
此为两个 2 阶矩阵的相乘,第一个矩阵的数据依次是 1,2,3,4;第二个矩阵的数据依次是 5,6,7,8,最 后的运行结果依次是 19,22,43,50。
Register 图如下:
各寄存器的参数值如上。
(写不完时,可另加附页。)
2
3.流水线图某一流程截图如下:
4.时钟周期表最后如下:
3
程序
程
序
代
码
.data
;*** Prompts for input
;输入提示部分
dat1: .space 64
dat2: .space 64
result: .space 64
Prompt1: .asciiz "Input the martrixA line:"
Prompt2: .asciiz "Input the martrixA column and the martrixB line: " Prompt3: .asciiz "Input the martrixB column:"
Prompt4: .asciiz "Input the martrixA's number:"
Prompt5: .asciiz "Input the martrixB's number:"
Prompt6: .asciiz " This is my program !"
;*** Data for printf-Trap
;输出数据设置部分
PrintfFormat: .asciiz "%d "
.align 2
PrintfPar: .word PrintfFormat
PrintfValue: .space 4
PrintfFormat1: .asciiz "\n "
.align 2
PrintfPar1: .word PrintfFormat1
PrintfValue1: .space 4
PrintfFormat2: .asciiz "Output the martrixA:\n "
.align 2
PrintfPar2: .word PrintfFormat2
PrintfValue2: .space 4
PrintfFormat3: .asciiz "Output the martrixB:\n "
.align 2
PrintfPar3: .word PrintfFormat3
PrintfValue3: .space 4
PrintfFormat4: .asciiz "Output the martrixC:\n "
.align 2
PrintfPar4: .word PrintfFormat4
PrintfValue4: .space 4
.text
.global main
main:
addi r1,r0,Prompt1
jal InputUnsigned
movi2fp f1,r1 ;矩阵 A 的行数
addi r1,r0,Prompt2
jal InputUnsigned
4
movi2fp f2,r1 ;矩阵 A 的列数,矩阵 B 的行数
addi r1,r0,Prompt3
jal InputUnsigned
movi2fp f3,r1 ;矩阵 B 的列数
movfp2i r8,f1
movfp2i r6,f2
multu r4,r6,r8 ;总的矩阵 A 的元素个数 r4
addi r2,r10,dat1 ;指向 A 的首地址
loop1:
add r1,r0,Prompt4 ;分别读入矩阵 A 的元素值
jal InputUnsigned
sb 0(r2),r1 ;储存字节,读入元素
addi r2,r2,1 ;元素个数加一
sub r4,r4,1 ;总的矩阵元素个数 r4 减一
bnez r4,loop1 ;r4 不为