1

我在汇编中有这段代码。

    .data
tabela:     .word   4, 2, 10, 1, 6
print:      .asciiz "The value is: %d\n"
    .text
    .globl  programa
programa:

    ########################
    Do some stuff here.
    Value on $10 is -99
    ########################


la      $4,print
move    $5,$10
lw      $25,%call16(printf)($28)
jalr    $25

此代码将打印:

The value is: -99

我明白那个:

la $4,print加载要在函数调用的第一个参数 ($a0) 上打印的字符串的地址

move $5,$10移动寄存器 10(在本例中为 -99)上的值以注册函数调用的第二个参数

这是我的疑问。我在寄存器 25 上加载了一些东西。

是什么%call16(printf)($28)?这是打印字符串和数字的原因,但我不明白为什么......

4

1 回答 1

3

%call16指示汇编器插入类型为 R_MIPS_CALL16 的显式重定位,这是针对指定函数(在您的情况下为 )的 GOT 条目的 16 位宽重定位printf。重定位基本上是说“将偏移量 0x 处的值替换为符号 printf 存储在的内存位置”。然后jalr跳转到存储的地址$25

PS. In some cases (e.g. VxWorks), ELF binaries may not use PIC and then R_MIPS_CALL16 relocations point to an entry in the .got.plt section, but that doesn't change your use of the assembler at all.

于 2012-04-16T15:01:42.490 回答