MIPS编程:加载地址 [英] MIPS Programming: Load Address

查看:759
本文介绍了MIPS编程:加载地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是个学生刚开始学MIPS为我的课程之一,我的教授是不是允许的伪指令,例如加载地址的使用量()在我们的code。我想知道的标准说明正确使用的例子看起来像一个声明的变量的地址存入了后来在code使用的寄存器的内容。

I am a student just beginning to learn MIPS for one of my courses, and my professor is not allowing the usage of pseudo-instructions such as Load Address (la) in our code. I am wondering what an example of the correct usage of standard instructions would look like to store the address of a declared variable into a register for use later in the code.

我当前已经在尝试使用此code,但我得到一个语法错误的指令。

I have currently been attempting to use this code, though I am getting a syntax error in the lui instruction.

main:
.data
    Array:
    .space 80             #Declares that Array will hold 20 integers
.text
    lui  $s0, Array       #loads most significant bits into $s0
    ori  $s0, $s0, Array  #loads least significant bits into $s0

我的问题

据我了解,这将导致数组的地址被放入 $ S0 。然而,因为这似乎不是这样的话,我想知道是否有人能帮助我什么我应该在这里做。

My Question

From what I understand, this should result in the address of Array being placed into $s0. However, as that does not seem to be the case, I'm wondering if anyone would be able to help me out on what I should be doing here.

推荐答案

您需要参考的标签在吕和ORI指令的数据部分。对于GNU汇编了以下工作(如):

You need to refer to a label in the data section in the lui and ori instructions. The following works for gnu assembler (as):

    .data
    Array:
    .space 80             #Declares that Array will hold 20 integers
...
.text
    lui $s0, %hi(Array)
    ori $s0, %lo(Array)
    lw  $s1, 0($s0)       # load 1st word of Array
...

该喜%和%LO指令告诉是怎么回事,所以它可以把机器code标签阵列的地址链接。 (注意:这个可能不适合SPIM或MARS工作)

The %hi and %lo directives tell the linker what is going on, so that it can put the address of the label "Array" in the machine code. (NOTE: this likely doesn't work for SPIM or MARS.)

请参阅此<一个href=\"http://stackoverflow.com/questions/7264532/problem-loading-memory-address-only-using-real-instructions-in-mips-asm-on-mars?rq=1\">question.

见MIPS运行是典型的书在MIPS的CPU。这本书介绍了MIPS指令集,CPU架构和如何将它们与MIPS Linux操作系统。

See MIPS Run is the canonical book on MIPS CPUs. This book explains the MIPS instruction set, CPU architecture and how they relate to MIPS Linux.

这篇关于MIPS编程:加载地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆