The regular JMP and conditional Jcc jump instructions change the course of
working code, the latter based on the runtime status of certain bits in the RFLAGS register. The x86 and x86-64 processors implement pipelining of
instructions where they prefetch a certain number of instructions and evaluate
them before time. The number of instructions prefetched is dependent on the
prefetch input queue (PIQ).
Logical shifts are operations in which the bits of a register or memory location
are moved to the right or left by a certain number or a value in the CL
register. They are also a very quick way to multiply or divide by 2 or powers of
2 as it involves just a shift of bits. There are 4 shift bit instructions, 4
rotate bit instructions and 2 double precision shift bit instructions for
general purpose registers.
Below is a code snippet that prints a list of prime numbers, one on each line,
based on a limit entered by the user. It uses both while loops and conditional
branch if - else statements. We shall convert this to an assembly program to
demonstrate implementation of these control flow structures in x86-64 assembly.
In the Hello World sample
program we had used the instructions REPNZ and SCASB to calculate the length of the string being printed at runtime. In this program
we use NASM’sequ directive to calculate the length during assembly time as
opposed to at runtime. The variable promptlen gives an example.