I am writing an assembler in C for MIPS assembly (so it converts MIPS assembly to machine code).
Now MIPS has three different instructions: R-Type, I-Type and J-Type. However, in the .data. section, we might have something like message: .asciiz "hello world". In this case, how would we convert an ASCII string into machine code for MIPS?
Thanks
ASCII text is not converted to machine code. It is stored via the format found on Wikipedia.
MIPS uses this format to store ASCII strings. As for
.asciizin particular, it is the string plus the NUL character. So, according to the sheet, A is41in hexadecimal, which is just0100 0001in binary. But don’t forget the NUL character, so:0100 0001 0000.When storing the string, I’d take Mars MIPS simulator‘s idea and just start the memory section at a known address in memory and make any references to the label
messageset to that location in memory.Please note that everything in the data section is neither R-type, I-type, nor J-type. It is just raw data.