This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:multiasm:cs:chapter_3_10 [2025/01/07 22:06] – [Data addressing] ktokarz | en:multiasm:cs:chapter_3_10 [2025/01/09 08:19] (current) – [Program control flow destination addressing] ktokarz | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| ===== 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, | Instructions which reach the data have the possibility of specifying the data placement. The data is an argument of the instruction, | ||
| - | As in this part of the book the reader doesn' | + | As in this part of the book the reader doesn' |
| < | < | ||
| copy b, a | copy b, a | ||
| </ | </ | ||
| - | **Register operand** is used where the data which the processor wants to reach is stored or is intended to be stored in the register. If we assume that //a// and //b// are both registers named //R0// and //R1// the instruction for copying data from //R0// to // | + | |
| + | **Register operand** is used where the data which the processor wants to reach is stored or is intended to be stored in the register. If we assume that //a// and //b// are both registers named //R0// and //R1// the instruction for copying data from //R0// to // | ||
| < | < | ||
| copy R1, R0 | copy R1, R0 | ||
| </ | </ | ||
| + | |||
| + | <figure addrregister> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| **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. | ||
| Line 18: | Line 24: | ||
| copy R1, 5 | copy R1, 5 | ||
| </ | </ | ||
| + | |||
| + | <figure addrimmediate> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| **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 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 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: | ||
| Line 23: | Line 34: | ||
| copy R1, var | copy R1, var | ||
| </ | </ | ||
| + | |||
| + | <figure addrdirect> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| **Indirect memory operand** is accessed by specifying the name of the register which value represents the address of the memory location to reach. | **Indirect memory operand** is accessed by specifying the name of the register which value represents the address of the memory location to reach. | ||
| Line 29: | Line 45: | ||
| </ | </ | ||
| + | <figure addrindirect> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | **Variations of indirect addressing**. The indirect addressing mode can have many variations where the final address doesn' | ||
| + | < | ||
| + | copy R1, table[R0] | ||
| + | </ | ||
| + | |||
| + | <figure addrindex> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | Addressing mode with pre-decrementation (decrementing before instruction execution) could look like this: | ||
| + | < | ||
| + | copy R1, table[--R0] | ||
| + | </ | ||
| + | |||
| + | Addressing mode with post-incrementation (incrementing after instruction execution) could look like this: | ||
| + | < | ||
| + | copy R1, table[R0++] | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ===== 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. | ||
| + | |||
| + | **Direct addressing** of the destination is similar to direct data addressing. It specifies the destination address as the constant value, usually represented by the 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//: | ||
| + | < | ||
| + | jump destin | ||
| + | </ | ||
| + | |||
| + | <figure jumpdirect> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | **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//: | ||
| + | < | ||
| + | jump [R0] | ||
| + | </ | ||
| + | |||
| + | <figure jumpindirect> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | ===== 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 " | ||
| + | <figure addrabsolute> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | Absolute addressing is simple and doesn' | ||
| + | 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' | ||
| - | ===== Program flow destination | + | <figure addrrelative> |
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | Relative addressing is also implemented in many jump, branch or loop instructions. | ||