How To Store Registers In Memory Locaions
Microprocessors, instrumentation and control
Charles J. Fraser , ... (Sections 3.5.1–3.5.8), in Mechanical Engineer's Reference Book (Twelfth Edition), 1994
3.2.5 Memory map
The memory locations in RAM and ROM, which the processor can address, must accommodate space for such requirements as system monitor and utilities, user software and input/output. The manufacturer of the microcomputer assigns an area of memory for each functional requirement and provides the necessary information in a system memory map.
In 8-bit systems, with 64K of addressable memory, the memory map is usually composed of 32K of RAM and 32K of ROM or EPROM. The ROM holds the operating system software and normally some space is available in EPROM form for user firmware. In addition to providing space for user programs, the RAM area contains the system stack and the visual monitor data storage. The I/O facilities are also assigned an area of memory in a memory mapped system.
In a 6502 or 6800 based system the RAM is usually low down in memory and the ROM is high up. A typical memory map is shown in Figure 3.3. The I/O is accommodated anywhere within the above structure and varies from one manufacturer to another.
The display screen RAM is often fitted with a moveable boundary in order to set variable resolution modes for graphics. Typically, the screen memory need only be IK for a text mode to give a 40 × 25 character display. This would be insufficient for computer graphics and a high resolution would require 20K of memory to MAP the screen. It should be noted that this greatly reduces the amount of RAM available to the user.
8080- and Z80-based systems have a distribution of memory similar to that as shown in Figure 3.3. The ROM, however, is usually low down and the RAM high up in the memory map. The 16-bit PCs, with a 20-bit address bus, have 1M byte of addressable memory with the RAM comprising the first three quarters and ROM occupying the last quarter. A general memory map showing the distribution of RAM/ROM for a PC is given in Figure 3.4.
A familiarity with the memory map of the system to be used in any data-acquisition application is essential, since it indicates the areas reserved for the operating system. The programmer can then knowledgeably determine the locations available for data storage and machine-code programs.
Read full chapter
URL:
https://www.sciencedirect.com/science/article/pii/B9780750611954500075
Instruction Usage Examples
Joseph Yiu , in The Definitive Guide to the ARM Cortex-M0, 2011
Simple Data Accesses
Normally the memory locations (physical addresses) of software variables are defined by the linker. However, we can write the software code to access to the variables as long as we know the symbol of the variables. For example, if we need to calculate the sum of an integer array " DataIn" with 10 elements (32-bit each) and put the result in another variable called "Sum" (also 32-bit), we can use the following assembly code:
-
LDR r0,=DataIn; Get the address of variable 'DataIn'
-
MOVS r1, #10 ; loop counter
-
MOVS r2, #0 ; Result - starting from 0
-
-
add_loop
-
LDM r0!,{r3} ; Load result and increment address
-
ADDS r2, r3 ; add to result
-
SUBS r1, #1 ; increment loop counter
-
BNE add_loop
-
LDR r0,=Sum ; Get the address of variable 'Sum'
-
STR r2,[r0] ; Save result to Sum
-
In the preceding example, we use the LDM instruction rather than a normal LDR instruction. This allows us to read the memory and increment the address to the next array element at the same time.
When using assembly to access data, we need to pay attention to a few things:
- •
-
Use correct instruction for corresponding data size. Different instructions are available for different data sizes.
- •
-
Make sure that the access is aligned. If an access is unaligned, it will trigger a fault exception. This can happen if an instruction of incorrect data size is used to access a data.
- •
-
Various addressing modes are available and can simplify your assembly codes. For example, when programming/accessing a peripheral, you can set a register to its base address value and then use an immediate offset addressing mode for accessing each register. In this way, you do not have to set up the register address every time a different register is accessed.
Read full chapter
URL:
https://www.sciencedirect.com/science/article/pii/B9780123854773100060
Microcomputer Buses and Links
J.D. Nicoud , in Encyclopedia of Physical Science and Technology (Third Edition), 2003
I.D Special Cycles
Frequently, consecutive memory locations must be transferred over the bus. Moving the address once and incrementing a counter on the memory are more efficient than sending the address each time, especially if the bus is multiplexed. Block transfers are supported by the most complex buses and are available with limitations on the most recent 32-bit microprocessors.
Reading from many devices simultaneously is called broadcall. This costs additional bus lines and transfer time and is not frequently implemented.
Combined cycles are possible. Read–modify–write cycles are interesting in multiprocessor systems. Read-after-write cycles are never implemented because one has confidence in what has been written.
Finally, split cycles are a way of having only write cycles in the system. In order to read some information, one writes a read request and waits. The slave interrupts the master to get its information read, and the process may continue. This is useful when the slave, for example, a disk interface, transfers blocks of data and is slow: It would be inefficient to wait for an acknowledge.
Read full chapter
URL:
https://www.sciencedirect.com/science/article/pii/B0122274105004397
Memory Systems
Joseph Yiu , in The Definitive Guide to the ARM Cortex-M3 (Second Edition), 2010
5.2 Memory Maps
The Cortex-M3 processor has a fixed memory map (see Figure 5.1 ). This makes it easier to port software from one Cortex-M3 product to another. For example, components described in previous sections, such as Nested Vectored Interrupt Controller (NVIC) and Memory Protection Unit (MPU), have the same memory locations in all Cortex-M3 products. Nevertheless, the memory map definition allows great flexibility so that manufacturers can differentiate their Cortex-M3-based product from others.
Some of the memory locations are allocated for private peripherals such as debugging components. They are located in the private peripheral memory region. These debugging components include the following:
- •
-
Fetch Patch and Breakpoint Unit (FPB)
- •
-
Data Watchpoint and Trace Unit (DWT)
- •
-
Instrumentation Trace Macrocell (ITM)
- •
-
Embedded Trace Macrocell (ETM)
- •
-
Trace Port Interface Unit (TPIU)
- •
-
ROM table
The details of these components are discussed in later chapters on debugging features.
The Cortex-M3 processor has a total of 4 GB of address space. Program code can be located in the code region, the Static Random Access Memory (SRAM) region, or the external RAM region. However, it is best to put the program code in the code region because with this arrangement, the instruction fetches and data accesses are carried out simultaneously on two separate bus interfaces.
The SRAM memory range is for connecting internal SRAM. Access to this region is carried out via the system interface bus. In this region, a 32-MB range is defined as a bit-band alias. Within the 32-bit‑band alias memory range, each word address represents a single bit in the 1-MB bit-band region. A data write access to this bit-band alias memory range will be converted to an atomic READ-MODIFY-WRITE operation to the bit-band region so as to allow a program to set or clear individual data bits in the memory. The bit-band operation applies only to data accesses not instruction fetches. By putting Boolean information (single bits) in the bit-band region, we can pack multiple Boolean data in a single word while still allowing them to be accessible individually via bit-band alias, thus saving memory space without the need for handling READ-MODIFY-WRITE in software. More details on bit-band alias can be found later in this chapter.
Another 0.5-GB block of address range is allocated to on-chip peripherals. Similar to the SRAM region, this region supports bit-band alias and is accessed via the system bus interface. However, instruction execution in this region is not allowed. The bit-band support in the peripheral region makes it easy to access or change control and status bits of peripherals, making it easier to program peripheral control.
Two slots of 1-GB memory space are allocated for external RAM and external devices. The difference between the two is that program execution in the external device region is not allowed, and there are some differences with the caching behaviors.
The last 0.5-GB memory is for the system-level components, internal peripheral buses, external peripheral bus, and vendor-specific system peripherals. There are two segments of the private peripheral bus (PPB):
- •
-
Advanced High-Performance Bus (AHB) PPB, for Cortex-M3 internal AHB peripherals only; this includes NVIC, FPB, DWT, and ITM
- •
-
Advance Peripheral Bus (APB) PPB, for Cortex-M3 internal APB devices as well as external peripherals (external to the Cortex-M3 processor); the Cortex-M3 allows chip vendors to add additional on-chip APB peripherals on this private peripheral bus via an APB interface
The NVIC is located in a memory region called the system control space (SCS) (see Figure 5.2). Besides providing interrupt control features, this region also provides the control registers for SYSTICK, MPU, and code debugging control.
The remaining unused vendor-specific memory range can be accessed via the system bus interface. However, instruction execution in this region is not allowed.
The Cortex-M3 processor also comes with an optional MPU. Chip manufacturers can decide whether to include the MPU in their products.
What we have shown in the memory map is merely a template; individual semiconductor vendors provide detailed memory maps including the actual location and size of ROM, RAM, and peripheral memory locations.
Read full chapter
URL:
https://www.sciencedirect.com/science/article/pii/B9781856179638000089
Computers and their application
Ian Robertson , in Mechanical Engineer's Reference Book (Twelfth Edition), 1994
4.7.12.1 Data transfer
This loads an accumulator from a specified memory location and writes the contents of the accumulator into a specified memory location. Most CPUs have variations such as adding contents of memory location to the accumulator and exchanging the contents of the accumulator and memory locations.
CPUs with multiple registers also have some instructions which can move data to and from these registers, as well as the accumulator. Those with 16-bit or greater word lengths may have versions of these and other instruction types which operate on bytes as well as words.
With a double operand addressing mode (see Section 4.7.8) a generalized 'Move' instruction allows the contents of any memory location or register to be transferred to any other memory location or register.
Read full chapter
URL:
https://www.sciencedirect.com/science/article/pii/B9780750611954500087
Instruction sets
Theresa Schousek , in The Art of Assembly Language Programming Using PIC© Technology, 2018
Indirect
Indirect addressing is where the memory location of the address is stored in the location specified by the instruction. This is one step removed from direct addressing. Indirect addressing is where the memory location's address, not value, is then specified by the instruction's operand. This is referred to as one level of indirection. If the location of the address is further contained in the memory location's address, then this is considered two levels of indirection. In theory, this can be continued indefinitely.
-
For example, from page 19 in the data sheet, the code first initializes the pointer to 0x10.
-
MOVLW 0x10
-
MOVWF FSR
-
Then, the INDF is cleared and the pointer is incremented for the next instruction in a loop.
-
CLRF INDF
-
INCF FSR,F
Read full chapter
URL:
https://www.sciencedirect.com/science/article/pii/B9780128126172000031
Number systems
A.C. Fischer-Cripps , in Newnes Interfacing Companion, 2002
2.1.6 Signed numbers
An 8-bit memory location can cover the range of decimal integers from 0 to 255. To enable an 8-bit memory location to hold both positive and negative numbers, the most significant bit (msb) is reserved and is called the sign bit. A sign bit = 1 indicates a negative number. A sign bit = 0 indicates a positive number. The other 7-bit positions are used to represent the magnitude of the number – but the way of doing this is different for positive and negative numbers.
1. Positive numbers: The remaining 7-bit positions represent the magnitude of the number directly. 7 bits give a range 0 to +127. | 2. Negative numbers are represented in 2's complement notation. Example: −40 is: | ||||||||
0 0 1 0 1 0 0 0 |
| ||||||||
0 msb indicates a positive number. The magnitude of the number is 23 + 24 = 40. | The sign bit (msb) indicates a negative number. |
Whether or not a particular binary bit pattern represents a signed or unsigned number depends on the context in which it is being used. For binary numbers starting with 0, there is no confusion since they have the same value whether they are signed or unsigned numbers. For numbers starting with 1, they may be interpreted as an unsigned integer or the 2's complement representation of a negative number.
For signed number representation, the range that can be covered by 8 bits is −128 to +127. Signed positive binary numbers roll over to represent negative numbers after +127.
The +1 step in finding the 2's complement takes into account ±0 possibilities (i.e. 1's complement goes from −127 to −0, and +0 to +127).
Read full chapter
URL:
https://www.sciencedirect.com/science/article/pii/B978075065720450108X
Microcomputer Instrumentation and Control
William B. Ribbens , in Understanding Automotive Electronics (Eighth Edition), 2017
Addressing Peripherals
The reason for distinguishing between memory locations and peripherals is that they perform different functions. Memory is a data storage device, while peripherals are input/output devices. However, many microcomputers address memory and peripherals in the same way because they use a design called memory-mapped I/O (input/output). With this design, peripherals, such as data terminals, are equivalent to memory to the CPU so that sending data to a peripheral is as simple as writing data to a memory location. In systems where this type of microcomputer has replaced some digital logic, the digital inputs enter the computer through a designated memory slot. If outputs are required, they exit the computer through another designated memory slot.
The relatively efficient means of input/output of data via memory map facilitates operations such as digital filtering of sampled analog signals or for control operations as explained in Appendix B. In such cases, the A/D converter providing the sampled input would have a specific memory location. Similarly, any D/A or ZOH (see Chapter 2) would also have a designated memory location. Such memory-mapped I/O is particularly helpful for speeding computer operations in discrete time control for automotive systems.
Read full chapter
URL:
https://www.sciencedirect.com/science/article/pii/B978012810434700003X
Beginning code
Theresa Schousek , in The Art of Assembly Language Programming Using PIC© Technology, 2018
Elementary Programs
ACC Convention
Within mathematical routines, there is a general consensus that data memory uses the convention of leading variable names with "ACC" to indicate accumulators. For example, ACCaLO and ACCaHI are used to indicate data memory uses "a" with two words indicated as "LO" or "HI" as LO byte and HI byte, respectively.
The following, allocation of variable memory locations, allows the programmer to use variable names instead of specific address names. The variables begin in location 0x40 or, interchangeably, 40h.
Label | Opcode | Operands | Comments |
---|---|---|---|
Start | CBLOCK | 0x40 | |
ACCaLO, ACCaHI, ACCbLO, ACCbHI | ;Allocation of Variable ;Memory Locations | ||
ACCcLO, ACCcHI, ACCdLO, ACCdHI | |||
End |
8-Bit Data Transfer
-
Data transfer is the transfer of a byte of data; copying of a memory location to a second memory location. The MOVE instructions are used to move contents from one memory location to another. This is similar to other processors' Load and Store commands.
-
Problem: Copy the contents of memory location 40h to location 41h.
-
Test Case: (0040h) = 5B
-
Result: (0041h) = 5B
Solution:
Label | Opcode | Operands | Comments |
---|---|---|---|
MOVF | 40h, 0 | ;(40h) ➔ W | |
MOVWF | 41h | ;W ➔ (41h) | |
RETLW | 00h | ;Clear W register & return |
Note that we are accessing base page 00 in memory, even though leading zeros have been omitted in the solution. MOVF 40h, 0 could more explicitly show this with MOVF 0040h, 0. The option 0, following the address, indicates that the W register is used. Your program may use "W" in place of 0 if it is declared at the beginning of the program.
The solution ends with RETLW, to return control back to the calling function. Alternatively, a GOTO $ command indicates you are to GOTO the same line as you are already on. The GOTO may be used to place the code in an infinite loop.
16-Bit Data Transfer
-
Move the contents of 40h, most significant byte (MSB) and 41h, least significant byte (LSB) into 42h (MSB) and 43h (LSB). The MOVE instructions are used to move contents from one memory location to another.
-
Problem: Copy the contents of memory location 40h to location 42h. Copy the contents of memory location 41h to location 43h.
-
Test Case: (0040) = 5B
-
(0041) = 6E
-
Result: (0042) = 5B
-
(0043) = 6E
-
Solution:
Label | Opcode | Operands | Comments |
---|---|---|---|
MOVF | 40h, 0 | ;Get MSB in 40h ➔ W | |
MOVWF | 42h | ;W ➔ 42h | |
MOVF | 41h, 0 | ;Get LSB in 41h ➔ W | |
MOVWF | 43h | ;W ➔ 43h | |
RETLW | 00h | ;Clear W register & return |
8-Bit Addition
-
The Addition instructions are used to add two operands, in this problem, (ACCaLO) and (ACCbLO). The result is to store and, therefore, overwrite the second operand. Can you see the negative side to this approach? If you are testing the code, you will need to always reenter the initial value of ADDbLO.
-
Problem: Add the contents of two memory locations, 0040 and 0041. Place the result in memory location 0041.
-
Test Case: (0040h) = 27h
-
(0041h) = 1Ah
-
Result: (0041h) = 41h
-
Solution:
Label | Opcode | Operands | Comments |
---|---|---|---|
MOVF | 40h, 0 | ;(40h) ➔W | |
MOVWF | 41h | ;W ➔ (41h) | |
RETLW | 00h | ;Clear W register & return |
8-Bit Subtraction
-
The Subtraction instruction is used to subtract one operand from another. In this problem, (ACCaLO) is subtracted from (ACCbLO). The result is in memory location ACCbLO.
-
Problem: Subtract the contents of memory location ACCaLO from location ACCbLO. Place the result in memory location ACCbLO.
-
Test Case: (ACCaLO) = 27h
-
(ACCbLO) = 1Ah
-
Result: (ACCbLO) = 0Dh
-
Solution:
Label | Opcode | Operands | Comments |
---|---|---|---|
MOVF | ACCaLO,0 | ;ACCaLO ➔W | |
SUBWF | ACCbLO,1 | ;Subtract W from ACCbLO and store in ACCbLO | |
RETLW | 00h | ;Clear W register & return |
8-Bit Multiply by Two (Rotate Left 1 Bit)
-
This example illustrates the rotation of ACCbLO as a one-byte operation. Rotate left through Carry places the most significant bit in the Carry position. Also, a zero is placed in the least significant bit position.
-
Problem: Multiply ACCbLO by two.
-
Test Case: (ACCbLO) = 5Eh = 01011110b
-
Result: (ACCbLO) = BCh = 10111100b Carry remains 0.
Solution:
Label | Opcode | Operands | Comments |
---|---|---|---|
RLF | ACCbLO,1 | ;Rotate Left Thru Carry | |
RETLW | 00h | ;Clear W register & return |
8-Bit Multiply by Four (Shift Left 2 Bits)
-
This example illustrates the rotation of ACCbLO as a one-byte operation. Rotate left through Carry places the most significant bit in the Carry position. Also, a zero is placed in the least significant bit position.
-
Problem: Multiply ACCbLO by four.
-
Test Case: (ACCbLO) = 5Eh = 01011110b
-
Result: (ACCbLO) = 78h = 01111000b Carry is 1.
Solution:
Label | Opcode | Operands | Comments |
---|---|---|---|
RLF | ACCbLO,1 | ;Rotate Left Thru Carry | |
RLF | ACCbLO,1 | ;Rotate Left Again Thru Carry (MSB, in Carry ;from first Opcode, will be truncated) | |
RETLW | 00h | ;Clear W register & return |
8-Bit Divide by Two (Rotate Right 1 Bit)
-
This example illustrates the right rotation of ACCbHI to perform a divide by two. The least significant bit is truncated.
-
Problem: Divide ACCbHI by two.
-
Test Case: (ACCbHI) = 5Eh = 01011110b
-
Result: (ACCbHI) = 2Fh = 00101111b
Solution:
Label | Opcode | Operands | Comments |
---|---|---|---|
RRF | ACCbHI,1 | ;Rotate Right Thru Carry and store result in file register ;ACCbHI, Note Carry is pulled into the MSB position | |
RETLW | 00h | ;Clear W register & return |
Mask Off Most Significant 4 Bits
-
Problem: Mask off most significant 4 bits
-
Test Case: (ACCbHI) = 5Eh = 01011110b
-
Result: (ACCbHI) = 0Eh = 00001110b
Solution:
Label | Opcode | Operands | Comments |
---|---|---|---|
MOVF | 40h,0 | ;Get data from the content of (40h) into W register | |
ANDWF | '00001111'b,0 | ;Mask 4 most significant bits and return solution ;to file register W | |
MOVWF | 40h | ;Return value to location 40h | |
RETLW | 00h | ;Clear W register & return |
Mask Off Least Significant 4 Bits
-
Problem: Mask off least significant 4 bits
-
Test Case: (ACCbHI) = 5Eh = 01011110b
-
Result: (ACCbHI) = 50h = 01010000b
Solution:
Label | Opcode | Operands | Comments |
---|---|---|---|
MOVF | 40h,0 | ;Get data from the content of 40h into W register | |
ANDWF | '11110000'b,0 | ;Mask 4 least significant bits and return solution ;to working register W | |
MOVWF | 40h | ;Return value to location 40h | |
RETLW | 00h | ;Clear W register & return |
Clear a Memory Location
-
Problem: Clear memory location
-
Test Case: (40h) = 5Eh = 01011110b
-
Result: (40h) = 00h = 00000000b
Solution:
Label | Opcode | Operands | Comments |
---|---|---|---|
CLRF | 40h | ;Clear register f and set zero bit Z, in Status ;register, to 1 | |
RETLW | 00h | ;Clear W register & return |
Set a Memory Location to All Ones
-
Problem: Set a memory location to all ones
-
Test Case: (40h) = 5Eh = 01011110b
-
Result: (40h) = 00h = 00000000b
Solution:
Label | Opcode | Operands | Comments |
---|---|---|---|
MOVF | 40h,0 | ;Get data from the content of 40h into W register | |
IORLW | '11111111'b | ;Inclusive OR with FFh to set Working register to ;all ones | |
MOVWF | 40h | ;Reset 40h to all ones | |
RETLW | FFh | ;Return with all ones |
Find Larger of Two Numbers
-
Problem: Find the larger of two numbers
-
Test Case: (40h) = 5Eh = 01011110b
-
(41h) = 6Ch = 01101101b
-
Result: (41h) holds the larger number
Solution:
Label | Opcode | Operands | Comments |
---|---|---|---|
MOVF | 40h,0 | ;Get data from the content of 40h into W register | |
SUBWF | 41h,0 | ; | |
BTFSS | STATUS,0 | ;N = 1 Negative | |
RETLW | 40h | ;Contents of 40h is the Larger Number | |
BTFSS | STATUS,2 | ;Z = 1 Zero | |
RETLW | 00h | ;0 for numbers that are equal | |
RETLW | 41h | ;Contents of 41h is the Larger Number |
Find Smaller of Two Numbers
-
Problem: Find the smaller of two numbers
-
Test Case: (40h) = 5Eh = 01011110b
-
(41h) = 6Ch = 01101101b
-
Result: (40h) holds the smaller number
Solution:
Label | Opcode | Operands | Comments |
---|---|---|---|
MOVF | 40h,0 | ;Get data from the content of 40h into ;W register | |
SUBWF | 41h,0 | ;Subtraction sets Status Bits | |
BTFSS | STATUS, 0 | ;N = 1 Negative | |
RETLW | 41h | ;Contents of 41h is the Smaller Number | |
BTFSS | STATUS, 2 | ;Bit Test Z = 1 Zero | |
RETLW | 00h | ;0 for equality of numbers | |
RETLW | 40h | ;Contents of 40h is the Smaller Number |
Read full chapter
URL:
https://www.sciencedirect.com/science/article/pii/B9780128126172000043
Getting Started with MSP430 Assembler
Dan Harres , in MSP430-based Robot Applications, 2013
The indirect and the indirect autoincrement addressing modes
For the source operand, there are additional addressing modes. The more common of these is the Indirect Addressing Mode, an example of which is:
mov @R6,R8
which moves the contents of the memory location pointed to by R6 into R8. But doesn't the Indexed Mode do the same thing when used with a zero offset? Well, yes. In fact, the ADD example given a little earlier could be rewritten as:
add @R8,2(R8).
Not only can you use this last statement in place of the earlier ADD syntax, but the Assembler will actually substitute this Indirect Addressing Mode for the earlier Indexed Addressing Mode, should you write your program using the Indexed Addressing Mode for the source operand. The reason for this is that, although they produce equivalent results, the Indirect Addressing Mode is more compact, requiring just one word of instruction, instead of the three words that the Indexed Addressing Mode requires.
The Indirect Autoincrement Addressing Mode is exactly like the Indirect Addressing Mode, except that it increments the pointing register by 1 or 2 (depending on whether the instruction is for byte-long data or word-long data). This can be useful when loading data from a table (that is, a list of bytes or words in memory). The program can execute a MOV instruction that loads the byte or word from memory and, without using an extra instruction to increment the table pointer, be ready to load the next memory location.
Read full chapter
URL:
https://www.sciencedirect.com/science/article/pii/B9780123970121000102
How To Store Registers In Memory Locaions
Source: https://www.sciencedirect.com/topics/engineering/memory-location
Posted by: terryawor1978.blogspot.com
0 Response to "How To Store Registers In Memory Locaions"
Post a Comment