1
votes

450A 480C 0258 A200 B000 DATA 000A 0005 END

for example, I have a string with characters:" 450A/n480C/n.." for each memory address(one byte), how can I store the string byte by byte(each line is four bytes) into memory address. For example: I have address: 0x00, 0x01, 0x02, 0x03, how should I store 450A/n480C to memory? like 0x00-4, 0x01-5, I'm new to MIPS, anyone can give me some help?

1
Look up the sb instruction in MIPS32™ Architecture For Programmers Volume II: The MIPS32™ Instruction SetMichael

1 Answers

0
votes

Well each line is 4 bytes, so each char is 1 byte...

You can use the 'sb' = store byte instruction to do so, with a loop... if in $s0 you want to save each char and your string "45....." is in $t0 you can do this:

(I've made you this program... this could be done with a function though)

    .data

save:      .space 55    # this is where you are going to save byte by byte your string
string:    .asciiz "450A/n480C/n.."

    .globl __start
    .text

__start:


    la $s0, save    # we are just loading adresses
    la $t0, string

    Loop:

        lb $t1, 0($t0)    # 'load byte' of your string... in other words take the 1st
                          # byte of your string and put it in $t1

        sb $t1, 0($s0)    # storing the 1st byte of the string in the 1st adress of $s0

        addi $s0 $s0, 1   # we have to increment the adress, so the next byte 
                          # of $t0 will be stored in the next adress of $s0

        addi $t0, $t0, 1   # we also have to move the pointer in the string, so we can take 
                          # the next character

        beq $t1, $zero, End # every string ends in '\0' (null) character, which is zero
                           # so 'beq' means that if the string is finished and
                           # the char we have is '\0', we will go to End

        j Loop    # if its not the end of the string; we are going to loop again 
                           # and do the same steps until the string is finished

    End:

    li $v0, 10
    syscall             # exit and finish program