LDR/STR指令学习

来源:互联网 发布:mac三国志13战斗卡 编辑:程序博客网 时间:2024/05/18 14:42

S3C2440A datasheet上关于这两条指令的说明如下:

 SINGLE DATA TRANSFER (LDR, STR), The single data transfer instructions are used to load or store single bytes or words of data.

 简单的理解就是数据的传送/存储指令。

 

接下来是datasheet上关于这两个指令格式的说明:

<LDR|STR>{cond}{B}{T} Rd,<Address>
where:
LDR   ---   Load from memory into a register
STR   ---   Store from a register into memory
{cond} ---Two-character condition mnemonic. See Table 3-2.  (这个可以不用考虑)
{B} ---  If B is present then byte transfer, otherwise word transfer.  (这个也可以不用考虑)
{T}  --- If T is present the W bit will be set in a post-indexed instruction, forcing non-privileged
mode for the transfer cycle. T is not allowed when a pre-indexed addressing mode is
specified or implied.   (这个也可以不用考虑)
Rd ---    An expression evaluating to a valid register number. (CPU一个寄存器的具体名字:R0~R15)
Rn and Rm ---   Expressions evaluating to a register number. If Rn is R15 then the assembler will
subtract 8 from the offset value to allow for ARM920T pipelining.
In this case base write-back should not be specified.
<Address>can be:  (以下是关于地址的几种表示方法)
1       An expression which generates an address:  (立即寻址)
The assembler will attempt to generate an instruction using the PC as a base and a
corrected immediate offset to address the location given by evaluating the expression.
This will be a PC relative, pre-indexed address. If the address is out of range, an error
will be generated.
2        A pre-indexed addressing specification:  (变址寻址)
[Rn] offset of zero
[Rn,<#expression>]{!} offset of <expression> bytes
[Rn,{+/-}Rm{,<shift>}]{!} offset of +/- contents of index register, shifted
by <shift>
3       A post-indexed addressing specification:  (偏移寻址)
[Rn],<#expression> offset of <expression> bytes
[Rn],{+/-}Rm{,<shift>} offset of +/- contents of index register, shifted as
by <shift>.
<shift> General shift operation (see data processing instructions) but you cannot specify the shift
amount by a register.


{!} --- Writes back the base register (set the W bit) if! is present  (是否会写基寄存器,这个一般很少用)

在ARM架构下,  数据从内存到CPU之间的移动只能通过LDR/STR指令来完成.  而MOV只能在寄存器之间移动数据,或者把立即数移动到寄存器中,并且数据的长度不能超过8位

以下是具体的应用例子:

     1.  LDR   r0,=label      用于加载立即数或一个地址值到指定寄存器中

   1.1  如果label是立即数:  LDR r0,=0X123           ;将0X123存入r0中

   1.2  如果name是个标识符:  LDR   r0,=label_1    ;将label_1所指向的地址值存入r0中

2.   LDR       r0,[r1]   ;将R1中的值存到r0中

3.   LDR       r1,[r2,#16]    ;将(r2+16)地址中的内容存到r1中

4.   LDR       r1,[r2],#4    ;将r2地址中的内容存到r1中,同时r2=r2+4

 

a.  STR   r1,[r2]        ; 将r1中的值存到r2所指定的地址中

b.  STR   r1,[r2,#4]   ;将r1中的值存到r2+4所指定的地址中

c.   STR   r1,[r2],#4  ;将r1中的值存到r2所指定的地址中, 同时r2=r2+4