数组转置和相应的汇编代码

时间:2016-02-21 06:34:05

标签: c arrays assembly reverse-engineering x86-64

C代码:

void transpose (long A[M][M]) {
    long i, j;
    for (i = 0; i < M; i ++)
        for (j = 0; j < i; j ++) {
            long t = A[i][j];
            A[i][j] = A[j][i];
            A[j][i] = t;
        }
}

基于INNER循环的-O1优化的相应汇编代码:

.L6:
    movq   (%rdx), %rcx  //
    movq   (%rax), %rsi
    movq   %rsi, (%rdx)
    movq   %rcx, (%rax)
    addq   $8, %rdx
    addq   $120, %rax
    cmpq   %rdi, %rax
    jne    .L6

我对汇编代码的理解:

1.  movq (%rdx), %rcx
      int *rdx = ?
      int rcx = *rdx  

2.  movq (%rax), %rsi
      int *rax = ?
      int rsi = *rax  

3.  movq %rsi, (%rdx)
      *rdx = rsi = *rax

4.  movq %rcx, (%rax)
      *rax = rcx = *rdi

5.  addq $8, %rdx
      rdx +=8

6.  addq $120, %rax
      rax += 120

7.  cmpq %rdi, %rax
    jne .L6
      int rdi = ?
      if (rdi != rax) jump to L6

外卖:

  • rdx增加8。
  • rdx与C代码中的j类似。
  • 每行在数组中长度为120个字节。
  • for循环rdx之外的
  • 可能在0初始化。
  • 我仍然没有得到rax正在返回的内容。

问题:

  1. 哪个寄存器包含指向数组元素A[i][j]

  2. 的指针
  3. 哪个寄存器包含指向数组元素A[j][i]

  4. 的指针
  5. M的价值是什么?

  6. 我的想法:

    1. rdxrdx总是上升8,所以它会经过整行。

    2. rsi也许??? rsi设置为保留返回值,我认为返回值是元素A[j][i]

    3. 120 / 8 = 15

    4. 对我的回答或拒绝的任何确认将不胜感激。

1 个答案:

答案 0 :(得分:1)

元素是with open("file.txt", 'r') as fd: d = dict(line.rstrip().split(":") for line in fd) s(长度为8个字节),您正在检查内部循环(在 Admin admin = null; Configuration config = HBaseConfiguration.create(); // Add custom config parameters here Connection connection = ConnectionFactory.createConnection(config); try { admin = connection.getAdmin(); for (String tableName : tableNames) { System.out.print("Truncate table " + tableName); try { if (HBaseHelper.isTableExists(tableName)) { if (admin.isTableDisabled(TableName.valueOf(tableName))) { System.out.print("Table " + tableName + " was disabled. Enabling it..."); admin.enableTable(TableName.valueOf(tableName ); } HBaseHelper.truncateTable(tableName); } } catch (IOException e) { System.out.print("Failed to truncate table " + tableName + "\nError Msg: " + e.getMessage()); } } } catch (Exception e){ System.out.print("Could not connect to HBase Admin. Error Msg: " + e.getMessage()); } 上),所以:

long

表示j明确指向rdx +=8

rdx

表示A[i][j]指向rax += 120

rax等于15,因为一行长度为120个字节(A[j][i]M之间的字节距离),每个A[j][i]长度为8个字节(距离)在A[j+1][i]long之间。