Presentation is loading. Please wait.

Presentation is loading. Please wait.

Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.

Similar presentations


Presentation on theme: "Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to."— Presentation transcript:

1 Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to

2 © 2006 Department of Computing Science CMPUT 229 Immediate and Absolute Addressing  Immediate Addressing The value of the operand is contained in the instruction itself: MOVE#1234, D0[D0]  1234 ADD#1234, D0[D0]  [D0] + 1234 Used to handle constants –Value must be known when the program is written  Absolute Addressing The address that contain the operand is part of the instruction MOVE1234, D0[D0]  [1234] ADD1234, D0[D0]  [D0] + [1234] Slower than immediate addressing (requires an additional memory access) Value can change after the program is written Clements, pp. 249

3 © 2006 Department of Computing Science CMPUT 229 Address-Register Indirect Addressing –The location of the value is in a pointer stored in an address register: ADD.B(A0), D0[D0]  [D0] + [[A0]] Clements, pp. 252 COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED

4 © 2006 Department of Computing Science CMPUT 229 Address-Register Indirect Addressing with Displacement –A constant is added to the value in an address register to determine the memory location of the operand. MOVE4(A0), D0[D0]  [[A0]+4] Clements, pp. 252 COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED

5 © 2006 Department of Computing Science CMPUT 229 Postincrementing and Predecrementing  Automatically increments/decrements the address register MOVE.B(A0)+, D0[D0]  [[A0]]; [A0]  [A0]+1 MOVE.W-(A2), (A3)+[A2]  [A2]-2; [[A3]]  [[A2]]; [A3]  [A3]+2 Clements, pp. 253 COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED

6 © 2006 Department of Computing Science CMPUT 229 Postincrementing and Predecrementing Clements, pp. 253 COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED

7 © 2006 Department of Computing Science CMPUT 229 Indexed Addressing  The address is given by two registers and a constant displacement MOVE.bOffset(A0, D0), D1[D1]  [[A0]+[D0]+Offset] Clements, pp. 258 COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED

8 © 2006 Department of Computing Science CMPUT 229 Indexed addressing (example)  PROBLEM: DIARY is a data structure divided into weeks and days. The week is in D0 and the position of a day within a week is given by a constant. Write a program that accesses the entry for Tuesday of a given week. –The address of this location is given by EntryAddress = DIARY + (WEEK-1)  7+TUESDAY

9 © 2006 Department of Computing Science CMPUT 229 Indexed addressing (example solution) SUNDAYEQU0 MONDAYEQU1 TUESDAYEQU2 WEDNESDAYEQU3 ….. LEADIARY, A0A0 points to the begin of the data structure MOVE.LWEEK, D0D0 contains the week number SUB.L#1, D0D0  WEEK - 1 MULU#7, D0D0  (WEEK - 1)  7 MOVE.BTUESDAY(A0,D0), D1Access the required entry EntryAddress = DIARY + (WEEK-1)  7+TUESDAY Clements, pp. 259

10 © 2006 Department of Computing Science CMPUT 229 Relative Address  Same as the indirect addressing, but the register used in the Program Counter (PC). –Makes possible to relocate programs without changing absolute addresses MOVEd16(PC), D0[D0]  [[PC] + d16] Clements, pp. 259

11 © 2006 Department of Computing Science CMPUT 229 Relative Address Clements, pp. 259 COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED

12 © 2006 Department of Computing Science CMPUT 229 Relative Branching  The target address of most branches are also expressed relative to the current value of the PC

13 © 2006 Department of Computing Science CMPUT 229 Outer Product  Given two vectors, the outer product of these two vectors is defined as follows

14 © 2006 Department of Computing Science CMPUT 229 Exercise #2  Write a code whose inputs are in memory at the following addresses: $8000: word containing the length of vector u; $8002: long word with the address of the first position of u; $8006: word containing the length of vector v; $8008: long word with the address of the first position of v; $800C: long word with the address of the first position of matrix A;  The program has to compute the values in matrix A, where A is the outer product of u and v: –A = u  v –A must be stored on a row-first order.

15 © 2006 Department of Computing Science CMPUT 229 Flow-Graph Sketch Addresses/Sizes Initialization i  0 counter for vector u i = size of u? j  0 counter for vector v j = size of v? A(i,j) = u(i)  v(j) j = j+1 i = i+1 yes no Done yes A = u  v

16 © 2006 Department of Computing Science CMPUT 229 RTL Sketch A0  L #$8000 D1  W (A0)+ length of vector u A1  L (A0)+ address of vector u D2  W (A0)+ length of vector v A2  L (A0)+ address of vector v A3  L (A0) address of matrix A  Write a code whose inputs are in memory at the following addresses: $8000: word containing the length of vector u; $8002: long word with the address of the first position of u; $8006: word containing the length of vector v; $8008: long word with the address of the first position of v; $800C: long word with the address of the first position of matrix A; Address/Size Initialization

17 © 2006 Department of Computing Science CMPUT 229 Flow-Graph Sketch D3  W 0counter for vector u LoopUCMPD3,D1 BEQDone D4  W 0counter for vector v LoopVCMP D4,D2 BEQ nextU D4  W D4+1j  j+1 BRA LoopV nextU D3  W D3+1i  i+1 BRA LoopU Done  A0  L #$8000 D1  W (A0)+ length of vector u A1  L (A0)+ address of vector u D2  W (A0)+ length of vector v A2  L (A0)+ address of vector v A3  L (A0) address of matrix A Address/Size Initialization Addresses/Sizes Initialization i  0 counter for vector u i = size of u? j  0 counter for vector v j = size of v? A(i,j) = u(i)  v(j) j = j+1 i = i+1 yes no yes Done

18 © 2006 Department of Computing Science CMPUT 229 Flow-Graph Sketch D3  W 0counter for vector u LoopUCMPD3,D1 BEQDone D4  W 0counter for vector v LoopVCMP D4,D2 BEQ nextU D4  W D4+1j  j+1 BRA LoopV nextU D3  W D3+1i  i+1 BRA LoopU Done  A0  L #$8000 D1  W (A0)+ length of vector u A1  L (A0)+ address of vector u D2  W (A0)+ length of vector v A2  L (A0)+ address of vector v A3  L (A0) address of matrix A Address/Size Initialization Addresses/Sizes Initialization i  0 counter for vector u i = size of u? j  0 counter for vector v j = size of v? A(i,j) = u(i)  v(j) j = j+1 i = i+1 yes no yes Done

19 © 2006 Department of Computing Science CMPUT 229 Flow-Graph Sketch D3  W 0counter for vector u LoopUCMPD3,D1 BEQDone D4  W 0counter for vector v LoopVCMP D4,D2 BEQ nextU D4  W D4+1j  j+1 BRA LoopV nextU D3  W D3+1i  i+1 BRA LoopU Done  A0  L #$8000 D1  W (A0)+ length of vector u A1  L (A0)+ address of vector u D2  W (A0)+ length of vector v A2  L (A0)+ address of vector v A3  L (A0) address of matrix A Address/Size Initialization Addresses/Sizes Initialization i  0 counter for vector u i = size of u? j  0 counter for vector v j = size of v? A(i,j) = u(i)  v(j) j = j+1 i = i+1 yes no yes Done

20 © 2006 Department of Computing Science CMPUT 229 Flow-Graph Sketch D3  W 0counter for vector u LoopUCMPD3,D1 BEQDone D4  W 0counter for vector v LoopVCMP D4,D2 BEQ nextU D4  W D4+1j  j+1 BRA LoopV nextU D3  W D3+1i  i+1 BRA LoopU Done  A0  L #$8000 D1  W (A0)+ length of vector u A1  L (A0)+ address of vector u D2  W (A0)+ length of vector v A2  L (A0)+ address of vector v A3  L (A0) address of matrix A Address/Size Initialization Addresses/Sizes Initialization i  0 counter for vector u i = size of u? j  0 counter for vector v j = size of v? A(i,j) = u(i)  v(j) j = j+1 i = i+1 yes no yes Done

21 © 2006 Department of Computing Science CMPUT 229 Flow-Graph Sketch D3  W 0counter for vector u LoopUCMPD3,D1 BEQDone D4  W 0counter for vector v LoopVCMP D4,D2 BEQ nextU D4  W D4+1j  j+1 BRA LoopV nextU D3  W D3+1i  i+1 BRA LoopU Done  A0  L #$8000 D1  W (A0)+ length of vector u A1  L (A0)+ address of vector u D2  W (A0)+ length of vector v A2  L (A0)+ address of vector v A3  L (A0) address of matrix A Address/Size Initialization Addresses/Sizes Initialization i  0 counter for vector u i = size of u? j  0 counter for vector v j = size of v? A(i,j) = u(i)  v(j) j = j+1 i = i+1 yes no yes Done


Download ppt "Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to."

Similar presentations


Ads by Google