how to save on $sp the strings

This topic contains 3 replies, has 3 voices, and was last updated by  ChrisImgtec 3 years, 5 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #31666

    I have to sort n strings, but I need to save then on memory.

    I make an example with 2 strings. But if I insert. First and after second..
    It just print second twice.

    .data

    string1: .space 10 #String1 de tamanho = 10

    .text

    .globl teste1

    teste1:

    addi $sp, $sp, -8 #carrega 2 posições na memoria

    li $v0, 8 #lê um inteiro em $v0
    la $a0, string1 #string1 aponta para $a0
    addi $a1,$zero,10 #define $a1 com tamanho 10
    syscall #executa chamada do SO

    sw $a0, -8($sp)

    li $v0, 8 #lê um inteiro em $v0
    la $a0, string1 #string1 aponta para $a0
    addi $a1,$zero,10 #define $a1 com tamanho 10
    syscall #executa chamada do SO

    sw $a0, -4($sp)

    lw $a0, -8($sp)

    addi $v0, $zero, 4 #carrega o valor 4 em $v0
    #la $a0, opcao1 #carrega opcao1 no registrador $a0
    syscall #Dado $v0 == 0, o mips imprime o valor de $a0

    lw $a0, -4($sp)
    addi $v0, $zero, 4 #carrega o valor 4 em $v0
    #la $a0, opcao1 #carrega opcao1 no registrador $a0
    syscall #Dado $v0 == 0, o mips imprime o valor de $a0

    addi $sp, $sp, 8 #carrega 2 posições na memoria

    end: li $v0, 10 #código para encerrar o programa
    syscall #executa a chamada do SO para encerrasr

    #38605

    Sean
    Moderator

    What platform are you using? Have you tried using a debugger such as GDB to step through?

    Regards,

    Sean

    #38606

    I am using MARS in Windows..

    This code I am using ho learn as to walk throught the memory address on mips.

    the problem is..
    I read and record in -8($sp) = test_1
    I read and record in -4($sp) = test_2

    but the problem is.. I try to print the first string before of second..
    -8($sp)
    but it just print the second -4($sp), even I had load the -8 first in … lw $a1, -8($sp)

    what am I doing wrong?

    #38607

    ChrisImgtec
    Moderator

    lw $a1, -8($sp) This is wrong! you are reading from the calling functions stack not yours
    should be lw $a1, 8($sp)

    The same holds true for the sw (the offsets should be positive)

Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.