So here's the question that I've been thinking over for a few hours:
MIPS to C. Assume $s3 = i, $s4 = j, $s5 = @A. Below is the MIPS code:
Loop: addi $s4,$s4,1 # j = j + 1?
add $t1,$s3,$s3 # $t1 = 2 * i
add $t1,$t1,$t1 # $t1 = 4 * i
add $t1,$t1,$s5 # $t1 = @ A
lw $t0,0($t1) # $t0 = A
addi $s3,$s3,4 # i = i + 1?
slti $t1,$t0,10 # $t1 = $t0 < 10?
beq $t0,$0, Loop # goto Loop if >=
slti $t1,$t0, 0 # $t1 = $t0 < 0?
bne $t0,$0, Loop # goto Loop if <
Below is part of the corresponding C code:
do j = j + 1
while (______);
What C code properly fills in the blank in loop on right?
A: [i++] >= 10?
B: A[i++] >= 10 | A < 0?
C: A[i++] >= 10 & A < 0?
D: A[i++] >= 10 || A < 0?
E: A[i++] >= 10 && A < 0?
F: None of the above
I am in my first couple of weeks in a computer architecture class so I am reletively new at MIPS. But this little bit of code that I've bolded seems incorrect. If you use the slti instruction to set $t1 to either a 1 or 0 based off of $t0's value wouldn't you then use the beq instruction based off of $t1 not $t0 like the code is doing? It seems pointless to set $t1 if you aren't going to use it for something. Is there some sort of technique being applied here that I'm not seeing?