CodeKingPlusPlus
CodeKingPlusPlus

Reputation: 16081

Mips 32 store sequential array to memory

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?

Upvotes: 0

Views: 450

Answers (1)

Jester
Jester

Reputation: 58762

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.

Upvotes: 1

Related Questions