#====================================================================== # helloname.s # Fundamentals # Calling Functions Using the C Calling Conventions #====================================================================== .equ MAX_NAME_LENGTH, 100 #====================================================================== .section ".rodata" #====================================================================== pcPrompt: .asciz "What is your name? " pcScanfFormat: .asciz "%s" pcGreeting: .asciz "Hello %s.\n" #====================================================================== .section ".data" #====================================================================== #====================================================================== .section ".bss" #====================================================================== pcName: .skip MAX_NAME_LENGTH #====================================================================== .section ".text" #====================================================================== #---------------------------------------------------------------------- # int main(int argc, char *argv[]) # # Read a name from stdin, and write a greeting that uses that name # to stdout. # # Formal parameter offsets: .equ ARGC, 8 .equ ARGV, 12 #---------------------------------------------------------------------- .globl main .type main,@function main: pushl %ebp movl %esp, %ebp # printf("What is your name? "); pushl $pcPrompt call printf addl $4, %esp # scanf("%s", pcName); pushl $pcName pushl $pcScanfFormat call scanf addl $8, %esp # printf("Hello %s.\n", pcName); pushl $pcName pushl $pcGreeting call printf addl $8, %esp # return 0; movl $0, %eax movl %ebp, %esp popl %ebp ret