这怎么行ARM的工作吗? [英] How does this line of ARM work?

查看:177
本文介绍了这怎么行ARM的工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些麻烦搞清楚本次大会code如何工作的。我知道它循环16次,总每次迭代更新。特别是对在.L2标签行了,那不是给分段错误,因为previous行:LDR IP,[IP,#0]重新分配IP?可有人解释这是如何工作?预先感谢您的时间。

  .L5:
    .word数据
    .word总
_开始:
    LDR IP,.L5
    MOV R1,#0
    LDR R0,.L5 + 4
    MOV R3,R1
    MOV R2,R1
    LDR IP,[IP,#0]
    STR R1,[R0,#0]
.L2:
    LDR R1,[IP,R3]
    添加R3,R3,#4
    CMP R3,#64
    ADD R2,R2,R1
    STR R2,[R0,#0]
    BNE .L2


解决方案

您code:


  • 加载数据的地址在 IP 和地址 R0

  • 置零寄存器 R1 R2 R3

  • 加载到 IP 数据的内容,免去了previous内容(<$地址C $ C>数据)。这并不段错误。你被允许从内存中加载到任何寄存器,包括你刚才用来指定的有效地址的负载之一。所有发生的通常的:无论旧值在那里(在这种情况下,指针)被替换为新的值(指针对象)。

  • 百货 0

  • 重复16次:

    • 使用 IP 作为一个整数数组,负载的基地址为 R1 在整数偏移 R3 基址。

    • 厚积薄发 R1 入册 R2

    • 存储 R2


在此基础上

,我相信数据的类型为为int * 的类型为 INT 。因此,你的汇编我间pretation是:

伪code-Y类C汇编

 为int *的数据;
INT总;
无效启动(无效){
    INT ** IP =&放大器;数据;
    为int * R0 =放大器;全;
    INT R1 = 0,R2 = R1,R3 = R1;    为int * ipnew = *的IP;
    * R0 = R1; / *总= 0; * /    做{
        R1 = *为(int *)((字符*)ipnew + R3); / * R1 = ipnew [R3 / 4]; * /
        R3 + = 4;
        R2 + = R1;
        * R0 = R2; / *总= R2; * /
    }而(R3 = 64!);
}

用纯C

 为int *的数据;
INT总;无效启动(无效){
    为int * ARR =数据; / * * IP /
    注册INT总和= 0; / * R2 * /
    注册INT I = 0; / * R3,除以4 * /    总= 0;    做{
        总和+ =改编[我++]; / * r1包含从数组加载的价值。 * /
        总= SUM; / * r0包含&放大器;总* /
    }而(I = 16!);
}

I am having some trouble figuring how this assembly code works. I know it loops 16 times and updates the total every iteration. Specifically on the line at the .L2 label, wouldn't that give a segmentation fault since the previous line: ldr ip, [ip, #0] reassigns ip? Can someone explains how this works? Thank you in advance for your time.

.L5:
    .word data
    .word total
_start:
    ldr ip, .L5
    mov r1, #0
    ldr r0, .L5+4
    mov r3, r1
    mov r2, r1
    ldr ip, [ip, #0]
    str r1, [r0, #0]
.L2:
    ldr r1, [ip, r3]
    add r3, r3, #4
    cmp r3, #64
    add r2, r2, r1
    str r2, [r0, #0]
    bne .L2

解决方案

Your code:

  • Loads the addresses of data in ip and the address of total in r0.
  • Zeroes registers r1, r2 and r3
  • Loads into ip the contents of data, replacing the previous contents (the address of data). This does not segfault. You are allowed to load from memory into any register, including the one you just used to specify the effective address for the load. All that happens is the usual: Whatever old value was there (in this case, the pointer) is replaced with the new value (the pointee).
  • Stores 0 into total.
  • Repeats 16 times:
    • Using ip as the base address of an array of integers, load into r1 the integer at offset r3 from the base address.
    • Accumulate r1 into the register r2.
    • Store r2 to total.

Based on this, I believe that data is of type int* and that total is of type int. Therefore, my interpretation of your assembler is:

Pseudocode-y C-like assembler

int* data;
int total;


void start(void){
    int** ip = &data;
    int*  r0 = &total;
    int r1=0, r2=r1, r3=r1;

    int* ipnew = *ip;
    *r0 = r1;/* total = 0; */

    do{
        r1 = *(int*)((char*)ipnew + r3);/* r1 = ipnew[r3/4]; */
        r3 += 4;
        r2 += r1;
        *r0 = r2;/* total = r2; */
    }while(r3 != 64);
}

Pure C

int* data;
int  total;

void start(void){
    int* arr = data;      /* ip */
    register int  sum = 0;/* r2 */
    register int  i   = 0;/* r3, divided by 4 */

    total = 0;

    do{
        sum   += arr[i++];/* r1 contains the value loaded from the array. */
        total  = sum;     /* r0 contains &total */
    }while(i != 16);
}

这篇关于这怎么行ARM的工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆