Here is an example to show that computers just blindly follow instructions.
Three employees work 20, 40, and 50 hours, respectively, one week. Their hourly rates of pay are 6, 10, and 9 dollars, respectively. Calculate their gross wages, adjusting for time-and-a-half for hours worked over 40 per week.
The computer's RAM (Random Access Memory) contains the following values at the given address.
| address | contents |
|---|---|
| 0 | 40 |
| 1 | 20 |
| 2 | 40 |
| 3 | 50 |
| 4 | 6 |
| 5 | 10 |
| 6 | 9 |
| 7 | 0 |
| 8 | 0 |
| 9 | 0 |
| 10 | 0.5 |
The computer's CPU (Central Processing Unit, microprocessor) has two registers, R and I, containing 0 and 1, respectively. The CPU also has a register called PC (Program Counter) that it uses to keep track of which step it is currently executing.
The computer executes the following steps.
See if you can reproduce on scratch paper on your own what we did in class.
For the curious, the following C++ program performs the same calculations as the machine language steps above.
#include <iostream>
using namespace std;
int main() {
const double WEEK = 40.0; // 40 hours is a standard work week.
const double OVERTIME = 0.5; // Extra pay for working overtime.
const int EMPLOYEES = 3;
double hoursWorked[EMPLOYEES] = { 20.0, 40.0, 50.0 };
double payRate[EMPLOYEES] = { 6.00, 10.00, 9.00 };
double payCheck[EMPLOYEES];
for (int i = 0; i < EMPLOYEES; i++) {
payCheck[i] = 0;
if (hoursWorked[i] - WEEK > 0) {
double extraOvertime = (hoursWorked[i] - WEEK) * OVERTIME;
payCheck[i] = payCheck[i] + extraOvertime * payRate[i];
}
payCheck[i] = payCheck[i] + hoursWorked[i] * payRate[i];
}
cout << payCheck[0] << " " << payCheck[1] << " " << payCheck[2] << endl;
return 0;
}
home page:
http://elvis.rowan.edu/~hartley/index.html
e-mail:
hartley@elvis.rowan.edu