#---------------------------------------------------------------------------- # hello.s # by TC Bressoud #---------------------------------------------------------------------------- # Start with the data section. Define the strings used # by the program. Global integer and float data would have # similar definitions. .data astr: .string "Enter a: " # The .string directive zero terminates s: .string "%d" hello: .string "Hello World = %d\n" bye: .string "Leaving now" # Group together all the executable code in the .text section .text .globl main main: # Prologue pushl %ebp movl %esp, %ebp andl $0xffffff00, %esp # align esp on 16 byte boundary to begin subl $32, %esp movl $astr, 4(%esp) # printf(astr) movl $1, (%esp) call __printf_chk leal 28(%esp), %eax # scanf(s, &a), where a is in the stack frame movl %eax, 4(%esp) movl $s, (%esp) call __isoc99_scanf # Instructions below are translation of the if-statement movl 28(%esp), %eax testl %eax, %eax je nottrue movl %eax, 8(%esp) movl $hello, 4(%esp) movl $1, (%esp) call __printf_chk nottrue: movl $bye, (%esp) call puts # Epilogue leave ret