简体   繁体   English

从程序集调用printf-不起作用

[英]Calling printf from assembly - not working

Well.. i've tried a few things but I can't get this to work. 好吧..我已经尝试了一些东西,但是我无法使它正常工作。

How do I push the address of _hello correctly for the printf() function? 如何为printf()函数正确推送_hello的地址?

.intel_syntax noprefix

.extern printf

.global printf2

_hello: .ascii  "Hello World!\0"

printf2:
    push ebp
    mov ebp, esp

    push _hello
    call _printf

    pop ebp
    ret

With " not working " I mean that the program simply crashes. 不起作用 ”是指程序完全崩溃。

I could not identify which OS you use. 我无法确定您使用的是哪个操作系统。

This is correct for MinGW-GAS for Windows: 这对于Windows的MinGW-GAS是正确的:

.intel_syntax noprefix

.extern _printf
.global _printf2

_hello: .ascii  "Hello World!\0"

_printf2:
    push ebp
    mov ebp, esp

    push OFFSET _hello
    call _printf
    add esp, 4

    pop ebp
    ret

And this one is for Linux-GAS: 这是针对Linux-GAS的:

.intel_syntax noprefix

.extern printf
.global printf2

_hello: .ascii  "Hello World!\0"

printf2:
    push ebp
    mov ebp, esp

    push OFFSET _hello
    call printf
    add esp, 4

    pop ebp
    ret

Consider the different use of the underscores! 考虑下划线的不同用法!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM