Clemson University -- CPSC 231 -- Fall 2009 memory addressing modes (for the following examples, assume an accumulator machine structure and that an add instruction is stored in memory, beginning at location 12) direct addressing memory assembly lang. addr contents hardware actions -------------- ---- -------- ---------------- ... ... add(one) 12 | 40 | acc <- acc + memory[24] 13 | 24 | = acc + 1 ... ... word(one,1) 24 | 1 | effective address = 24 ... ... so, when the PC points to 12: 40 (that is, the contents of location 12) is interpreted as an opcode 24 (that is, the contents of location 13) is interpreted as an address 1 (that is, the contents of location 24) is interpreted as data note that there are no tags or other indicators that the number 40 in location 12 has to be an opcode; it could just as well be used as an address or as data immediate addressing assembly lang. memory hardware actions -------------- ------ ---------------- ... ... add_immediate(1) 12 | 41 | acc <- acc + 1 13 | 1 | ... ... no additional memory fetch for data beyond the instruction fetch (since the instruction contains the data being used) since an add must have different hardware actions than an add_immediate, add_immediate has to be a different opcode (or there has to be an extra type-of-addressing-mode code in the instruction format to go along with the opcode) indirect addressing assembly lang. memory hardware actions -------------- ------ ---------------- ... ... add_indirect(ptr) 12 | 42 | acc <- acc + memory[memory[36]] 13 | 36 | = acc + memory[24] ... ... = acc + 1 word(one,1) 24 | 1 | ... ... effective address = 24 word(ptr,one) 36 | 24 | ... ... the address included in the instruction is that of a pointer, that is, a word that holds another address indexed addressing assembly lang. memory hardware actions -------------- ------ ---------------- ... ... add_indexed(b0,x) 12 | 43 | acc <- acc + memory[20+memory[36]] 13 | 20 | = acc + memory[20+4] 14 | 36 | = acc + memory[24] ... ... = acc + 1 word(b0,5) 20 | 5 | word(b1,-2) 21 | -2 | effective address = 24 word(b2,3) 22 | 3 | word(b3,9) 23 | 9 | word(b4,1) 24 | 1 | ... ... word(x,4) 36 | 4 | ... ... on machines with multiple registers, addresses and index values can be held in registers