Question: Hi, I am writing code that implements the c standard function memset in mips/spim assembly language and that works in QTspim. However, in the code

Hi, I am writing code that implements the c standard function memset in mips/spim assembly language and that works in QTspim. However, in the code I've written when I compile it I am getting an error saying memory address out of bounds. How do I fix this?

.data # The data segment.

welc4: .asciiz "Now, memset. Should print 13 dots: "

hello: .asciiz "Hello, world."

alice: .asciiz "alice"

bob: .asciiz "bob"

crlf: .asciiz " "

dot: .byte 46

stch: .byte 'l'

buf: .space 128

.text # The code segment.

main:

# --- memset ---

li $v0, 4 # System call to print.

la $a0, welc4 # Load up our message.

syscall # Fire the system call.

la $a0, buf

lb $a1, dot

move $a2, $s0

jal memset

move $a0, $v0 # Load up the returned message.

li $v0, 4 # System call to print.

syscall # Fire the system call.

li $v0, 4 # System call to print.

la $a0, crlf # Load up our message.

syscall # Fire the system call.

# --- finished ---

li $v0, 10 # System call to exit.

syscall # Fire the system call.

# --- memset ---

memset:

addi $sp, $sp, -12

sw $s0, 0($sp)

add $s0, $zero, $zero

memset_L1:

bge $s0, $a2, memset_L2

add $t1, $s0, $a0

sb $a1, 0($t1)

addi $s0, $s0, 1

j memset_L1

memset_L2:

lw $s0, 0($sp)

addi $sp, $sp, 12

jr $ra

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!