开发者

Top testing loop that initializes n registers in MIPS assembly

开发者 https://www.devze.com 2023-04-06 06:55 出处:网络
I can\'t find an example of this online and I don\'t even know where to start searching. I\'m pretty new to asm and I\'m taking a MIPS course at my college. I will say this is part of a homework assig

I can't find an example of this online and I don't even know where to start searching. I'm pretty new to asm and I'm taking a MIPS course at my college. I will say this is part of a homework assignment, but this wasn't the prompt. Just something I need to implement within the larger program to make it work how开发者_运维百科 I want.

Anyway, what I am trying to do is create a top-testing loop that sets "n" registers based on the value of a separate register.

For example, if I set $t0 to 3, I want the loop to execute 3 times and prompt for input for $t1, $t2, and $t3. I know how to accomplish the input prompt, I just need help designing a loop that will accomplish this. Any tips on where to start or what operations I need to use?

This is basically what I have so far...

li $t2, 1
next1:
beq $t2, $s1, next2
    # loop code
addi $t2, $t2, 1    
j next1

next2:


There is no simple way of doing this because the destination register is typically hard-coded into the instruction encoding.

You could use the equivalent of a switch statement:

sll $a0, 2  # $a0 = 8 * $a0
# set one of $t0,$t1,...,t7 to the value of $a1 as selected by the value of $a0
b $a0(SW)
nop           # branch delay slot
DONE:
...
# switch cases start here. Each case uses 2 instructions
SW:
b DONE        # case 0
mov $t0, $a1  # branch delay slot
b DONE
mov $t1, $a1
...
b DONE
mov $t7, $a1
# end of switch cases

You could use self-modifying code instead, but that is not recommended.

0

精彩评论

暂无评论...
验证码 换一张
取 消