ARM汇编语言指令集(4)
3241 点击·0 回帖
![]() | ![]() | |
![]() | 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: {}{} Rd, 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{}{B} Rd, Rm, [Rn] SWP{条件}{B} 目的寄存器,来源寄存器1,[来源寄存器2] | |
![]() | ![]() |