home | |||
links |
|
||
developer's mag main page article part 1 part 2 part 3 part 4 part 5 part 6 part 7 part 8 part 9 |
4 - LDT and CompanyIn the assembly function two new opcodes make their appearance, and we need to know what they do in order to understand the code. Actually macros, they make life easier for the programmer by hiding the complexities of the ldt command: ldc and ldo.From the last article, you'll remember that ldt loads a constant into the t register. If you've looked over the documentation, you've likely wondered how a one-byte instruction can fill a 32 bit register. It doesn't; at least, not by itself. The key is the K flag that figures so much in branching. The ldt instruction is actually 64 instructions; each version differs in the last 6 bits of its opcode. These 6 bits are the instruction's payload, and contain the constant data to place into the t register. Selecting the appropriate ldt instruction places the appropriate value into t. The ldt instruction exhibits two types of behavior, depending on whether the K flag is already set or not. Since the K flag is only set by ldt, this effectively means that the first ldt in a series acts differently from the second and any subsequent ldts. Simply put, the first ldt places 6 bits of its opcode into the t register, clearing the previous data, while each subsequent ldt simply shifts the t register and then appends its 6 bit payload. These first six bits are sign extended, so negative values are loaded properly. In the worst case, no more than 6 ldts are needed for the largest 32 bit number, and for smaller numbers like zero only a single ldt is needed. To make working with ldt easier, the ldc macro takes a constant value and synthesizes the appropriate ldts, thus saving you the headache of calculating. The ldo macro does a similar task, but for branches. Branch instructions need an offset calculated from the branch to the destination. The ldo macro can be used to generate this offset easily, and since it is placed just before the branch (remember the K flag needs to be set), it is always accurate. Previous Section Next Section |
||
Copyright © 2001-2006 ebmDevMag.com - Legal Notice |