Как загрузить строку (построчно) в MIPS в память?

#mips

#mips

Вопрос:

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

например, у меня есть строка с символами: «450A / n480C / n ..» для каждого адреса памяти (один байт), как я могу сохранить строку байт за байтом (каждая строка по четыре байта) в адрес памяти. Например: у меня есть адрес: 0x00, 0x01, 0x02, 0x03, как мне сохранить 450A / n480C в памяти? например, 0x00-4, 0x01-5, я новичок в MIPS, кто-нибудь может мне помочь?

Комментарии:

1. Найдите sb инструкцию в MIPS32 ™ Архитектура для программистов Том II: Набор инструкций MIPS32 ™

Ответ №1:

Ну, каждая строка составляет 4 байта, поэтому каждый символ равен 1 байту…

Вы можете использовать для этого инструкцию ‘sb’ = сохранить байт, с циклом … если в $ s0 вы хотите сохранить каждый символ, а ваша строка «45 …..» находится в $ t0, вы можете сделать это:

(Я сделал вам эту программу … хотя это можно сделать с помощью функции)

     .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 '' (null) character, which is zero
                           # so 'beq' means that if the string is finished and
                           # the char we have is '', 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