0

I am trying to store the numbers 0 to 10 sequentially in memory using mips32. Here is my code:

addi $s2, $zero, 10
addi $s1, $zero, 0
addi $t0, $zero, 0
addi $s6, $zero, 10
L1: 
  beq $s1, $s2, exit   
  sll $t0, $s1, 2           #multiply by the size of a word to get the cur address of $s6
  sw $t0, 0($s6)            
  addi $s1, $s1, 1
  j L1

exit:

I got an error with sw $t0, 0($s6) What is wrong with storing this at the beginning of memory?

1 Answer 1

1

Unless you are running on bare metal, the OS (or the emulator) is providing virtual memory for your program. You don't typically get the whole address range assigned to your program, you need to ask the OS for blocks of memory - either via system calls or via the binary format itself, for example by reserving space in the .bss or the .data section.

PS.: The available address range rarely includes the first page, so that null pointers can be caught easily.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.