Reputation: 6215
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";
Heres my failed attempt:
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
EDIT: 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.
Upvotes: 3
Views: 37438
Reputation: 2143
static char hexdigits[16] = "0123456789ABCDEF";
Can be translated into:
.data
hexdigits: .byte '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
Or
.data
hexdigits: .ascii "0123456789ABCDEF"
We can access the elements using
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
Upvotes: 14