Jumps, loops, multiplication and bits
Comparing and jumping, signed and unsigned conditions, counting loops, MUL and DIV, printing numbers, and the logic and shift instructions.
About 10 hours of study
Learning objectives
- Write if-else and loops with CMP, jumps and LOOP
- Use MUL and DIV and print a number of any size
- Use masks and shifts to work on single bits
Lessons
- 1
Comparing and jumping
CMP and the conditional jumps that read its flags, signed and unsigned comparisons, and how if and if-else are written with labels.
- 2
Loops
Counting loops with LOOP and CX, while-loops built from CMP and jumps, guarding against CX = 0, and nested loops that save CX on the stack.
- 3
Multiplication and division Intermediate
MUL and DIV with their fixed registers (AX, and DX:AX for words), IMUL and IDIV for signed numbers, the divide overflow, and printing a number of any size by dividing by 10.
- 4
Bits: logic, shifts and rotates Intermediate
AND, OR, XOR, NOT and TEST with masks, turning letters to upper or lower case, SHL and SHR as fast multiply and divide by 2, rotates, and printing a number in binary.
Module practice
- Even or odd?Easy
- The largest digitMedium
- Sort three digitsHard
- Count downEasy
- A triangle of starsMedium
- A row of the times tableHard
- Quotient and remainderEasy
- Multiply two digitsMedium
- Add two numbersHard
- Shout itEasy
- Decimal to binaryMedium
- Bits of a key and their countHard
Module quiz
‹ Arithmetic, flags and input and outputArrays, the stack, procedures and strings ›