Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It appears that your question is along the lines of "How can I print out variable values in x86 assembler". The x86 itself doesn't know how to do that, because it depends entirely on what output device you're using (and the specifics of the OS-provided interface to that output device).</p> <p>One way of doing it is to use operating system syscalls, as you mentioned yourself in another answer. If you're on x86 Linux, then you can use the <code>sys_write</code> sys call to write a string to standard output, like this (GNU assembler syntax):</p> <pre><code>STR: .string "message from assembler\n" .globl asmfunc .type asmfunc, @function asmfunc: movl $4, %eax # sys_write movl $1, %ebx # stdout leal STR, %ecx # movl $23, %edx # length int $0x80 # syscall ret </code></pre> <p>However, if you want to print numeric values, then the most flexible method will be to use the <code>printf()</code> function from the C standard library (you mention that you're calling your assembler rountines from C, so you are probably linking to the standard library anyway). This is an example:</p> <pre><code>int_format: .string "%d\n" .globl asmfunc2 .type asmfunc2, @function asmfunc2: movl $123456, %eax # print content of %eax as decimal integer pusha # save all registers pushl %eax pushl $int_format call printf add $8, %esp # remove arguments from stack popa # restore saved registers ret </code></pre> <p>Two things to note:</p> <ul> <li>You need to save and restore registers, because they get clobbered by the call; and</li> <li>When you call a function, the arguments are pushed in right-to-left order.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload