Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.
-
date post
18-Dec-2015 -
Category
Documents
-
view
214 -
download
2
Transcript of Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.
![Page 1: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/1.jpg)
Faculty of Computer Science
CMPUT 229 © 2006
Addressing Modes
Where to load from/store to
![Page 2: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/2.jpg)
© 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
MOVE 1234, D0 [D0] [1234]
ADD 1234, D0 [D0] [D0] + [1234]
• Slower than immediate addressing (requires an additional memory access)
• Value can change after the program is written
Clements, pp. 249
![Page 3: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/3.jpg)
© 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
![Page 4: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/4.jpg)
© 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.
MOVE 4(A0), D0 [D0] [[A0]+4]
Clements, pp. 252
COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED
![Page 5: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/5.jpg)
© 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
![Page 6: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/6.jpg)
© 2006
Department of Computing Science
CMPUT 229
Postincrementing and Predecrementing
Clements, pp. 253
COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED
![Page 7: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/7.jpg)
© 2006
Department of Computing Science
CMPUT 229
Indexed Addressing
The address is given by two registers and a
constant displacement
MOVE.b Offset(A0, D0), D1 [D1] [[A0]+[D0]+Offset]
Clements, pp. 258
COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED
![Page 8: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/8.jpg)
© 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
![Page 9: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/9.jpg)
© 2006
Department of Computing Science
CMPUT 229
Indexed addressing (example solution)
SUNDAY EQU 0
MONDAY EQU 1
TUESDAY EQU 2
WEDNESDAY EQU 3
…..
LEA DIARY, A0 A0 points to the begin of the data structure
MOVE.L WEEK, D0 D0 contains the week number
SUB.L #1, D0 D0 WEEK - 1
MULU #7, D0 D0 (WEEK - 1) 7
MOVE.B TUESDAY(A0,D0), D1 Access the required entry
EntryAddress = DIARY + (WEEK-1)7+TUESDAY
Clements, pp. 259
![Page 10: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/10.jpg)
© 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
MOVE d16(PC), D0 [D0] [[PC] + d16]
Clements, pp. 259
![Page 11: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/11.jpg)
© 2006
Department of Computing Science
CMPUT 229
Relative Address
Clements, pp. 259
COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED
![Page 12: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/12.jpg)
© 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
![Page 13: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/13.jpg)
© 2006
Department of Computing Science
CMPUT 229
Outer Product
Given two vectors, the outer product of these two
vectors is defined as follows
![Page 14: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/14.jpg)
© 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.
![Page 15: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/15.jpg)
© 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
no
Done yes
A = u v
![Page 16: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/16.jpg)
© 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
![Page 17: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/17.jpg)
© 2006
Department of Computing Science
CMPUT 229
Flow-Graph Sketch
D3 W 0 counter for vector u
LoopU CMP D3,D1
BEQ Done
D4 W 0 counter for vector v
LoopV CMP D4,D2
BEQ nextU
<loop body>
D4 W D4+1 j j+1
BRA LoopV
nextU D3 W D3+1 i 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
no
yesDone
![Page 18: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/18.jpg)
© 2006
Department of Computing Science
CMPUT 229
Flow-Graph Sketch
D3 W 0 counter for vector u
LoopU CMP D3,D1
BEQ Done
D4 W 0 counter for vector v
LoopV CMP D4,D2
BEQ nextU
<loop body>
D4 W D4+1 j j+1
BRA LoopV
nextU D3 W D3+1 i 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
no
yesDone
![Page 19: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/19.jpg)
© 2006
Department of Computing Science
CMPUT 229
Flow-Graph Sketch
D3 W 0 counter for vector u
LoopU CMP D3,D1
BEQ Done
D4 W 0 counter for vector v
LoopV CMP D4,D2
BEQ nextU
<loop body>
D4 W D4+1 j j+1
BRA LoopV
nextU D3 W D3+1 i 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
no
yesDone
![Page 20: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/20.jpg)
© 2006
Department of Computing Science
CMPUT 229
Flow-Graph Sketch
D3 W 0 counter for vector u
LoopU CMP D3,D1
BEQ Done
D4 W 0 counter for vector v
LoopV CMP D4,D2
BEQ nextU
<loop body>
D4 W D4+1 j j+1
BRA LoopV
nextU D3 W D3+1 i 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
no
yesDone
![Page 21: Faculty of Computer Science © 2006 CMPUT 229 Addressing Modes Where to load from/store to.](https://reader037.fdocument.pub/reader037/viewer/2022110322/56649d265503460f949fca3d/html5/thumbnails/21.jpg)
© 2006
Department of Computing Science
CMPUT 229
Flow-Graph Sketch
D3 W 0 counter for vector u
LoopU CMP D3,D1
BEQ Done
D4 W 0 counter for vector v
LoopV CMP D4,D2
BEQ nextU
<loop body>
D4 W D4+1 j j+1
BRA LoopV
nextU D3 W D3+1 i 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
no
yesDone