0

I have an assignment in which I am asked to change each lowercase letter of a given string to an uppercase letter.

My problem is that the professor has asked us to input the string into the text segment and not the data segment.

I have tried using lw and sw but it doesn't work. Is there any other way? (My program works when the string is in the data segment)

This is what I have so far:

        .data    
str:    .space 100

textlow:    .asciiz "This is a sample text!"

        .text

main:
        li $t0, 0

loop:

lb $t1, textlow($t0)    
        beq $t1, 0, exit       
        blt $t1, 'a', diff  
        bgt $t1, 'z', diff

sub $t1, $t1, 32  
        sb $t1, textlow($t0)  


diff: 
        addi $t0, $t0, 1

j loop

exit:
        li $v0, 10      
        syscall
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
stvllar
  • 1
  • 3
  • What errors do you get, exactly? Is it an alignment error for the code? (MIPS instructions have to be aligned on a 4B boundary). If so, put `.align 4` after the string literal. https://stackoverflow.com/questions/47482102/error-5-unaligned-word-memory-reference – Peter Cordes Nov 25 '17 at 13:32
  • Typically, the text segment is read-only. Trying to write to a string in the text segment causes your program to crash. – fuz Nov 25 '17 at 13:52
  • Do you want to put the `textlow` string constant into the text segment, or do you also want to put `str: .space 100` in the text segment? If the latter, you might have to make an `mprotect` system call, unless your emulator has memory protection disabled. – Peter Cordes Nov 25 '17 at 14:03
  • I want to put the textlow string into the text segment. My professor is also prone to 'testing' us so I've begun to think that it's a trick question because it really doesn't make sense – stvllar Nov 25 '17 at 15:00
  • I believe you are supposed to produce the output in `str`. So yeah, you can put `textlow` into `.text` because it's gonna be read only. – Jester Nov 25 '17 at 15:25
  • Could you give me a code example of that? – stvllar Nov 25 '17 at 16:26
  • Don't `sb $t1, textlow($t0)`, rather, `sb $t1, str($t0)` – Jester Nov 25 '17 at 16:55

1 Answers1

0

use smc option.

https://courses.missouristate.edu/KenVollmar/MARS/Help/MarsHelpCommand.html

example:

java Mars4_5.jar smc mips1.asm
JaeIL Ryu
  • 159
  • 10