120 likes | 215 Views
Simulated Machine. Problem: Find the Average of the following three numbers: 5, 7 , 10 Average = 7 with a remainder of 1. Simulated Machine Flow logic of finding Average of three numbers. Start. Get number. Divide Sum by Count giving Answer. Add number to Sum Add 1 to Count.
E N D
Simulated Machine Problem: Find the Average of the following three numbers: 5, 7 , 10 Average = 7 with a remainder of 1 Dr Verbrugge Simulated Machine
Simulated Machine Flow logic of finding Average of three numbers Start Get number Divide Sum by Count giving Answer Add number to Sum Add 1 to Count Sum = 0 Count = 0 Write Answer Get number Get number Add number to Sum Add 1 to Count Add number to Sum Add 1 to Count Stop Dr Verbrugge Simulated Machine
CPU – Central Processing Unit Dr Verbrugge Simulated Machine
Computer structure Control/Logic – Instructions Add, Subtract, Transfer, etc. Registrars Accumulator, Multiply Quotient Instruction, Instruction location, etc. Input Devices Output Devices Secondary Storage 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 greaterthan 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 Dr Verbrugge Simulated Machine
Machine InstructionsThe structure of an instruction is [OpCode Operand]
Program the computer Registrars Accumulator……………………. Multiply Quotient……………….. Instruction………5..100….…… Instruction location…………0…. Control/Logic – Instructions ADD(9), CLA(5), RD(13), STO(6) TRA, etc. Dr Verbrugge Simulated Machine
Assembler InstructionOne 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 Dr Verbrugge Simulated Machine
Simulated Machine Flow logic of finding Average of any numbers 1 Start Is number = -9999? Divide Sum by Count giving Answer Yes Sum = 0 Count = 0 No Write Answer Get number Add number to Sum Add 1 to Count Stop Write number 1 Dr Verbrugge Simulated Machine
The Simulated Machine Dr Verbrugge Simulated Machine
Now in a higher level Language _ JAVA • // The Java model class for the assembler find average program • publicclass Avg • {publicvoid 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 Dr Verbrugge Simulated Machine