Addressing Modes for TI TMS320C54xModule by: Douglas L. Jones, Swaroop Appadwedula, Matthew Berry, Mark Haun, Dima Moussa, Daniel Sachs. E-mail the authors
Summary: The TI TMS320C54x microprocessor provides a number of ways to specify the location of data to be used in calculations. Immediate addressing, direct addressing, and indirect addressing are the three main types. Knowing the basic addressing modes of a microprocessor is important because they map directly into assembly language syntax and because the need to use a particular addressing mode often dictates which instruction one picks for a given task.
Microprocessors provide a number of ways to specify the location of data to be used in calculations. For example, one of the data values to be used in an add instruction may be encoded as part of that instruction's opcode, the raw machine language produced by the assembler as it parses your assembly language program. This is known as immediate addressing. Alternatively, perhaps the opcode will instead contain a memory address which holds the data (direct addressing). More commonly, the instruction will specify that an auxiliary register holds the memory address which in turn holds the data (indirect addressing). The processor knows which addressing mode is being used by examining special bit fields in the instruction opcode.
Knowing the basic addressing modes of your microprocessor is important because they map directly into assembly language syntax. Many annoying and sometimes hard-to-find bugs are caused by inadvertently using the wrong addressing mode in an instruction. Also, in any assembly language, the need to use a particular addressing mode often dictates which instruction one picks for a given task.
Chapter five, Data Addressing, in the CPU and Peripherals [link] reference contains extended descriptions of most of the addressing modes described below.
Accumulators: src, dstWhenever the abbreviations src or dst are used in the assembly language syntax description for an instruction, it means that only the accumulators A and B may be used for that particular operand. These are seen everywhere, but two classic examples are ld, which always loads data into an accumulator from somewhere else, and sth/stl, which always store data from an accumulator to somewhere else.Examples: ld *AR5,A ; sets A = (contents of memory location pointed to by AR5) sth B,*AR7+ ; sets (contents of memory location pointed to be AR7) = B, ; and then increments AR7 by one
Memory-mapped Registers: MMR, MMRx, MMRyMany of the TMS320C54x registers are memory-mapped, meaning that they occupy real addresses at the low end of data memory space. The most commonly used of these are the auxiliary registers AR0 through AR7. Whenever the abbreviation MMR is used in the assembly language syntax description for an instruction, it means that any memory-mapped register may be used for that particular operand. Only eight instructions use memory-mapped register addressing: ldm, mvdm, mvmd, mvmm, popm, pshm, stlm, and stm. With mvmm, since the instruction accepts two memory-mapped register operands, MMRx and MMRy, only AR0-AR7 and SP may be used.Do not use an asterisk in front of ARx variables here, since this is not indirect addressing.
Examples: mvmm AR3,AR5 ; sets AR5 = AR3 stm #5,AR2 ; sets AR2 = 5 ldm AR0,A ; sets A = AR0
Immediate Addressing: #k3, #k5, K, #k9, #lkImmediate addressing means that the numerical value of the data is itself provided within the assembly instruction. Various TMS320C54x instructions allow immediate data of 3, 5, 8, 9, or 16 bits in length, which are signified in the assembly language syntax descriptions with one of the above symbols. The 16-bit form is the most common and is signified by #lk. 16-bit immediate values always require an extra instruction word and therefore take an extra machine cycle to execute.An immediate data operand is almost always specified in assembler syntax by prepending a pound sign (#) to the data. Depending on the context, the assembler may assume that you meant immediate addressing anyway.
Examples: ld #0,A ; sets A = 0 cmpm AR1,#1 ; sets flag TC = 1 if AR1 == 1; else TC = 0
Labels make this more complicated. Recall that a label in your assembly code is nothing more than shorthand for the memory address where the labeled code or data is stored. So does an instruction like stm coef,AR2 ; sets AR2 = memory address of label coef
mean to store the contents of memory location coef in AR2, or does it mean to store the memory address coef itself in AR2? The second interpretation is correct. Because the stm instruction has only one form, expecting a #lkimmediate operand, the assembler does not care whether the label is prefixed with a pound sign or not. Still, it would have been better for us to include the pound sign in the above example for clarity.
Many instructions have several versions allowing the use of different addressing modes (see ld for a good example of this). With these instructions, including the pound sign is not optional when specifying immediate addressing. The only safe rule, then, is always to prefix the label with a pound sign if you wish to specify the memory address of the label and not the contents of that address.
If you are not sure how a particular instruction has been assembled, you can always examine the .lst file produced by the assembler, and compare the hexadecimal opcodes listed to the left of the assembly instructions with the assembly opcodes given in the assembly language manual (Chapter 4 of the Mnemonic Instruction Set [link] reference).
Direct Addressing: Smem and othersIn the modes called direct addressing by TI, the instruction opcode contains a memory offset (see the "dma" bits on page 5-8 of the CPU and Peripherals [link] reference) seven bits long, which is combined with either the DP (data pointer) or SP (stack pointer) register to obtain a complete 16-bit data-memory address. This divides the data memory into pages of 128 words each.SP is initialized for you in the core file and should not need to be modified. SP-referenced direct addressing is used by the pshd, pshm, popd, and popm instructions for stack manipulation, as well as by all subroutine calls and returns, which save program addresses on the stack.
DP-referenced direct addressing is available wherever you see the Smem abbreviation in an assembly syntax description. The advantage of DP-referenced addressing over the *(lk) form described in the next section is that DP-referenced addressing will not add an extra instruction word (and corresponding extra machine cycle). The disadvantage is that it is limited to 128 words of contiguous memory, and you have to make sure that DP points to the right 128 words. DP may be changed with the ld instruction as needed.
Examples: ld 10,A ; sets A = (contents of memory location DP + 10) add 6,B ; sets B = B + (contents of memory location DP + 6)
NOTE:Make sure you understand that the numbers 10 and 6 above are interpreted as memory addresses, not data values. To get data values, you would need to use a pound sign in front of the numbers. Absolute Addressing: dmad, pmad, *(lk)/SmemThis seems to be TI's term for all the forms of direct addressing which it does not call direct addressing! It is represented in assembly-instruction syntax-definitions using one of the above abbreviations (*(lk) addressing is available when the syntax definition says Smem). dmaddmad (Data Memory ADdress) operands are used by mvxxdata move instructions and represent 16-bit memory addresses in data memory whose contents are used in the instruction.Example: f3ptr .word 0 ; reserve one word of storage; initialize to 0 . . . . mvdm f3ptr,AR4 ; set AR4 = memory address of f3ptr
pmadpmad (Program Memory ADdress) operands are used by the firs, macd, macp, mvdp, and mvpd instructions, as well as all subroutine calls and branching instructions. They represent 16-bit addresses in program memory whose contents are used in the instruction, or jumped to in the case of branch instructions. Other than subroutine calls and branches, the most common use of a pmad is for the firs instruction.Example: firs *AR3+,*AR4+,coefs
NOTE:coefs is a label in the program section of the code, not the data section. *(lk)*(lk) addressing is a syntactic oddity. The asterisk symbol generally means that indirect addressing is being used (see below), but this is actually direct addressing with a 16-bit data memory address encoded in the instruction's last word. The reason for the asterisk is that TI does set the "I" bit in the opcode, usually denoting indirect addressing, and this form can only be used when an Smem is called for in the assembly syntax. Other bits in the low byte of the first instruction word tell the processor that the "*(lk) exception" is to be used, and to fetch the memory address in the next word (see the MOD bits on page 5-10 of the CPU and Peripherals [link] reference). You can easily recognize this addressing mode in .lst files because the low byte of the first instruction word always equals F8h.Examples: hold .word 1 ; reserve one word of storage and initialize to 1 count .word 0 ; reserve one word of storage and initialize to 0 . . . . ld *(count),B ; sets B = 0 (assuming memory was not changed) st T,*(hold) ; sets (storage location at address hold) = T
Indirect Addressing: Smem, Xmem, YmemIndirect addressing on the TMS320C54x always uses the auxiliary registers AR0 through AR7 and comes in two basic flavors. These are easily recognized from the assembly language syntax descriptions as either Smem orXmem/Ymem. SmemIn Smem indirect addressing, only one indirect address is used in the instruction and a number of variations is possible (see the table on page 5-13 of the CPU and Peripherals [link] reference). An asterisk is always used, which signifies indirect addressing. Any of the registers AR0-AR7 may be used, with optional modifications: automatic post-decrement by one, pre- and post-increment by one, post-increment and post-decrement by n (n being stored in AR0), and more, including many options for circular addressing (which automatically implements circular buffers) and bit-reversed addressing (which is useful for FFTs). Xmem/YmemXmem/Ymem indirect addressing is generally used in instructions that need two different indirect addresses, although there are a few instances where an Xmem by itself is specified in order to save bits in the opcode for other options. In Xmem/Ymem indirect addressing, fewer bits are used to encode the option modifiers in the opcode; hence, fewer options are available: post-increment by one, post-decrement by one, and post-increment by AR0with circular addressing.Examples: stl B,*AR6 ; sets (contents of location pointed to by AR6) = low word of B stl B,*AR6+0% ; sets (contents of location pointed to by AR6) = low word of B, ; then increments AR6 with circular addressing mar *+AR3(-6) ; decrements AR3 by 6 (increment by -6)
NOTE:The mar (modify address register) instruction is unusual in the sense that it takes an Smem operand but does nothing with the data pointed to by the ARx register. Its purpose is to perform any of the allowed register modifications discussed above without having to do anything else. This is often handy when you are using an Xmem/Ymem-type instruction but need to do an ARx modification that is only allowed with an Smem-type operand. SummaryThe ld instruction is illustrative of the many possible addressing modes which can be selected with the proper choice of assembly language syntax: ld #0,A ; immediate data: sets A = 0 ld 0,A ; DP-referenced direct: sets A = (contents of the address DP + 0) ld mydata,A ; DP-referenced direct: sets A = (contents of the address ; DP + lower seven bits of mydata) ld #mydata,A ; immediate data: sets A = 16 bit address mydata ld *(mydata),A ; *(lk) direct: sets A = (contents of the 16 bit address mydata) ld B,A ; accumulator: sets A = B ld *AR1+,A ; indirect: sets A = (contents of address pointed to by AR1), ; and afterwards increments AR1 by one ldm AR2,A ; memory-mapped register: sets A = AR2addressing modes helps the programmer to store or retrieve the data which is stored in any part of the data memory by addressing mode specified in the program.
Data can be accessed from memory by using the addressing modes, 8085 has 5 addressing modes namely,1. Immediate addressing mode 2. register addressing mode 3. direct addressing mode 4. indirect addressing mode 5. implied addressing mode
The 8086 microprocessor supports several data addressing modes, including immediate, direct, indirect, indexed, and based addressing modes. In immediate addressing, the operand is specified directly in the instruction. Direct addressing involves providing the memory address of the operand. Indirect addressing uses a pointer in a register to reference the operand's memory location, while indexed addressing combines a base address with an offset from an index register. Additionally, based addressing uses a base register to locate the operand in memory.
An addressing machine is a type of computational device or system that uses specific addressing schemes to access and manage data within a memory structure. These machines utilize various addressing modes to locate and retrieve information efficiently, allowing for effective data manipulation and processing. Addressing machines are foundational in computer architecture, enabling the execution of programs and operations by directing how and where data is stored and accessed.
Different Addressing modes are: 1. Direct Addressing Mode 2. Indirect Addressing Mode 3. Immediate Addressing Mode 4. Register Addressing Mode 5. Implicit Addressing Mode Immediate addressing Data is present in the instruction. Load the immediate data to the destination provided. Example: MVI R,data Register addressing Data is provided through the registers. Example: MOV Rd, Rs Direct addressing Used to accept data from outside devices to store in the accumulator or send the data stored in the accumulator to the outside device. Accept the data from the port 00H and store them into the accumulator or Send the data from the accumulator to the port 01H. Example: IN 00H or OUT 01H Indirect Addressing This means that the Effective Address is calculated by the processor. And the contents of the address (and the one following) is used to form a second address. The second address is where the data is stored. Note that this requires several memory accesses; two accesses to retrieve the 16-bit address and a further access (or accesses) to retrieve the data which is to be loaded into the register.
The addressing modes in the 8086 microprocessor provide flexibility in accessing data by allowing various ways to specify the operands for instructions. This enables programmers to efficiently use memory by accessing data directly, indirectly, or using offsets, which can simplify code and reduce the number of instructions needed. Additionally, different addressing modes facilitate the manipulation of data structures, such as arrays and records, enhancing the overall versatility and power of the microprocessor.
The advantage of indirect and indexed addressing modes lies in their flexibility and efficiency for accessing data. Indirect addressing allows for dynamic memory access by using a pointer to the memory location, enabling easier management of data structures like arrays and linked lists. Indexed addressing, on the other hand, facilitates accessing elements within data structures by combining a base address with an offset, making it efficient for iterating through arrays and performing calculations with varying data sizes. Together, these addressing modes enhance program versatility and can lead to more efficient memory usage.
Indirect addressing modes can introduce limitations in terms of speed and complexity. Accessing data requires an additional memory fetch to retrieve the address before the actual data can be accessed, which can slow down performance. Additionally, managing multiple levels of indirection can complicate the programming model and increase the potential for errors, such as dereferencing invalid pointers.
There can be two modes in a data set. For example, in the data set {0,1,2,3,3,4,5,5,9}, there are two modes: 3 and 5.
Implicit addressing modes are of the assumption that the data is in predefined registers. also Known as Zero address instructions: Eg: XLAT ; assumes the operands in AX and BX AAM ;operates on the contents of AX only
Are computers better data processors than humans
Yes, a set of data can have two modes. It is called bimodal.