Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

storing a value into a data segment in MIPS

Tags:

assembly

mips

Hello I am brand new to using MIPS and I was just confused on this wording, it is probably very simple but I cannot find anything in my notes or online specifically for this question.

Here is my code:

.data
val1: .word 1
val2: .word 2
val3: .word 3

.asciiz "Daniel"
.asciiz "Enter a number "
.asciiz "\n"

.globl main
.text

main:

addi $s0, $0, 23 # initializes the register $s0 to 23

lui $a0, 0x1001
ori $a0, $a0, 19
ori $v0, $0, 4
syscall
addi $v0, $0, 5
syscall
addi $s1, $v0, 0

My Question is: how do I a. Store the value in $s1 into the data segment labeled “val1” ?? I know how to store it into another register but not a value please and thank you!

like image 214
MasterDNE Avatar asked Jun 30 '26 07:06

MasterDNE


1 Answers

la $t0, val1
sw $s1, 0($t0)

$t0 was chosen arbitrarily, it doesn't matter which register you choose to use to hold the base address of the val1 array. Also la (load address) is a pseudo operation so make sure you are able to use it first.

like image 178
Jake Mcglone Avatar answered Jul 04 '26 16:07

Jake Mcglone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!