I have a loop in MIPS(assembly) that looks like this:
LOOP:
slt $t2, $0, $t1
beq $t2, $0, DONE
subi $t1, $t1, 1
addi $s2, $s2, 2
j LOOP
DONE:
If the value of $t1
is set to 10 in the beginning, what is the value of $s2
if $s2
is set to ZERO in the beginning?
I tried to solve the answer to the question and I'm getting 20. But, the solutions manual says its 200. Can anyone tell me what im missing out here? Won't $s2
keep getting incremented by 2 until $t1
is 0?
I agree with @Joe Farrell, this loop is basically equivalent to this C-style loop:
while(t1 > 0)
{
--t1;
s2 += 2;
}
Looks like you're working out of the book "Computer Organization and Design: The Hardware/Software Interface" I only managed to find errata sheets for 3rd and 4th editions, and I didn't see this typo addressed in either. Which edition are you using?
答案将是22。因为如果u重复循环直到t1 = -1,则s2将为22,并且当循环再次开始时,t2变为0,这导致打印DONE(循环退出的地方)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.