Hi guys,

Im new to MIPS and have no idea how to do this.
Just need to convert an integer to a character.


6 Years
Discussion Span
Last Post by leatheag

So what's your question?

How to learn MIPS?

> Just need to convert an integer to a character.
Is that it?
Or will you 'just' need to do another MIPS assignment next week as well?


No No, im in a computer arch class right now and have a pretty basic program all done except he wants us to convert int to chars.
example. 1 to '1' 2 to '2' etc to put in a char array. I know char takes a byte of data each but I just don't know how to convert. Any help would be appreciated


yes thanks, the hex values are the same. So what instruction do I use to change that byte in memory to the hex value?

And I have this in a loop like:

for(int i = 0; i<10; i++){
         char[i] = i;

I have the loop part done already but do I just increment the location in memory of the char array by one byte every time to get the next spot?

Thanks again

Edited by mike_2000_17: Fixed formatting


so this is what I did, don't know if its right though (ill just show the char and int i parts)

charArray: .space 10 # Array with 10 bytes

la $s6, charArray # sets the array to $s6
addi $s4, $s4, 1 # i++
addi $s6, $s6, 1 #move array pointer
sb $s4, 0($s6) # stores i in charArray

these parts are all in and my MIPS programs runs. IN my first byte of my char array im getting 0x03020100.
Is that the same as '0' '1' '2' '3'?


jeancarlo I was looking for the MIPS way to do it, but thanks for the thought..and never mind 0x03020100 is '3' '2' '1' '0'

Thanks for your help! I look forward to being a member on this site

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.