17
Lecture 3 Lecture 3

Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

Embed Size (px)

Citation preview

Page 1: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

Lecture 3Lecture 3

Page 2: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

Diff b/w RAM and Diff b/w RAM and RegistersRegisters

Registers are used to hold data immediately Registers are used to hold data immediately applicable to the operation at handapplicable to the operation at hand

Main Memory is used to hold data that Main Memory is used to hold data that would be needed in near futurewould be needed in near future

A bus is a collection of wires. Through bus A bus is a collection of wires. Through bus the CPU is able to extract or read data from the CPU is able to extract or read data from main memory by supplying the address.main memory by supplying the address.

Also CPU can write data into memory by Also CPU can write data into memory by providing the address or destination of the providing the address or destination of the cell cell

Page 3: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

Sec 2.3 Program Sec 2.3 Program Execution CycleExecution Cycle

A computer follows a program stored in A computer follows a program stored in Main memory by copying one instruction Main memory by copying one instruction at a time from memory to control unitat a time from memory to control unit

Once in the Control Unit each instruction Once in the Control Unit each instruction is decoded and obeyedis decoded and obeyed

The order in which the instructions are The order in which the instructions are fetched from memory correspond to the fetched from memory correspond to the order in which they are stored in memory order in which they are stored in memory unless specified by JUMPunless specified by JUMP

Page 4: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

Machine CycleMachine Cycle

Control Unit continually repeat a set Control Unit continually repeat a set of steps known as of steps known as Machine Cycle Machine Cycle that are:that are:

FetchFetch Decode Decode ExecuteExecute

Page 5: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

What is Fetch ??What is Fetch ?? During the Fetch the Control Unit During the Fetch the Control Unit

requests the Main Memory to provide it requests the Main Memory to provide it with the instruction next to be executed.with the instruction next to be executed.

The Control Unit knows the instruction The Control Unit knows the instruction address because it is kept in the address because it is kept in the Program CounterProgram Counter

The Control Unit places the instruction The Control Unit places the instruction received from memory in its Instruction received from memory in its Instruction Register and then increments the PC Register and then increments the PC

Page 6: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

What is Decode ??What is Decode ??

With the instruction now in the IR the control With the instruction now in the IR the control unit decodes the instruction, which involves unit decodes the instruction, which involves breaking it up into Op-code and Operands.breaking it up into Op-code and Operands.

Op-code is the number that indicates the Op-code is the number that indicates the machine instruction that needs to be machine instruction that needs to be executed.executed.

Operands are those that would be Operands are those that would be manipulated by the execution of the manipulated by the execution of the instructioninstruction

Page 7: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

Figure 2.5Figure 2.5 The The composition of an composition of an instruction for the instruction for the

machine in Appendix Cmachine in Appendix C

Page 8: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

Figure 2.6Figure 2.6 Decoding the Decoding the instruction 35A7instruction 35A7

Page 9: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

Figure 2.7Figure 2.7 An encoded An encoded version of the version of the

instructions in Figure instructions in Figure 2.22.2

Page 10: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

What is Execute ??What is Execute ??

The Control Unit then executes the The Control Unit then executes the instruction by activating the proper instruction by activating the proper circuitry to perform the requested taskcircuitry to perform the requested task

Example:Example: If the instruction is LOAD from If the instruction is LOAD from

memory the CU causes the load to memory the CU causes the load to occuroccur

When the Execute is over the Control When the Execute is over the Control Unit begins the cycle againUnit begins the cycle again

Page 11: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

What About the JUMP What About the JUMP Instruction ??Instruction ??

There are two kinds of Jump There are two kinds of Jump Conditional and Unconditional JumpsConditional and Unconditional Jumps

Conditional Jump would be executed Conditional Jump would be executed only if certain condition is met only if certain condition is met

ExampleExample If I have instruction B43C then B is If I have instruction B43C then B is

the opcode for jump , 4 stands for the opcode for jump , 4 stands for Register R4 , 3C is the memory Register R4 , 3C is the memory addressaddress

???????????????????????????????? ????????????????????????????????

Page 12: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

This means that the Control Unit would This means that the Control Unit would first compare the contents of Register 4 first compare the contents of Register 4 with Register 0 if both are equal then the with Register 0 if both are equal then the Control would put the address 3C into PC.Control would put the address 3C into PC.

Thus Program Execution would be altered Thus Program Execution would be altered and the instructions in between would be and the instructions in between would be skipped.skipped.

However if R0 and R4 are not equal then However if R0 and R4 are not equal then normal execution would be continued.normal execution would be continued.

Page 13: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

Figure 2.9Figure 2.9 Decoding the Decoding the instruction B258instruction B258

Page 14: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

An Example of Program An Example of Program ExecutionExecution

Suppose I have written the following High Level Language Suppose I have written the following High Level Language InstuctionInstuction

a:= b+ca:= b+c Now a, b , c are names given to some cells of memory Now a, b , c are names given to some cells of memory Suppose the address of Suppose the address of a is B2a is B2 b is C3b is C3 c is AAc is AA

Simplified :Simplified : Load the value stored in address C3 in some registerLoad the value stored in address C3 in some register Load the value stored in address AA in some registers Load the value stored in address AA in some registers Add both the registers and store their answer in the third Add both the registers and store their answer in the third

registerregister Put Back / Store the answer in the main memory at address B2Put Back / Store the answer in the main memory at address B2 Stop/ Halt the instructionStop/ Halt the instruction

Page 15: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

Machine InstructionsMachine Instructions Single High Level instructions gets translated Single High Level instructions gets translated

into one or more Machine Level Instructionsinto one or more Machine Level Instructions

Thus Machine Instructions would be:Thus Machine Instructions would be: 15C3 : Load R5 with the contents of b15C3 : Load R5 with the contents of b 16AA : Load R6 with the content of c16AA : Load R6 with the content of c 5056 : Add R5, R6 and store their result in 5056 : Add R5, R6 and store their result in

R0R0 30B2 : Store the result saved in R0 to 30B2 : Store the result saved in R0 to

address B2address B2 C000: Halt C000: Halt

Page 16: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

An Example of Program An Example of Program Execution (cont….)Execution (cont….)

AddressAddress ContentContent

A0A0 1515

A1A1 C3C3

.A2.A2 1616

.A3.A3 AAAA

A4A4 5050

A5A5 5656

A6A6 3030

A7A7 B2B2

A8A8 C0C0

A9A9 0000

.. ??

AAAA 0909

AddressAddress ContentContent

B0B0 ??

.. ??

B2B2 ??

.. ??

.. ??

.. ??

.. ??

.. ??

C3C3 0202

.. ??

.... ??

Page 17: Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data

At first PC would be A0 IR would be emptyAt first PC would be A0 IR would be empty--------------------------------------------------------------------------------------------------------------PC : A2 IR: 15C3PC : A2 IR: 15C3Step 1: R5 would contain 2Step 1: R5 would contain 2--------------------------------------------------------------------------------------------------------------PC: A4 IR : 16AAPC: A4 IR : 16AAStep 2: R6 would contain 9Step 2: R6 would contain 9----------------------------------------------------------------------------------------------------------------PC: A6 IR: 5056PC: A6 IR: 5056Step 3: R0 would contain BStep 3: R0 would contain B------------------------------------------------------------------------------------------------------------------PC : A8 IR: 30B2PC : A8 IR: 30B2Step 4: Next value B would be copied to location B2Step 4: Next value B would be copied to location B2----------------------------------------------------------------------------------------------------------------------------------PC: AA IR: C000PC: AA IR: C000Step 5: HaltStep 5: HaltIn the end B2 i.e memory a would be containing the resultIn the end B2 i.e memory a would be containing the result