Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:multiasm:cs:chapter_3_10 [2025/12/10 14:43] – [Program control flow destination addressing] ktokarzen:multiasm:cs:chapter_3_10 [2026/01/10 20:18] (current) pczekalski
Line 1: Line 1:
 ====== Fundamentals of Addressing Modes ====== ====== Fundamentals of Addressing Modes ======
-Addressing Mode is the way in which the argument of an instruction is specified. The addressing mode defines a rule for interpreting the address field of the instruction before the operand is reached. Addressing mode is used in instructions which operate on the data or in instructions which change the program flow.+Addressing Mode is the way in which the argument of an instruction is specified. The addressing mode defines a rule for interpreting the address field of the instruction before the operand is reached. Addressing mode is used in instructions that operate on data or change the program flow.
  
 ===== Data addressing ===== ===== Data addressing =====
-Instructions which reach the data have the possibility of specifying the data placement. The data is an argument of the instruction, sometimes called an operand. Operands can be of one of the following: register, immediate, direct memory, or indirect memory. +Instructions that reach the data can specify the data placement. The data is an argument of the instruction, sometimes called an operand. Operands can be of one of the following: register, immediate, direct memory, or indirect memory. 
-As in this part of the book, the reader doesn't know any assembler instructions, we will use the hypothetical instruction //copy// that copies the data from the source operand to the destination operand. The order of the operands will be similar to high-level languages, where the left operand is the destination and the right operand is the source. Copying data from //a// to //b// will be done with an instruction as in the following example:+As in this part of the book, the reader doesn't know any assembler instructions, we will use the hypothetical instruction //copy//, which copies data from the source operand to the destination operand. The order of the operands will be similar to high-level languages, where the left operand is the destination and the right operand is the source. Copying data from //a// to //b// will be done with an instruction as in the following example:
 <code> <code>
  copy b, a  copy b, a
Line 40: Line 40:
 </figure> </figure>
  
-**Indirect memory operand** is accessed by specifying the name of the register whose value represents the address of the memory location to reach.  We can compare the indirect addressing to the pointer in high-level languages, where the variable does not store the value but points to the memory location where the value is stored. Indirect addressing can also be used to access elements of the table in a loop, where we use the index value, which changes every loop iteration, rather than a single address. Different assemblers have different notations of indirect addressing; some use brackets, some square brackets, and others //@// symbol. Even different assembler programs for the same processor can differ. In the following example, we assume the use of square brackets. The instruction which copies the data from the memory location addressed by the content of the //R0// register to //R1// register would look like this:+**Indirect memory operand** is accessed by specifying the name of the register whose value represents the address of the memory location to reach.  We can compare the indirect addressing to the pointer in high-level languages, where the variable does not store the value but points to the memory location where the value is stored. Indirect addressing can also be used to access elements of the table in a loop, where we use the index value, which changes every loop iteration, rather than a single address. Different assemblers use different notations for indirect addressing; some use brackets, others square brackets, and others the//@// symbol. Even different assembler programs for the same processor can differ. In the following example, we assume square brackets are used. The instruction which copies the data from the memory location addressed by the content of the //R0// register to //R1// register would look like this:
 <code> <code>
  copy R1, [R0]  copy R1, [R0]
Line 50: Line 50:
 </figure> </figure>
  
-**Variations of indirect addressing**. The indirect addressing mode can have many variations where the final address doesn't have to be the content of a single register, but rather the sum of a constant value with one or more registers. Some variants implement automatic incrementation (similar to the "++" operator) or decrementation ("- -") of the index register before or after instruction execution to make processing the tables faster. For example, accessing elements of the table where the base address of the table is named //data_table// and the register //R0// holds the index of the byte which we want to copy from a table to //R1// could look like this:+**Variations of indirect addressing**. The indirect addressing mode can have many variations in which the final address need not be the contents of a single register; it can be the sum of a constant and one or more registers. Some variants implement automatic incrementation (similar to the "++" operator) or decrementation ("- -") of the index register before or after instruction execution to make processing the tables faster. For example, accessing elements of the table where the base address of the table is named //data_table// and the register //R0// holds the index of the byte which we want to copy from a table to //R1// could look like this:
 <code> <code>
  copy R1, table[R0]  copy R1, table[R0]
Line 76: Line 76:
 ===== Program control flow destination addressing ===== ===== Program control flow destination addressing =====
  
-The operand of jump, branch, or function call instructions addresses the destination of the program flow control. The result of these instructions is the change of the Instruction Pointer content. Jump instructions should be avoided in structural or object-oriented high-level languages, but they are rather common in assembler programming. Our examples will use the hypothetic //jump// instruction with a single operand—the destination address. +The operand of jump, branch, or function call instructions addresses the destination of the program flow control. The result of these instructions is the change of the Instruction Pointer content. Jump instructions should be avoided in high-level structural or object-oriented languages, but they are common in assembler programming. Our examples will use the hypothetic //jump// instruction with a single operand—the destination address. 
  
 **Direct addressing** of the destination is similar to direct data addressing. It specifies the destination address as the constant value, usually represented by a name. In assembler, we define the names of the addresses in code as //labels//. In the following example, the code will jump to the label named //destin//: **Direct addressing** of the destination is similar to direct data addressing. It specifies the destination address as the constant value, usually represented by a name. In assembler, we define the names of the addresses in code as //labels//. In the following example, the code will jump to the label named //destin//:
Line 100: Line 100:
 ===== Absolute and Relative addressing ===== ===== Absolute and Relative addressing =====
  
-In all previous examples, the addresses were specified as the values which represent the **absolute** memory location. The resulting address (even calculated as the sum of some values) was the memory location counted from the beginning of the memory address "0". It is presented in Fig{{ref>addrabsolute}}.+In all previous examples, the addresses were specified as values representing the **absolute** memory location. The resulting address (even calculated as the sum of some values) was the memory location counted from the beginning of the memoryaddress "0". It is presented in Fig{{ref>addrabsolute}}.
  
 <figure addrabsolute> <figure addrabsolute>
Line 107: Line 107:
 </figure> </figure>
  
-Absolute addressing is simple and doesn't require any additional calculations by the processor. It is often used in embedded systems, where the software is installed and configured by the designer and the location of programs does not change. +Absolute addressing is simple and doesn't require any additional calculations by the processor. It is often used in embedded systems, where the software is installed and configured by the designerand the location of programs does not change. 
-Absolute addressing is very hard to use in general-purpose operating systems like Linux or Windows where the user can start a variety of different programs, and their placement in the memory differs every time they're loaded and executed. Much more useful is the **relative addressing** where operands are specified as differences from memory location and some known value which can be easily modified and accessed. Often the operands are provided relative to the Instruction Pointer which allows the program to be loaded at any address in the address space, but the distance between the currently executed instruction and the location of the data it wants to reach is always the same. This is the default addressing mode in the Windows operating system working on x64 machines. It is illustrated in Fig{{ref>addrrelative}}.+Absolute addressing is difficult to use in general-purpose operating systems like Linux or Windowswhere users can start a variety of programs, and their placement in memory varies each time they're loaded and executed. Much more useful is the **relative addressing**where operands are specified as differences from memory location and some known valuewhich can be easily modified and accessed. Oftenthe operands are provided relative to the Instruction Pointerwhich allows the program to be loaded at any address in the address space, but the distance between the currently executed instruction and the location of the data it wants to reach is always the same. This is the default addressing mode in the Windows operating systemworking on x64 machines. It is illustrated in Fig{{ref>addrrelative}}.
  
 <figure addrrelative> <figure addrrelative>
en/multiasm/cs/chapter_3_10.1765370631.txt.gz · Last modified: 2025/12/10 14:43 by ktokarz
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0