Search code examples
assemblycompiler-constructionmipscode-generation

How to modify .data values inside the .text segment in Mips?


I have a global variable in Mips declared at the .data segment

.data
   globalVariable:  .word  10

How can I access and modify its content inside the .text segment?


Solution

  • .data
       globalVariable:  .word  10
    
    .text
    
       #access
       lw $a0, globalVariable 
    
       #modify
       la $a0, globalVariable #get address
       li $a1, 11 #new value
       sw $a1 0($a0) #save new value
    
       lw $a2, globalVariable  #get new value