/* * COSC 065 - Hardware Systems * D.W. Brylow * Intel x86 assembly demo. */ .section .rodata FMT: .string "%d\n" .section .text .globl main /* int main() * { * printf("%d\n", foo(4) ); * * } */ main: pushl %ebp movl %esp, %ebp pushl $4 call foo pushl %eax pushl $FMT call printf movl %ebp, %esp popl %ebp ret /* int foo(int x) * { * int y; * int z; * y = 5; * z = x + y; * return z; * } */ foo: pushl %ebp movl %esp, %ebp subl $8, %esp movl $5, -8(%ebp) movl -8(%ebp), %eax addl 8(%ebp), %eax movl %eax, -4(%ebp) movl -4(%ebp), %eax movl %ebp, %esp popl %ebp ret