Page 74 - Computer_Science_F5
P. 74

Addressing modes                         Direct addressing
              In the  previous section,  we learned    The  instruction  specifies  a  memory
              about  the  instruction  cycle.  We  saw   address where the data is stored.         Chapter One: Computer architecture
              how instructions are fetched, decoded,
              and their operations are carried         Example (MIPS): lw $t2, 10($s0) (Loads
          FOR ONLINE READING ONLY
              out.  Addressing modes are  special      data from the memory location 10 bytes
              instructions that help the CPU find data.  away from the address in $s0 into $t2).


              Recall the kitchen-ISA analogy introduced   Indirect addressing
              at the beginning of this chapter. Imagine   The  instruction  specifies  a  memory
              you are a chef following a recipe (the   address that points to another memory
              program) in a kitchen (the CPU). The     location with the actual data.
              recipe tells you what ingredients (data)
              to use and what steps (instructions) to   Example (MIPS): lw $t4, ($s5) (Loads
              take. But how does the recipe tell you   data from the memory location pointed
              exactly where to find those ingredients?   to by the address in $s5 into $t4).
              This is where addressing modes come
              in – they are like special instructions   Relative addressing
              within instructions, telling the CPU     The instruction specifies an offset from
              how to locate the data it needs to work   the current instruction’s address.
              with. Common addressing modes are;
              register addressing, immediate addressing,   Example (MIPS): beq $t6, $s7, Label
              direct addressing, indirect addressing and   (Branches to “Label” if the values in $t6
              relative addressing.                     and $s7 are equal, using an offset relative
                                                       to the current instruction’s address).
              Register addressing

              Data is stored in registers within the       Exercise 1.14
              CPU, providing fast and efficient access.
              Example  (MIPS): add $t1,  $s2, $s3        Imagine  you are  a  programmer
              (Adds  values in registers $s2  and $s3,   working on a game engine for a
              storing the result in $t1).                mobile  racing game.  The game
                                                         uses  various data structures to store
              Immediate addressing                       information about the race track, car
              The instruction includes the actual data   physics, and player input. Answer the
              value.                                     following questions, considering the
                                                         most appropriate addressing mode
              Example (MIPS): addi $t0, $s1, 5 (Adds     (register, immediate,  direct,  indirect,
              5 to the value in register $s1, storing the   or relative)  for each scenario and
              result in $t0).                            explain your reasoning.


                                                     65
               Student’s Book  Form Five



     Computer Science Form 5.indd   65                                                      23/07/2024   12:32
   69   70   71   72   73   74   75   76   77   78   79