Assembly MIPS %call16(printf)

巧了我就是萌 提交于 2021-02-10 14:57:56

问题


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

This code will print:

The value is: -99

I understand that:

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

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

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

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


回答1:


%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.

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.



来源:https://stackoverflow.com/questions/10175962/assembly-mips-call16printf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!