What is Condition code?
Flags such as zero, negative, carry and overflow that record the outcome of a compare or arithmetic operation. Conditional branches in x86 and Arm mainly test them; RISC-V has none.
Japanese name: 条件コード
Flags such as zero, negative, carry and overflow that record the outcome of a compare or arithmetic operation. Conditional branches in x86 and Arm mainly test them; RISC-V has none.
Japanese name: 条件コード
The processor has a dedicated register that collects the flags. The flags represent, one bit each, that a result was zero, that it was negative, that a carry occurred, that an overflow occurred and so on. Arithmetic instructions update them as a by-product of computing. A compare instruction performs a subtraction, discards the result and leaves only the flags. A conditional branch instruction looks at a combination of flags to decide whether to branch. Different flags are examined for comparing signed numbers and for comparing unsigned numbers.
The advantage is that comparison and branching can be separate instructions. Because there are instructions that carry the carry flag into the next addition, arithmetic on numbers wider than a register is easy to write. The disadvantage is that the flags are hidden inputs and outputs not written in the instruction. In an ISA such as x86, where almost every arithmetic instruction updates the flags, this creates extra dependencies between instructions. A processor that executes instructions out of order needs machinery to track, for the flags as well, which instruction wrote each value.
RISC-V has no condition codes. A single instruction compares two registers and branches. There are also instructions that place the result of a comparison in an ordinary register as 0 or 1. A carry is detected by comparing whether the sum is smaller than one of the original numbers. Arithmetic on large numbers takes more instructions, but the hidden dependencies disappear and the processor is simpler to build. x86 and Arm processors also merge a compare and the conditional branch that follows it into one operation internally.
Answer: C. In RISC-V the branch compares two registers directly; in x86 the branch tests flags set by a compare instruction
In x86, "cmp eax, ebx" compares and sets flags (condition codes) such as zero and carry, and the following "je" or "jl" branches on those flags. RISC-V has no flags; the branch itself compares two registers, as in "beq a0, a1, L" or "blt a0, a1, L". With no implicit state like flags, dependences are easier to track when instructions are reordered or executed in parallel.
It depends on the ISA and the instruction. In x86 many arithmetic and logical instructions change the flags, but instructions that merely move a value do not. In Arm, many arithmetic instructions let the program choose whether the flags are changed.
Yes. Arm has instructions that test directly whether a register is zero and branch.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.