CS273

Quiz 7 Solution

 

Put your social security number in the right hand corner of each page.  Please do not put your name anywhere on this quiz.  Failure to follow these instructions will cost you 1 point on the quiz.  Note: Be sure to show all your work and no calculators. You will have until the end of class to complete the quiz.

 

For each of the following mystery programs:

a)      Fill-in the comment at the top to say the function of the program.

b)      Label each loop structure you find in the code with:
                While (do-while) loop; Repeat (do-until) loop; or Dead (ending) loop.

c)      Change the names of the EQU directives to more appropriate names
                 (be sure to also change their references).

1. (4.5 points)

 

*

* Sum of numbers from 1 to nam5 (N)
*

*
nam1 RAM          equ     $0010            *

nam2 EEPROM       equ     $f800            *
nam3 RESET        equ     $fffe            *  

                  org     nam1   RAM       *

nam4              rmb     1                *

                  org     nam2   EEPROM    *

nam5              fcb     $09              *

nam6              ldaa    nam5             *

                  ldab    nam5             *

                  decb                    *

nam7              aba                     *  REPEAT {      

                  decb                    *

                  bne     nam7             *  } Until (b == 0)

                  staa    nam4             *

nam8              bra     nam8             *  DEAD Loop

                  org     nam3   RESET     *

                  fdb     nam6             *

 

 

2. (6 points)

 

*

*  ¼ Second Green lights; ¼ Second No lights; Repeat for Motors
*

*
stf44  EEPROM     equ     $f800            *
stf55  RESET      equ     $fffe            *

stf66  GREENLTS   equ     $f0              *

stf77  NOLGTS     equ     0

stf88  MOTORS     equ     $1004            *  

                  org     stf44   EEPROM   *

stf11             ldx     #49999           *  REPEAT {

                  ldaa    #stf66  GREENLTS *

stf22             staa    stf88   MOTORS   *  REPEAT {

                  dex                     *

                  bne     stf22            *  } Until (b == 0)

                  nop                     *

                  brn     stf22            *

                  ldaa    #stf77  NOLGTS   *

                  ldx     #49999           *

stf33             staa    stf88   MOTORS   *  REPEAT {

                  dex                     *

                  bne     stf33            *  } Until (b == 0)

                  nop                     *

                  bra     stf11            *  } Until (1)

                  org     stf55   RESET    *

                  fdb     stf11            *

 

3. (4.5 points)

*

*  Sum of numbers from 1 to lab5 (N)
*

*
lab9  RAM         equ    $0010            *

lab8  EEPROM      equ    $f800            *

lab7  RESET       equ    $fffe            *

                  org    lab9  RAM        *

lab4              rmb    1                *

                  org    lab8  EEPROM     *

lab5              fcb    4                *

lab6              ldaa   #0               *

                  ldab   lab5             *

lab3              beq    lab2             *  While (b != 0) {

                  aba                     *

                  decb                    *

                  bra    lab3             *  }

lab2              staa   lab4             *

lab1              bra    lab1             *  DEAD Loop

                  org    lab7  RESET      *

                  fdb    lab6             *