The Labouchere system for roulette is played as follows. Write down a list of
numbers, usually 1, 2, 3, 4. Bet the sum of the first and last, i.e. 1 + 4 = 5,
on red. If you win, delete the first and last numbers from the list. If you
lose, add the amount that you last bet to the end of the list. Then use the new
list and bet the sum of the first and last numbers (if there is only one number,
bet that amount). Continue until your list becomes empty. You will see
that, if this happens, you will always win the sum 1 + 2 + 3 + 4 = 10, of the
original list. The below program simulates this system. Execute the
program, and see if you always win!
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.