4 ms·
It depends on the CPU, though in most CPUs, the comparison is a separate instruction from the branch. For example, on x86, CMP RAX, RBX JL label woul
by thequux 6y ago
It depends on the CPU, though in most CPUs, the comparison is a separate instruction from the branch. For example, on x86,
CMP RAX, RBX
JL label
would jump if RAX < RBX.
Similarly, on ARM:
CMP r1, r2
BLT label /* jump if r1<r2 */
Some processors do have a conditional jump that takes the registers to compare though, such as the PDP-10's bewildering array of skip instructions:
CAML A, B
ADDI C, 100 ; This instruction will be skipped if A < B
Finally, it's also fairly common to have branch instructions that compare against 0, such as PDP-10:
JUMPL A, label ; jump if A<0
That said, off the top of my head, I don't know of any real processors with something equivalent to the fantasy CPU's JL, which combines a comparison between two registers with a jump to an arbitrary immediate.