2

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

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

编辑:如果有人可以提供一个示例如何打印出这些项目之一,那将非常有帮助(您可以根据需要修改我拥有的代码)。因为我刚刚收到内存地址错误。

4

1 回答 1

14
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]

您可以使用系统调用打印元素(如果您的模拟器支持它。大多数都支持)

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
于 2012-04-05T05:24:40.197 回答