0

I am starting to learn Assembler. Could anyone please help: how may this code look like in Assebler:

while (j<16)
do {
    a=A[j];
    b=a+B[a];
} 

I am a bit confused how j<16 should be written in the conditional statement for while loop.

susenj
  • 342
  • 1
  • 4
  • 12
Lina
  • 9
  • 2
  • If this is supposed to be C-like syntax, the `do` should be removed. `do{}while()` loops have the condition at the bottom of the loop (like normal for asm: [Why are loops always compiled into "do...while" style (tail jump)?](//stackoverflow.com/q/47783926)). – Peter Cordes Jul 27 '19 at 17:47
  • 1
    Possible duplicate of [While, Do While, For loops in Assembly Language (emu8086)](https://stackoverflow.com/q/28665528/5221149) – Andreas Jul 27 '19 at 17:47
  • 2
    This loop is weird because `j` isn't modified anywhere inside the loop so it either runs zero times or infinite. You just need an `if` to skip over a loop that uses `j` at the bottom. Of course it has no side-effects other than reading memory, and it's always the same elements read every iteration. If faulting is a visible side-effect that you need to preserve in asm, then you would at least need address-calculation and loads inside a loop that uses `j` to loop forever. – Peter Cordes Jul 27 '19 at 17:49
  • @Andreas: nope, MIPS branching is very different from x86; MIPS doesn't have a FLAGS register so you have to compare into an integer register with `slt $t0, $t1, 16` or something, and then branch on that with an instruction like `bne $t0, $zero, target` – Peter Cordes Jul 27 '19 at 17:51

0 Answers0