Whay rip is used here in a Hello world assembly? [duplicate]

孤街醉人 提交于 2021-01-29 14:11:34

问题


I found some assembly code about "hello world", but I don't understand leaq L1(%rip), %rdi, why rip is used here?

.text
.globl _main
_main:
    pushq %rbp
    movq %rsp, %rbp
    leaq L1(%rip), %rdi   <--it's the first time that I found IP is directly used in code.
    movq $0, %rax
    callq printf
    movq #0, %rax    <-sorry, here shoud be $0
    leaveq
    retq

    .data 
L1: .string 'hello jason\n'

usually, I understand and often use the following style assembly code as url http://libra.cs.virginia.edu/~aaron/08-nasm/nasmexamples.html

    global  _main
    extern  _printf

    section .text
_main:
    push    message
    call    _printf
    add esp, 4
    ret
message:
    db  'Hello, World', 10, 0

therefore, I don't understand the first program, why %rip is used? it's very strange.

来源:https://stackoverflow.com/questions/60133542/whay-rip-is-used-here-in-a-hello-world-assembly

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