40 likes | 179 Views
Stored Program. Instruction memory is used to store a program Processor gets one instruction at a time It stores it locally (like) I0, I1 registers PC points to next location It is automatically incremented Control directs execution Another memory stores data Execution goes as follows
E N D
Stored Program • Instruction memory is used to store a program • Processor gets one instruction at a time • It stores it locally (like) I0, I1 registers • PC points to next location • It is automatically incremented • Control directs execution • Another memory stores data • Execution goes as follows LD/STADD/SUB/OR/XOR/AND I0 <-- IMEM[PC], PC+ I0 <-- IMEM[PC], PC+ I1 <-- IMEM[PC], PC+ Rz <-- (Rx) OP (Ry) Addr <-- (I1) Rx <-- DMEM[Addr] for LD, or DMEM [Addr] <-- Rx for ST
Conditional Branch Instruction • PC points to next instruction that is to be executed by a machine • However, user may want to change control flow • They use a branch instruction and condition code • For example if one wants to check if register R1 is greater than R2, we may subtract R2 from R1 and check the sign bit • Sign bit one means result is negative and R1 is smaller than R2 SUB R0, R1, R2 BNEG neg pos: …… ……. neg: ……. …….. • The conditions to check: • GT, LT, EQ, NE, GE, LE
Another Example: Deciding Grade • Consider a program segment to decide final grade If (grade < 50) then GRADE is fail (0) else if (grade < 60) then GRADE is D (1) else if (grade < 70) then GRADE is C (2) else if (grade < 80) then GRADE is B (3) else GRADE is A (4) we need to compare grade (say in register R1) with fixed values say in R2 (=50), R3(=60), R4(=70), R5(=80), and decide what to do • How will we write the program? SUB R0, R1, R2 /* Sub R2 from R1 and store result into R0 */ BPOS g50 /* Branch if result is a positive value */ LD R3, ZERO /* Load value from location called zero */ BR Done /* we are done */ g50: SUB R0, R1, R3 /* Store R1-R3 into R0 */ BPOS g60 /* Branch if > 60 */ …..
Inst Mem IIAD PC INST IAddr WIAD Input Output RA1 RA2 M- Reg WOUT Reg File OpCode EMR EALU EI S H I F T A L U WM Mem Unit Cond Code RM WR Data Addr SC WA EM WDAD Accounting for Branch Condition • If the branch condition is met, then we want to change PC value with new value, else we just increment PC • Branch address is part of instruction • We need to copy new address in PC • What change we need to make in data path?