I've been trying to figure out this project for my class where we take daBeef
and daGreeting
and save their reverses in buffer1
and buffer2
. So buffer1
would have 0xcafebeef
and buffer2
would have "etov" (I'm pretty sure this is what the assignment is asking at least). But like the title says I really have no clue where to begin with this and nothing the teacher has posted really helps with figuring this out. I have emailed him about it but he's notoriously slow at answering and tomorrow is Sunday and the project is due Monday (11-9-20) at 11:59 pm. So I figured it would be best to ask for help here in case he doesn't respond to my email in time or his response simply doesn't help.
Here is the code I have so far, again, I'm super new to mips and I don't really understand it so sorry if there are a bunch of glaring mistakes.
.data # Do not change this data segment
daBeef: .word 0xefbefeca
someSpace: .space 4
daGreeting: .byte 'v','o','t', 'e'
daGarbage: .byte 'D':100 # same as .byte 0x44:100
.data 0x100100a0 #starts next series of bytes at this address
buffer1: .byte 'a':4 # where your first answer will reside
buffer2: .byte 'b':4 # where your second answer will reside
.text
#read value from memory in daBeef and daGreeting
#write the value to the required memory space buffer1 and buffer2 in REVERSE ORDER
main:
lb $a0 daGreeting #save array address
lw $a1 buffer2 #save buffer address
jal reverseByte #call the 'reverse' function
la $a0 daBeef
la $a1 buffer1
jal reverseWord
#end of main
li $v0, 10
syscall
reverseByte:
#a0 = daGreeting address
#a1 = buffer2 address
srl $t0, $a0, 16 #t0 = end of daGreeting (16 bits right)
addi $t2, $zero, 3 #t2 = i = 3
loop:
beqz $t2, exit #repeat until i = 0
sb $a1, ($t0) #save daGreeting[j] to buffer2[i]
addiu $t0, $t0, -4 #daGreeting moves back 1 unit
addiu $a1, $a1, 4 #buffer2 moves forward 1 unit
addi $t2, $t2, -1 #i--
j loop
exit:
jr $ra
reverseWord:
#a0 = daBeef
#a1 = buffer1 address
srl $t0, $a0, 16 #t0 = end of daBeef (16 bits right)
addi $t2, $zero, 3 #t2 = i = 3
loop1:
beqz $t2, exit1 #repeat until i = 0
sw $a1, ($t0) #save daBeef[j] to buffer1[i]
addiu $t0, $t0, -4 #daBeef moves back 1 unit
addiu $a1, $a1, 4 #buffer1 moves forward 1 unit
addi $t2, $t2, -1 #i--
j loop1
exit1:
jr $ra
When I run this I get:
Error in C:\Users\kerfu\Desktop\mips\mips2.asm line 38: Runtime exception at 0x0040003c: address out of range 0x00000000
Line 38 is this one btw: sb $a1, ($t0) #save daGreeting[j] to buffer2[i]
Any help is appreciated, even if it's just pointing out that the logic in my comments is wrong. Also, I can't edit anything before .text
as a part of the project instructions.
User contributions licensed under CC BY-SA 3.0