1 / 12

Simulated Machine

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.

kennan
Download Presentation

Simulated Machine

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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

  3. CPU – Central Processing Unit Dr Verbrugge Simulated Machine

  4. 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

  5. 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

  6. Machine InstructionsThe structure of an instruction is [OpCode Operand]

  7. 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

  8. 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

  9. Dr Verbrugge Simulated Machine

  10. 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

  11. The Simulated Machine Dr Verbrugge Simulated Machine

  12. 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

More Related