Exam 1

Prof. Tak Auyeung

Instructions: You may bring any material that is handwritten or printed prior to the examination to help you. You can also bring a calculator if you think it may help you. However, you can only use the calculator for numerical computations only.

You, as an individual, are expected to do your own work. This means you cannot seek, receive or otherwise acquire any assistance except clarifications from the professor during an examination. Any communication involving the contents of the subject matter or the examination is considered cheating. Do not initiate or accept such communication, or the result of your examination is automatically voided.

Each correct answer is worth one point, each wrong answer is worth -0.25 point, and each unanswered question is worth zero point.

Make sure you write down you name on the upper right corner first, otherwise I cannot give points to anonymous students!

  1. Which of the following instructions do not involve any memory operands?
    1. movl %eax, (%edx)
    2. movl %eax, 123
    3. movl $123, -3(%edx)
    4. movl $123, %ebx
    5. jmp label1
  2. Which of the following instruction sequences goes to label L1 if and only if the value of register eax is greater than the value of register ebx? Assume both registers should be interpreted as unsigned values.
    1. cmpl %eax, %ebx
      ja   L1
      
    2. cmpl %eax, %ebx
      jnc  L1
      
    3. cmpl %eax, %ebx
      jb   L1
      
    4. cmpl %ebx, %eax
      ja   L1
      
    5. both 2c and 2d
  3. Which flag or flags are interpreted by ja?
    1. only C
    2. only Z
    3. only C and Z
    4. only O, S and Z
    5. only O and S
  4. Which flag or flags are set after the following instructions?
    movb $0x7f, %al
    cmpb $0x7e, %al
    
    1. only S
    2. only C
    3. only Z
    4. only O
    5. none of the S, C, Z or O flags is set
  5. In some cases, the negation of a condition can be handled by changing the comparison operator. Select a pseudocode that is equivalent to the following code:


    \begin{algorithmic}
\IF{$(x < y) \wedge (y < z)$}
\STATE block1
\ENDIF
\end{algorithmic}


    1. \begin{algorithmic}
\IF{$(x < y) \wedge (y < z)$}
\STATE goto L1
\ENDIF
\STATE block1
\STATE L1:
\end{algorithmic}

    2. \begin{algorithmic}
\IF{$(x \ge y)$}
\STATE goto L1
\ENDIF
\IF{$(y \ge z)$}
\STATE goto L1
\ENDIF
\STATE block1
\STATE L1:
\end{algorithmic}

    3. \begin{algorithmic}
\IF{$(x < y)$}
\STATE goto L1
\ENDIF
\IF{$(y \ge z)$}
\STATE goto L1
\ENDIF
\STATE block1
\STATE L1:
\end{algorithmic}

    4. \begin{algorithmic}
\IF{$(x \ge y)$}
\STATE goto L1
\ENDIF
\IF{$(y < z)$}
\STATE goto L1
\ENDIF
\STATE block1
\STATE L1:
\end{algorithmic}

    5. \begin{algorithmic}
\IF{$(x \ge y)$}
\STATE goto L1
\ENDIF
\IF{$(y \ge z)$}
\STATE goto L1
\ENDIF
\STATE L1:
\STATE block1
\end{algorithmic}
  6. What is the value of register eax at label test?
    .data
    someData:
      .long 0x11223344
    someOtherData:
      .long 0xaabbccdd
    .text
    .global _start
    _start:
      movl someData,%eax
      movw someOtherData,%ax
    test:
      nop
      # the rest of the program is not important
    
    1. 0x3344
    2. 0xccdd
    3. 0x1122ccdd
    4. 0xaabb3344
    5. 0xccdd1122
  7. Which register is modified in the following instruction?

    movl %eax, (%ebx, %edx, 1)

    1. only %eax
    2. only %ebx
    3. only %ebx and edx
    4. eax, ebx and edx
    5. no register is modified
  8. Which flag cannot be set when the Z flag is set?
    1. only C
    2. only S
    3. only O
    4. both C and S
    5. both C and O
  9. What do we know about the following code?
    L1:
      addl $1,%eax
      jnz  L1
    
    1. this loop always exits, regardless of the value of eax before the loop
    2. this is an infinite loop (it never exits)
    3. this loop exits only if eax was odd before the loop
    4. this loop exits only if eax was even before the loop
    5. this loop generates a segmentation fault
  10. What is the value of eax at label test?
    .data
    someData:
      .byte 0x01, 0x02, 0x03, 0x04, 0x05, 0x06
    someDataEnd:
    .text
    .global _start
    _start:
      movl $someData, %eax
      movl $0, %ebx
    L1:
      cmpl $someDataEnd, %eax
      jnc  test
      addb (%eax), %bl
      addl $1,%eax
      jmp  L1
    test:
      # some more code to follow
    
    1. 0
    2. someDataEnd
    3. 0x06
    4. the sum of 1, 2, 3, 4, 5, 6
    5. someData


Copyright © 2005-02-24 by Tak Auyeung