Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dr Verbrugge Simulated Machine Simulated Machine Problem: Find the Average of the following three numbers: 5, 7, 10 Average = 7 with a remainder of 1.

Similar presentations


Presentation on theme: "Dr Verbrugge Simulated Machine Simulated Machine Problem: Find the Average of the following three numbers: 5, 7, 10 Average = 7 with a remainder of 1."— Presentation transcript:

1 Dr Verbrugge Simulated Machine Simulated Machine Problem: Find the Average of the following three numbers: 5, 7, 10 Average = 7 with a remainder of 1

2 Dr Verbrugge Simulated Machine Simulated Machine Flow logic of finding Average of three numbers Get number Add number to Sum Add 1 to Count Sum = 0 Count = 0 Get number Add number to Sum Add 1 to Count Get number Add number to Sum Add 1 to Count Stop Start Divide Sum by Count giving Answer Write Answer

3 Dr Verbrugge Simulated Machine CPU – Central Processing Unit

4 Dr Verbrugge Simulated Machine Computer structure Central Processing Unit Memory (RAM) 0……………. 1……………. Registrars Accumulator, Multiply Quotient Instruction, Instruction location, etc. Control/Logic – Instructions Add, Subtract, Transfer, etc. Input Devices Output Devices Secondary Storage

5 Dr Verbrugge Simulated Machine The Hardware 1000 Memory Locations (Addressed 0 - 999) –101 - 999 Reserved for Variables and Constants –000 - 100 Reserved for Instructions AC -- Accumulator Register MQ -- Multiplier-Quotient Register –Both registers can hold any positive or negative value greater than or equal to –2,147,483,648 and less than or equal to 2,147,483,647. Two controlling Registers –Instruction Register -- Holds the binary instruction - viewed in Decimal –Instruction Location Register -- Holds the binary value of the memory location where the instruction was - viewed in Decimal

6 Dr Verbrugge Simulated Machine Machine Instructions

7 Dr Verbrugge Simulated Machine Program the computer Central Processing Unit Memory (RAM) 0…..…5..100 100…………..0 1….….6..101 101…………… (will hold the sum) 2……..6..102 102…………… (will hold the count) 3……13..103 103…………… (will hold the number) Registrars Accumulator……………………. Multiply Quotient……………….. Instruction………5..100….…… Instruction location…………0…. Control/Logic – Instructions ADD(9), CLA(5), RD(13), STO(6) TRA, etc.

8 Dr Verbrugge Simulated Machine Assembler Instruction One to One translation to Machine Instructions LABEL: OperationCode Operand #Comment The assembler is not case sensitive. Thus cla, CLA, and Cla are the same. Some different forms of an instruction are the following: start: CLA 1 # 1 is a constant and this instruction has a label STO one #one is a variable which now holds 1 TRA next: ADD one # this instruction will be skipped Next: STP

9 Dr Verbrugge Simulated Machine

10 Simulated Machine Flow logic of finding Average of any numbers Get number Sum = 0 Count = 0 Add number to Sum Add 1 to Count Stop Start Divide Sum by Count giving Answer Write Answer Write number Is number = -9999? No 1 1 Yes

11 Dr Verbrugge Simulated Machine The Simulated Machine

12 Dr Verbrugge Simulated Machine Now in a higher level Language _ JAVA // The Java model class for the assembler find average program public class Avg { public void computeAvg() { int num = Integer.parseInt( JOptionPane.showInputDialog("Enter A Number")); int count = 0; int sum = 0; while (!(num == -9999)) { sum = sum + num; count = count + 1; num = Integer.parseInt(JOptionPane.showInputDialog("Enter A Number")); } JOptionPane.showMessageDialog(null, " Avg = " + sum / count + “Remainder = “ + sum % count ); } // end computeAvg() } // end class


Download ppt "Dr Verbrugge Simulated Machine Simulated Machine Problem: Find the Average of the following three numbers: 5, 7, 10 Average = 7 with a remainder of 1."

Similar presentations


Ads by Google