Everyone_Else
Everyone_Else

Reputation: 3264

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.

Upvotes: 0

Views: 1146

Answers (1)

mcleod_ideafix
mcleod_ideafix

Reputation: 11438

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

Upvotes: 3

Related Questions