MIPS中的char数组 [英] char array in MIPS

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

问题描述

我将如何创建一个字符数组并在MIPS中访问这些字符?我正在做一个项目,部分原因就是这样做.我了解如何使用整数,并且无法在网上找到有关如何处理字符的任何参考,特别是我试图移植...

How would I create a char array and access those chars in MIPS? Im doing a project and part of it is to do this. I understand how to with integers and cant find any reference online on how to deal with just chars, specifically im trying to port...

static char   hexdigits[16] = "0123456789ABCDEF";

这是我失败的尝试:

hexarray: .word '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' #declare memory space for our hex array

如果有人可以提供示例如何打印出这些项目之一,则将非常有帮助(您可以将代码修改为所需的任何内容).因为我只是遇到内存地址错误.

if someone could provide an example how to print out one of these items it would be very helpful (you can modify the code i have to whatever you wish). as I im just getting a memory address error.

推荐答案

static char   hexdigits[16] = "0123456789ABCDEF";

可以翻译为:

.data
hexdigits: .byte '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'

.data
hexdigits: .ascii "0123456789ABCDEF"

我们可以使用

la    $t0, hexdigits
lb    $t1, 0($t0)        # $t1 = hexdigits[0]
lb    $t2, 1($t0)        # $t2 = hexdigits[1]

您可以使用系统调用来打印该元素(如果您的模拟器支持该元素.大多数情况下可以这样做)

You can print the element using a system call (if your simulator support it. Most do)

la    $t0, hexdigits          # address of the first element
lb    $a0, 10($t0)            # hexdigits[10] (which is 'A')
li    $v0, 11                 # I will assume syscall 11 is printchar (most simulators support it)
syscall                       # issue a system call

这篇关于MIPS中的char数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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