Can someone explain the following instructions for loading and storing with ARM ISA?

I'm just starting to learn ARM, and it's hard for me to understand exactly what the loading and storage instructions do.

Download Instructions:

ldrsb ldrb ldrsh ldrh ldr 

Storage Instructions:

 strb strh str 

What does “download half a word” mean, signed or unsigned? Or for a "byte download" signed or unsigned? What is the difference between signed and unsigned, and in which specific applications, some of the loading / storing instructions should be practical to use? In general, I am looking for an intuitive understanding of what these instructions do, as I am still confused about how they work and what their goals are.

+4
source share
2 answers

When it comes to ARM, the word “32”, “half-layer” is 16 bits, and “byte” is 8 bits. If you read the documentation for the instruction set in the ARM Architecture Reference Guide (just run ARMv5, if you don't know which one to get, infocenter.arm.com), you will see that ldrb loads the byte into the lower 8 bits, the destination register fills the upper 24 bits of zeros. Ldrsb will sign the extension instead of a pad with zeros. The same goes for the half-word.

if you have a code like this:

 char a,b,c; ... c = a+b; if(c<0) { } 

And either a, b, or both were in memory at the time you needed to make this addition, then you would ideally want to make the character extended (provided that you told your compiler that char is signed) loading to save the instruction expanding registers so you can do the math and have flags set for comparison.

From ARM ARM.

The LDRSB (registered byte register) loads the byte from memory, signs it to form a 32-bit word, and writes the result to the general register.

LDRB (Load Register Byte) loads a byte from memory, zero expands it to form a 32-bit word, and writes the result to the general register.

+8
source

ARM is a RISC (Reduced Instruction Set Computing) architecture, meaning that memory must be moved to and from registers using the instructions you refer to, instructions for loading and storing.

Download instructions take one value from memory and write it to the general register. Storage instructions read the value from the general register and store it in memory.

Most Often Used Load/Store Instructions

 Loads Stores Size and Type LDR STR Word (32 bits) LDRB STRB Byte (8 bits) LDRH STRH Halfword (16 bits) LDRSB Signed byte LDRSH Signed halfword LDM STM Multiple words 

(taken from the ARM assembly language - William Hohl)

Instructions for loading and storing (in general) are given in the following form:

 LDR | STR {type}{cond} Rt, [Rn {, #offset}] 

(although there are some differences depending on the type of addressing mode you want to use, but I will not go into this here if you want to know more addressing modes, you should check "ARM post-index and pre-indexing" )

"Type" is optional and is described in the table above, where you can choose to work with halfwords, bytes, as well as signed or unsigned bytes or halfwords. You also have the option to load or save multiple registers.

You also have the opportunity to add a condition code to the instruction (cond), which is used to set the flags of the conditions stored in the Status Register of the current program (CPSR) - if you want to know more about this, you can search for "conditional execution ARM" and " condition codes. "

In ARM, you must provide the source / destination register. And you must also provide a register containing an address that refers to a location in memory. This is because the ARM instruction is a fixed length (32 bits), and some of these bits must be used for the command itself, so it is not possible to encapsulate a 32-bit memory address into a 32-bit ARM instruction.

In the above example, “Rt” is the register in which the value that you load from memory (or the register containing the value that you store in memory if you are executing the storage) will be loaded. "Rn" is a register containing an address. Square brackets are in place to tell the processor that we are working with a register that contains the address that we are working with the pointer. An additional bias is present if you want to compensate for a certain amount from the base register (this is convenient in all types of useful applications, but I will not cover them here).

Hope this gives you some insight into how ARM loading and storing instructions work! :)

+4
source

All Articles