MIPS 程序集:如何在 .data 部分声明整数值? [英] MIPS assembly: how to declare integer values in the .data section?

查看:44
本文介绍了MIPS 程序集:如何在 .data 部分声明整数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 MARS 模拟器尝试使用 MIPS 汇编语言.

I'm trying to get my feet wet with MIPS assembly language using the MARS simulator.

我现在的主要问题是如何初始化一组内存位置,以便以后可以通过汇编语言指令访问它们?

My main problem now is how do I initialize a set of memory locations so that I can access them later via assembly language instructions?

例如,我想用值 0x99、0x87、0x23、0x45 初始化地址 0x1001000 - 0x10001003.我认为这可以在我的汇编程序的数据声明 (.data) 部分完成,但我不确定语法.这可能吗?

For example, I want to initialize addresses 0x1001000 - 0x10001003 with the values 0x99, 0x87, 0x23, 0x45. I think this can be done in the data declaration (.data) section of my assembly program but I'm not sure of the syntax. Is this possible?

或者,在 .data 部分,我如何指定将整数值存储在某个内存位置(我不在乎在哪里,但我只想在某处引用它们).因此,我正在寻找等效于int x = 20, y=30, z=90;"的 C我知道如何使用 MIPS 指令做到这一点,但是否可以在 MIPS 汇编程序的 .data 部分声明类似的内容?

Alternatively, in the .data section, how do I specify storing the integer values in some memory location (I don't care where, but I just want to reference them somewhere). So I'm looking for the C equivalent of "int x = 20, y=30, z=90;" I know how to do that using MIPS instructions but is it possible to declare something like that in the .data section of a MIPS assembly program?

推荐答案

您通常不会初始化特定的内存位置;每个部分(包括 .data)在链接时定位,然后解析重定位

You don't usually initialize specific memory locations; each section (including .data) is positioned at link time, and relocations are resolved then

要对数据条目进行重定位,请选择一个名称并将 name: 放在其前面,以便以后可以按名称引用它.您可以使用 .size value 指定数据块.例如:

To make a relocation on a data entry, you choose a name and put name: before it, so you can refer to it by name later. You specify a data block using .size value. For example:

.data
    x: .word 20
    y: .word 30
    z: .word 90

然后你可以在你的程序集中使用标签:

Then you can use the labels in your assembly:

.text
    lw $t0, x

这篇关于MIPS 程序集:如何在 .data 部分声明整数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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