Skip to main content
Logo image

Dive Into Systems: Exercises

Section 7.4 Conditional Control and Loops

Checkpoint 7.4.1. Condition Code Flags.

    Assume that register %rax contains the value 0xFFFFFFFF. Which condition code flags will be set to 1 after the following instruction executes?
    add $1, %rax
  • ZF
  • Correct!
  • SF
  • Incorrect.
  • CF
  • Correct!
  • OF
  • Incorrect. Consider that 0xFFFF is -1. Adding 1 to -1 should result in a 0 result if there is no overflow, which it does if you perform binary addition.

Checkpoint 7.4.2. Understanding How Flags are Set by Cmp.

    Assume that %rax contains 12 and %rcx contains 22. Which condition code flags will be set by the following instruction:
    cmp %rcx, %rax
  • ZF
  • Incorrect.
  • SF
  • Correct!
  • CF
  • Incorrect.
  • OF
  • Incorrect.

Checkpoint 7.4.3. Understanding How Flags are Set by Cmp.

    Find values for %rax and %rcx for which cmp %rcx, %rax would result in setting all condition code flags to 0.
    For which of the following values for %rax and %rcx does the instruction cmp %rcx, %rax not set any flags?
  • %rax = 5, %rcx = 4
  • Correct!
  • %rax = 4, %rcx = 5
  • Incorrect.
  • %rax = 5, %rcx = 5
  • Incorrect.
  • All of the above instruction set a flag.
  • Incorrect.
  • None of the above instruction set a flag.
  • Incorrect.

Checkpoint 7.4.4. Understanding How Flags are Set by Test.

    Assume that %rax contains 0. Check all the flags that would be set by the following instruction:
    test %rax, %rax
  • ZF
  • Correct!
  • SF
  • Incorrect
  • CF
  • Incorrect.
  • OF
  • Incorrect.

Checkpoint 7.4.5. Hits/Misses.

Given the following initial state:
%rcx 0x1
%rdx 0x8
What value is in the %rdx register after the following code is executed? Enter your answer in hex.
cmp $rcx, %rdx
jge label
inc %rdx
label:
sub $2, %rdx
Your Answer:

Checkpoint 7.4.6. Basic operation of CMP and JMP.

    Under what conditions would the following instructions jump to label Foo?
    cmp %rax, %rcx
    jle Foo
  • When the contents of %rcx is greater than the contents of %rax
  • Incorrect.
  • When the contents of register %rcx is less than the contents of %rax
  • Correct!
  • When the contents of register %rcx is equal to the contents of %rax
  • Correct!
  • None of the above.
  • Incorrect.