News for hackers. Stuff that matters.
Re:Implement an emulator for a fantasy CPU in JavaScript by thequux on Sunday August 23, 2020 @07:46PM (#24256275)
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.

There are no comments on this comment yet.