简体   繁体   中英

How to call printf in machine language

Let's say we have the assembly code that prints Z to the screen.

pushl $'Z'
call putchar
add $4, %esp

How can we write this in machine language code? I've checked both online resources and this code in gdb, but the former disagrees with the latter and the latter changes each time I run the code. Thank you for your help.

I'm using linux x86. Again, I'd like to say that I want to know how to write this in machine language code.

Use putchar instead of printf . printf needs a string , and you have provided it a char . Also, remember that you have to restore the stack just after calling your function, as both printf and putchar uses the cdecl calling convention.

pushl $'Z'
call putchar
add $4, %esp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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