Practice Exercise 9

  1. Encode the following into binary just as it would be stored in the CSC-1's memory:
                     LOD     M
          AGAIN:     ADD     K
                     SHL
                     JZ      AGAIN
                     HLT
          M:         NUM     8
          K:         NUM     10

  1. In the CSC-1 only 4 bits are dedicated to the opcode for instructions that have an operand. The instructions that have no operand, such as SHR, which implicitly work on the A register, are encoded using the "escape" mechanism of setting the top 4 bits to 1111 and putting the "real" opcode into the next 4 bits. Propose a way to allow the inclusion of more instructions that have an operand. What effect would your proposal have on the basic fetch/decode/execute cycle?

  1. Create an assembler skeleton for a piece of C code that uses the <= comparison. The body of the then and else parts need not be specified. Here's the C' skeleton
     if (a <= b)
          /*  then code  */
     else
          /*  else code */

  1. Trace through the following CSC-1 program, whose purpose is to find the largest element in an array of integers. Show the values of the A, S, PC and IR registers at the beginning of each instruction execution. Use symbolic values for the IR register but show integer values for the others.
  0  TOP:      LDI  2000      ; bring ARRAY[I] into A reg
  1            ADD  I         ; by first calculating address
  2            A2S
  3            LDS
  4            JN   ENDLOOP   ; if the element is negative, stop
  5            STD  TEMP      ; save it in TEMP for later reuse
  6            SUB  MAX       ; compare element to current MAX value
  7            JP   CHANGE    ; if it's greater than MAX, then change max
  8            JMP  NOCHANGE  ; else do nothing
  9  CHANGE:   LOD  TEMP      ; get element out of TEMP
  10           STD  MAX       ; and copy it into MAX
  11 NOCHANGE: LDI  1         ; add 1 to index variable I
  12           ADD  I         ; which sets us up for next round
  13           STD  I
  14           JMP  TOP       ; keep going!  (This is a loop...)
  15 ENDLOOP:  HLT            ; the answer is in memory location MAX
  16           =2000
2000 ARRAY:    NUM  26        ; this is the array of 3 integer
2001           NUM  47        ; we can see this is the max value!
2002           NUM  17
2003           NUM  -1        ; sentinel value signaling the end of the array
2004 I:        NUM  0         ; index variable
2005 MAX:      NUM  0         ; start out with lowest possible value
2006 TEMP:     NUM  0         ; temporary storage place


     Here's the starting configuration:

Time  PC     IR        A       S        I         MAX        TEMP
-----------------------------------------------------------------
  0    0   LDI 1000    0       0        0          0          0

  1. Perform a full integer multiplication of 196×37 using the scheme shown at the end of Chapter 9.

  1. Write a CSC-1 program that performs subtraction (A-B) by forming the 2's complement of the subtrahend (B) and then adding that to the subtractor (A).