汇编 MIPS %call16(printf) [英] Assembly MIPS %call16(printf)

查看:123
本文介绍了汇编 MIPS %call16(printf)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在汇编中有这个代码.

I have this code in Assembly.

    .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)上加载要打印的字符串地址

la $4,print Loads the address of the string to print on the first parameter of function call ($a0)

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

move $5,$10 moves the value on register 10 (in this case -99) to register the second parameter of a function call

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

And here are my doubts. I load something on register 25.

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

What is %call16(printf)($28)? It´s what prints the string and the number but I don't understand why...

推荐答案

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

%call16 instructs the assembler to insert an explicit relocation of type R_MIPS_CALL16, which is a 16 bit wide relocation against the GOT entry for the specified function (in your case, printf). The relocation basically says "replace the value at offset 0x... with the memory location that symbol printf is stored at". Then jalr jumps to the address stored in $25.

附注.在某些情况下(例如 VxWorks),ELF 二进制文件可能不使用 PIC,然后 R_MIPS_CALL16 重定位指向 .got.plt 部分中的条目,但这根本不会改变您对汇编程序的使用.

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.

这篇关于汇编 MIPS %call16(printf)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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