Which 8080 conditional jump instruction would the compiler generate for if (a !=b)?

1.1k Views Asked by At

Options:

  1. jz
  2. jnz
  3. jc
  4. jnc

I have the answer to this question but am struggling to understand exactly what it is asking. What does it mean and what would be a good way to brush up on this topic? Thanks.

1

There are 1 best solutions below

0
anatolyg On

I used mainly the x86 instruction set, but it seems the 8080 one is close enough, so the jump instructions are the same.

In x86 (or 8080), if your C code looks like this

if (a != b)
{
    code1
}
code2

the compiler will usually produce assembly code like this:

    cmp a, b
    jz label2

    code1

label2:

    code2

In pseudo-code

  1. Compare a and b
  2. If they were equal, go to 4 (skip code1)
  3. code1
  4. code2

An optimizing compiler can change your code layout (sometimes radically, so you will see neither cmp nor jz), but you cannot predict that, so the best you can do is assume there were no optimizations and rearrangements.