Homework 3
Arrays and Procedures

Modified

Overview

Assembly language programmers benefit greatly from program analysis and design methods such as those studied in C201 and C202, which can be applied to implementing an algorithm in any language.

It consists of:

  1. Analysis of problem (determination of input and output, decomposition of problem into module structure chart).
  2. Design of algorithm (pseudo code and variables of algorithm for each module of structure chart).
  3. Implementation (translation to target language).
Recall that the target language influences the algorithm's design only slightly. It is STRONGLY urged that you practice this design method as test questions will often provide pseudo code algorithms for implementation in Assembler language.

Assignment

A high-level algorithm in pseudocode (that strongly resembles Java or C++) is given below.

Note the use of a global count and n variables.

The algorithm simulates tossing a die a given number of times, tallying the number of times 1, 2, 3, 4, 5, an 6 appear.

    int count[] = {0,0,0,0,0,0};
    int n;
    public void simulate() {
        int i = n
        do {
            int r = random(6);
            count[r]++;
       } while (--i != 0) 
    }
    
    public void print() {
         int i = 6
         do {
               printDec(count[i]);
               println();
         }  while (--i != 0) 
   }    
   
   public void main() {
       printString("Enter number of tosses:");
       n = readDec();

       simulate( );
       print();
    }

Turn in

  1. Cover sheet with your name, date, and Homework 3.
  2. A structure chart of the program similar to Figure 5-13 on page 173 of the text. Show procedures from link library also.
  3. Implement the high-level pseudo code algorithm above as an Assembler language solution.

    Give program listing of solution.

    Test output using input of 4,000,000,000.

    To capture the output window:

    For documentation and as helpful reminder of the algorithm when debugging assembly code, include pseudo code comments to the right of assembly instructions.

Hints

  1. Use the pseudocode program as a guide for program structure.
  2. The input should be an unsigned 32-bit number. Use ReadDec to read an unsigned integer from the keyboard into the eAx register.
  3. The text's string output function, WriteString, requires the eDx register to point to the location of the string to be output.
  4. Use Randomize to produce a different sequence of random numbers for each execution.
  5. Use RandomRange(6) to generate a random number 0..5.
  6. Consider using array indexing, such as count[ eSi*4], to update the toss count, where eSi is the random number.
  7. Do initial testing using a smaller input than 4,000,000,000. The relative frequency of die number 1, 2, 3, 4, 5, 6 for small input values should be approximately the same.