title: MIPS Error : Cannot write directly to text segment!0x00500000
body: <p>I'm trying to do a mips interactive exercise (BubbleSort). I have to read 20 integers from the user and store them into an array,then sort the array with the method of BUBBLESORT.
  I have a problem with storing the integers into the array.
  Here is a bit of my code:</p>
  
  <p>.data</p>
  
  <pre><code>prompt:.asciiz "enter the integer one by one \n "
  </code></pre>
  
  <p>.text</p>
  
  <pre><code>        addi $sp,$sp,-88               #space on the stack
      lui  $s0, 0x0040                   #s0=adress of array
      sw   $s0,-84($sp)                  #store s0 on the stack
      sw   $ra,-80($sp)                  #store ra on the stack
  </code></pre>
  
  <p>readInt:    </p>
  
  <pre><code>    #prompt the user
      li $v0, 4                          #op code to print string
      la $a0, prompt
      syscall
  
      #get the array's integer
      addi $t0,$zero,0                    #t0=compteur
      addi $a1,$zero,80                   #a1=size of array*4 (20 int)
      move $a0,$s0                        #a0= adress of array 
  </code></pre>
  
  <p>loop:      </p>
  
  <pre><code>beq  $t0,$a1,BubbleSort             #if t0 = size of array ==&gt;BubbleSort
      li   $v0,5                          #opcode to read int
      syscall 
    **sw  $v0,0($a0)**                    ERROR HERE !!!! :(
      addi $a0,$a0,4                      #increment a0  (next int)   
      addi $t0,$t0,4                      #incrementer t0  (counter +=4)
      j loop
  </code></pre>