Lec 4-2 Five operations of the machine cycle Fetch- fetch the next program instruction from memory. (PC+1); instruction to IR Decode- decode the instruction stored in the IR. Fetch- fetch the operand to the registers Execute- process the command. Store – write the results of the instruction into main memory.
Instruction Cycle Two steps: * Fetch * Execute
Fetch Cycle Program Counter (PC) holds address of next instruction to fetch Processor fetches instruction from memory location pointed to by PC Increment PC –Unless told otherwise Instruction loaded into Instruction Register (IR) Processor interprets instruction and performs required actions
Execute Cycle Processor-memory –data transfer between CPU and main memory Processor I/O –Data transfer between CPU and I/O module Data processing –Some arithmetic or logical operation on data Control –Alteration of sequence of operations –e.g. jump Combination of above
Example 1: Describe the sequence of events carried out during the machine cycle when executing the following instructions. AddressContents 500LDA ADD STO JMP
Instruction #1 LDA 1000 – Load to the accumulator the contents of the memory location 1000.
:::: LDA ADD 1001STO 1002JMP 510 :::: :::: IR MAR MDR PC TMP ACC 500 CPU MM Address bus Data bus RW LDA 1000 Decode LDA
Instruction #2 ADD 1001 – add the contents of location 1001 and the contents of the accumulator and store the result back in the accumulator.
:::: ADD 1001STO 1002JMP 510 :::: :::: IR MAR MDR PC TMP ACC 501 CPU MM Address bus Data bus RW LDA ADD 1001 Decode Add
Instruction #3 STO 1002 – store the contents of the accumulator to the memory location 1002.
:::: ADD 1001STO 1002JMP 510 :::: :::: IR MAR MDR PC TMP ACC 502 CPU MM Address bus Data bus RW LDA STO 1002 Decode
Instruction #4 JMP 510 – Jump to memory location 510
:::: ADD 1001STO 1002JMP 510 :::: :::: IR MAR MDR PC TMP ACC 503 CPU MM Address bus Data bus RW LDA Decode 10 JMP
Example 2: Describe the sequence of events carried out during the machine cycle when executing the following instructions. AddressContents 100JMP MOV R1 R2Move the contents of register R2 to R1. 201STO 800 R1Store the contents of R1 in memory location 800.
AddressContentsComments 100JMP LDA MPY 1001Multiply the contents of the Accumulator with the contents of the memory location 1001 and store the result back in the Accumulator. 202STO Example 3: