2.3.2 测试程序编译流程

1. 编写MIPS架构的汇编文件

文件中包含需要测试的指令

MIPS程序的基本模板如下:

# Comment giving name of program and description of function
# 说明下程序的目的和作用(其实和高级语言都差不多了)
# Template.s
#Bare-bones outline of MIPS assembly language program


           .data       # variable declarations follow this line
                    # 数据变量声明
                       # ...

           .text       # instructions follow this line    
               # 代码段部分                                                            
main:                  # indicates start of code (first instruction to execute)
                       # 主程序
                       # ...

# End of program, leave a blank line afterwards to make SPIM happy

【十分钟教会你汇编】MIPS编程入门(妈妈说标题要高大上,才会有人看>_<!) https://www.cnblogs.com/thoupin/p/4018455.htm

2. 将汇编程序进行编译链接

关于编译相关知识自行学习,可参考博客https://blog.csdn.net/leishangwen/article/details/38228305

2.1 GNU工具链的安装

下载mips-sde-elf-i686-pc-linux-gnu.tar.tar(http://os.cs.tsinghua.edu.cn/oscourse/project/LoongsonCsprj2017/bit/cpu附件),将安装文件复制到Ubuntu的/opt目录下,打开Ubuntu的终端,使用如下命令解压缩。

cd /opt
tar vfxj mips-sde-elf-i686-pc-linux-gnu.tar.tar

然后打开用户主目录Home文件夹,在窗口菜单栏中选择View->Show Hidden Files,以显示所有文件,这样可以找到一个隐藏文件.bashrc,在此文件的最后加入 PATH 的设置,如下。

export PATH=”$PATH:/opt/mips-4.3/bin”

重新启动Ubuntu系统。

重启后,打开终端,在其中输入mips-sde-elf-,然后按两次Tab键,会列出刚刚安装的,针对MIPS平台的所有编译工具,表示GNU工具链安装成功。

2.2 使用GNU工具进行编译链接

配置交叉编译环境(具体方法见3.3交叉编译环境'的配置)

下载附件coe_file(http://os.cs.tsinghua.edu.cn/oscourse/project/LoongsonCsprj2019),里面包括了链接器脚本、使用mipsel-linux-gnu-交叉编译环境的makefile和将bin文件转换为coe格式的python程序。

可以直接将新编写的程序直接覆盖inst_rom.S文件的内容,然后输入make命令即可编译生成coe文件。

也可以修改makefile,将脚本中的文件名修改为自己的文件名

Last updated