Homework 3
|
Modified: |
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:
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.
- Analysis of problem (determination of input and output, decomposition of problem into module structure chart).
- Design of algorithm (pseudo code and variables of algorithm for each module of structure chart).
- Implementation (translation to target language).
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(); }
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.