Section 9.4
Review Questions

A program with a loop

  1. How are while and if control structures implemented in assembler?
  1. Who was the famous computer scientists who wrote the paper "Goto Considered Harmful?"
  1. What new methodology of programming appeared in the mid-1960s that replaced the older spaghetti code?
  1. What CSC-1 instruction always appears at the "bottom" of a while loop?
  1. Which CSC-1 instruction is often used as a "do-nothing" placeholder?
  1. How many jumps must there be in every while loop?
  1. Sketch out the skeleton of a while loop as implemented in CSC-1 assembler.
  1. When writing CSC-1 assembler code that implements an if statement, what instruction must appear before the ELSE?
  1. How are relational comparisons such as x < y implemented in assembler?
  1. If two numbers are equal what value results from their subtraction?
  1. When you subtract A-B, what does it mean when the answer is negative?
  1. What are improvements in code called?
  1. The gcd program in Section 9.4 does not have any I/O. Why not?
  1. How do many computers, such as those using the Motorola 68000 chip, actually perform input and output?

The following questions deal with actual CSC-1 code, especially that appearing in Section 9.4. You should attempt these questions only after you've carefully studied all the code examples in the section.
  1. Write 2 lines of CSC-1 assembler which compare x != y.
  1. Declare two integer variables called m and n. They should have the initial values 12 and 19, respectively.
  1. Which CSC-1 instruction should appear at the end of every program?
  1. Write a tiny chunk of CSC-1 assembler which implements an if-then statement, one that has no else clause. Here's the C statements. (Don't worry about what is in the middle where the dots are. You could use a NOP if you want to.)
               if (x != y) {
                    ....
               }
  1. Write a couple CSC-1 instructions which would implement the following C statement: (Assume that variables x and y have already been declared.)
               x = x + y;
  1. Write a couple CSC-1 instructions which would implement the following C statement: (Assume that all variables appearing in the C have already been declared.)
               y = x - z + w;
  1. Given the following fragment from the gcd program, why is x > y not implemented by a subtraction instruction?
        3:  IF:        JN    ELSE      ;      if (x > y)
        4:  THEN:      STD   X         ;           x = x - y;
        5:             JMP   ENDIF     ;
        6:  ELSE:      LOD   Y         ;      else
        7:             SUB   X         ;
        8:             STD   Y         ;           y = y - x;
        9:  ENDIF:     NOP             ;