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 [2026/01/10 20:18] pczekalskien:multiasm:cs:chapter_3_10 [2026/03/01 14:14] (current) – [Program control flow destination addressing] ktokarz
Line 20: Line 20:
  
 **An immediate operand** is a constant or the result of a constant expression. The assembler encodes immediate values into the instruction at assembly time. The operand of this type can be only one in the instruction and is always at the source place in the operands list. **An immediate operand** is a constant or the result of a constant expression. The assembler encodes immediate values into the instruction at assembly time. The operand of this type can be only one in the instruction and is always at the source place in the operands list.
-Immediate operands are used to initialise the register or variable, as numbers for comparison. An immediate operand, as it's encoded in the instruction, is placed in code memory, not in data memory and can't be modified during software execution. Instruction which initialises register //R1// with the constant (immediate) value of //5// looks like this:+Immediate operands are used to initialise the register or variable, as numbers for comparison. An immediate operand, as it's encoded in the instruction, is placed in code memory, not in data memory and can't be modified during software execution. It is shown in Fig {{ref>addrimmediate}}. Instruction which initialises register //R1// with the constant (immediate) value of //5// looks like this:
 <code> <code>
  copy R1, 5  copy R1, 5
Line 30: Line 30:
 </figure> </figure>
  
-**A direct memory operand** specifies the data at a given address. An address can be given in numerical form or as the name of the previously defined variable. It is equivalent to a static variable definition in high-level languages. If we assume that the //var// represents the address of the variable, the instruction which copies data from the variable to //R1// can look like this:+**A direct memory operand** specifies the data at a given address. An address can be given in numerical form or as the name of the previously defined variable. It is equivalent to a static variable definition in high-level languages. If we assume that the //var// represents the address of the variable, the instruction which copies data from the variable to //R1// can look like in the following code and in Fig {{ref>addrdirect}}.
 <code> <code>
  copy R1, var  copy R1, var
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 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:+**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, visible in Fig {{ref>addrindirect}}, 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 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:+**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 speed up processing of tables. 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 in Fig {{ref>addrindex}}, and in the code example:
 <code> <code>
  copy R1, table[R0]  copy R1, table[R0]
Line 78: Line 78:
 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.  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, shown in Fig {{ref>jumpdirect}} and in the code, the program will jump to the label named //destin//:
 <code> <code>
  jump destin  jump destin
Line 88: Line 88:
 </figure> </figure>
  
-**Indirect addressing** of the destination uses the content of the register as the address where the program will jump. In the following example, the processor will jump to the destination address, which is stored in //R0//:+**Indirect addressing** of the destination, as shown in Fig {{ref>jumpindirect}} uses the content of the register as the address where the program will jump. In the following example, the processor will jump to the destination address, which is stored in //R0//:
 <code> <code>
  jump [R0]  jump [R0]
en/multiasm/cs/chapter_3_10.1768069087.txt.gz · Last modified: by pczekalski
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