CS220 Lab 7
Conditional Processing

Trish Cornez


Part I: CPU Flags for Conditional Processing

Notes:
  1. CF: carry flag is set when the result of an unsigned arithmetic operation is too large to fit into the destination.
  2. SF: sign flag is cleared (0) when the result of an operation is a negative value, and is set (1) if the result is positive. Zero is assumed to be positive
  3. ZF: zero flag is set when the result of an operation is zero.
  4. OF: Overflow flag indicates a carry into and out of the high-order sign-bit following a signed arithmetic operation - a value is generated that is outside the signed range.

A. What will be the value of the Carry flag, CF, after each of the following instruction sequences has executed?
  1. MOV AX, 0FFFFFh
    ADD AX, 1


  2. MOV BH, 2d
    SUB BH, 2h


  3. MOV DX, 0h
    DEC DX


  4. MOV AL, ODFh
    ADD AL , 32h


  5. MOV EAX, 0B9F6h
    SUB EAX, 9874h


  6. MOV CX, 695Fh
    SUB CX , A218h






B. What will be the value of the Zero flag, ZF, after each of the following instruction sequences has executed?
  1. MOV AX, 0FFFFFh
    ADD AX, 1


  2. MOV BH, 2d
    SUB BH, 2h


  3. MOV DX, 0h
    DEC DX


  4. MOV AL, ODFh
    ADD AL , 32h


  5. MOV EAX, 0B9F6h
    SUB EAX, 9874h


  6. MOV CX, 695Fh
    ADD CX , 96A1h






C. What will be the value of the Sign flag, SF, after each of the following instruction sequences has executed?
  1. MOV AX, 0FFFFFh
    ADD AX, 1


  2. MOV BH, 2d
    SUB BH, 3h


  3. MOV DX, 0h
    DEC DX


  4. MOV AX, 7FFEh
    ADD AX , 22h


  5. MOV EAX, 0B9F6h
    SUB EAX, 9874h


  6. MOV CX, 8000h
    ADD CX , A69Fh





Part II: Practice Programs
Notes:
  1. The CMP instruction performs an implied subtraction of a source operand from a destination operation.
  2. The TEST instruction performs an implied AND operation between a pair of matching bits in two operands and set the flags accordingly.
Write a high level language program for each of the following and then rewrite in assembly language.

  1. Write a program that displays the text "BOBO" 6 times.

  2. Write a program that displays all the odd numbers from 1 through 100 in decreasing order.

  3. Write a program that displays all the uppercase letters in the alphabet.

  4. Write a program that displays the squares of the integers between 630 and 640. Note: The squares of these integers will require 32-bits.

  5. Write a program that displays the first 20 Fibonacci terms.

  6. Write a program that prompts the user for an integer between 69 and 169 - assume a valid entry. Display all the muliples of 7 between 30 and the integer input by the user.

  7. Write a program that reads in 10 test scores (validate) and computes the average score.