ARM汇编语言指令集(4)

 
·          Load/Store Instructions
The ARM is a Load/Store Architecture: Does not support memory to memory data processing operations. Must move data values into registers before using them.ARM has three sets of instructions which interact with main memory. These are
Single register data transfer(LDR/STR)
Block dtat transfer(LDM/STM)
Single Data Swap(SWP)
 
指令
描述
LDR
字资料载入指令
LDRB
字节资料载入指令
LDRH
半字资料载入指令
STR
字资料存储指令
STRB
字节资料存储指令
STRH
半字资料存储指令
Syntax:
<LDR|STR>{<cond>}{<sizez>} Rd,<address>
 
·          Load and Store Word or Byte,offset from the base register
 
指令
说明
LDR R0,[R1]
将地址 R1 处字资料读入 R0
LDR R0, [R1, R2]
将地址 R1+R2 处字资料读入 R0
LDR R0,[R1, #8]
将地址 R1+8 处字资料读入 R0
LDR R0, [R1, R2]!
将地址 R1+R2 处字资料读入 R0, 并将新地址 R1+R2 写入 R1
LDR R0, [R1, #8]!
将地址 R1+8 处字资料读入 R0, 并将新地址 R1+8 写入 R1
LDR R0, [R1], R2
将地址 R1 的字资料读入 R0, 并将新地址 R1+R2 写入 R1
LDR R0, [R1, R2,LSL #2]!
将地址 R1+R2x4 处字资料读入 R0, 新址 R1+R2x4 写入 R1
LDR R0,[R1],R2,LSL #2
将地址 R1 处字资料写入 R0, 新址 R1+R2x4 写入 R1
STR r0,[r1,#-12]
r0 写入到地址 r1-12
 
 
 
 
Example:Write a segment of code that add together elements x to x+(n-1) of an array, where the element x = 0 is the first element of the array. Each element of the array is word size(ie, 32bits). The segment should use post-indexed addressing.At the start of your segments, you should assume that: r0 points to the start of the array, r1 = x, r2 = n;
Sample Solution:
          DataSpace SPACE 100; 连续分配100个字节的存储单元并初始化为0
         
          ADD r0, r0, r1, LSL#2
          ADD r2, r0, r2, LSL#2
          MOV r1, #0
loop
           LDR r3, [r0],#4
           ADD r1, r1, r3
           CMP r0, r3
           BLT loop
 
·          Block Data Transfer
The Load and Store Multiple instruction(LDM/STM) allow between 1 and 16 registers to be transferred to or from memory.
格式:
         LDM(STM){条件}{类型}基址寄存器{!},寄存器列表{^}
该指令常见用途是将多个寄存器的内容入栈或出栈。类型包括非堆栈型寻址或堆栈型寻址。
 
寻址
说明
IA Increment After
基址寄存器在取后才增加
IB Increment Before
基址寄存器在取前才增加
DA Decrement After
基址寄存器在存取后才减少
DB Decrement Before
基址寄存器在存取前即减少
FD Full Descending
满递减
FA Full Ascending
满递增
ED Empty Descending
空递减
EA Empty Ascending
空递增
 
Traditionaly, a stack grows down in memory, with the last ‘pushed’ value at the lowest address. The ARM also supports ascending stacks, where the stack structure grows up through memory. The value of the stack pointer can either:
Point to the last occupied address(Full stack)—and so needs pre-decrementing(ie before the push). Point to the next occupied address(Empty stack)—and so needs post-decrementing(ie after the push)
 
注意,象 STMFD, STMED STMFA STMEA 分别跟 LDMFD, LDMED, LDMFA LDMEA 配对,故理解不能全部按照字面意思来。
 
 
·          资料交换指令
语法
          SWP{<cond>}{B} Rd, Rm, [Rn]
          SWP{条件}{B} 目的寄存器,来源寄存器1,[来源寄存器2]
SWP指令用于将来源寄存器2所指向的存储器中的字资料般移到目的寄存器,同时将来源寄存器1的字资料般移到来源寄存器2所指向的存储器中。当来源寄存器1和目的寄存器为同一存储器时,该指令交换该寄存器和存储器的内容
        SWP R0, R1, [R2]     ;将R2所指向的存储器中的字般移到R0,同时将R1中的字资料般移到R2指向的存储单元
        SWP R0, R0, [R1]      ;该指令完成将R1所指向的存储体中的字资料与R0中的字资料交换
        SWPB R0, R1, [R2] ; R2 所指向的記憶體中的位元組資料般移到 R0 R0 的高 24 位清零,同時將 R1 中的低 8 位元資料般移到 R2 所指向的存儲單元
        SWPB R0, R0, [R1] ; 該指令完成將 R1 所指向的記憶體中的位元組資料與 R0 中的低 8 位元資料交換
 
 
·          PSR Transfer Instructions
MRS and MSR allow contents of CPSR/SPSR to be transferred from appropriate status register to a general purpose register.
MRS{<cond>} Rd, <psr>
MSR{<cond>} <psr>, Rm
MSR{<cond>} <psrf>, Rm
<psr> = CPSR, CPSR_all, SPSR or SPSR_all
<psrf> = CPSR_flg or SPSR_flg
MSR{<cond>} <psrf>, #Immediate
其中Immediate为32位立即数,最高4位写入到flag bits.
 
有时LDR r0, =DataSpace和ADR r0,DataSpace效果一样
伪指令DCD分配一片连续的字存储单元并初始化,例如
string1 DCD 0x23, 0x24
string2 DCD 0x23, 0x25
 
类中定义的 static 变量和函数定义的 static 变量,全局变量一样,都是通过 startup 函数调用库定义的 ?main 函数来实现其初始化的。
 
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值