Professional Documents
Culture Documents
0 Ses 5 Add
0 Ses 5 Add
• Variables declared under the .data directive are responsible for storing our data
• They are then operated on by the lines of code given under the .code directive
• This is a form of direct addressing in which we don’t make use of the integer constant (our data). Rather we store them as data in memory and
then access them from memory.
• Hence the second addressing mode we have examined is known as Direct Addressing. In
which the instruction is formed using a memory address. Please note that the memory
address is fixed.
x86 Addressing modes
• Under the .data directive we used a label to refer to a directive initializer with an
initial and second value(line 05).
• Under the .code directive we had the base register point to the first number’s
address (line 09). The data located at this address was then moved to ax, notice the
brackets around BX (line 10).
• We moved BX forward by 2 bytes (16-bits) as we are using directive initializer of
DW (line 11). Which allowed us to add the second number to ax (line 12).
• To see this program in action let’s take a look at the log file.
x86 Addressing modes
• Is there anyway to increase the efficiency of our code? Can we have the
same results with fewer lines of code?
• The answer is yes!
• We will need to make use of Register Indirect + offset Addressing.
• In this type of program addressing mode we do not alter the contents of our
base register when we want to refer to the next consecutive memory space
• Let’s see how this works:
x86 Addressing modes
• Under our .data directive we used a label to refer to a directive initializer with an
initial and second value(line 05).
• Under our .code directive we had the base register point to the first number’s
address (line 09). The data located at this address was then moved to AX, notice
the brackets around BX (line 10).
• Instead of moving BX forward and altering its contents, we used an offset of 2. This
gives us the next memory location, whose data we can access through indirect
referencing. Once accessed we add it to ax (line 11).
• Let’s see this program in action.
x86 Addressing modes
BX has been loaded with the address of our data. The data itself has been loaded in to AX
x86 Addressing modes
BX has been offset by 2. This does not change its contents but still gives us the next address and its
data. Which can then be added to AX giving us our solution.
Session Five
Lesson Plan
• If I were to execute the first two instructions my registers will look like this:
Data Transfer Instructions
• Finally when I run my XCHG instruction, my registers will look like this:
Summary
• Using the log we reviewed and your lecture notes. Create a program that
adds three 16-bit integers using Register Indirect Addressing.
• Modify your program to do the same using Register Indirect + Offset
Addressing.
Thanks
• Any questions?
• Feel free to reach out
• saqib.sadiq@szabist.pk