CS273

Quiz 6 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.

 

  1. (5 points) For each of the following code segments, label each for their code structure:
                    While (do-while) loop; Repeat (do-until) loop; If-Then-Else; or
                    Sequential (linear):

                                                                                                          Code Structure Type

a.       loop1         ldaa          mem1                                             Repeat Loop
                  cba
                  bhi            loop1

b.      fred            ldaa           #$99                                              Sequential
                  tba
                  ldaa           #44
                  stab           mem1
                  staa           mem2

c.       sam            beq          charlie                                            While Loop
                  decb
                  deca
                  bra           sam
charlie        tab

d.      sanm          ldaa         first                                                  If .. Then .. Else
lanm           ldab         second
                  cba
                  bge         bigger
                  stab         large
                  bra          cont
bigger         staa         large
cont            bra          sanm

e.       larry            inx                                                                 Repeat Loop
                   ldab        wcnt
larry1          subb        one                                                 While Loop
                   bcc          larry
                   dec          wcnt1
                   bra           larry1       

 

  1. (5 points) For each of the following small programs, indicate True (T) or False (F) if the
                    code will assemble and execute correctly in the simulator; if False, briefly
                    explain why:
                                                                                                            True/False (why)
    1.            org      $f800
      start     fcb       $ff                                                                 F - `start’ is not
                  ldab     start                                                                      at an instruction
                  stab     $1004
      endl      bra      endl
                  org      $fffe
                   fdb      start

    2. n          fcb       $ff                                                                 F – fcb as no memory   
                  org      $f800                                                                   placememt
      start     ldab     n
                  stab     $1004
      endl      bra      endl
                   org      $fffe
                   fdb      start

    3. newv    equ     $ff                                                                 T        
                  org      $f800
      n          fcb       newv
      start     ldab     n
                  stab     $1004
      endl      bra      endl
                   org      $fffe
                   fdb      start

    4. start     org      $f800                                                           F - `start’ is not at an
      n          fcb      $ff                                                                      instruction
                  ldab     n
                  stab     $1004
      endl      bra      endl
                   org      $fffe
                   fdb      start

    5.             org      $f800                                                           T
      n          fcb      $f0
      start     ldab     n
                  stab     $1004
      endl      bra      endl
                   org      $fffe
                   fdb      start