### -------------------------------------------------------------------- ### absval.s ### Author: Bob Dondero ### -------------------------------------------------------------------- .section ".rodata" cPrompt: .string "Enter an integer: " cScanfFormat: .string "%d" cResult: .string "The integer's absolute value is %d.\n" ### -------------------------------------------------------------------- .section ".data" ### -------------------------------------------------------------------- .section ".bss" iInput: .skip 4 iAbsVal: .skip 4 ### -------------------------------------------------------------------- .section ".text" ## ------------------------------------------------------------- ## Read an integer from stdin, and write its absolute value ## to stdout. Return 0. ## int main(void) ## ------------------------------------------------------------- .globl main .type main,@function main: pushl %ebp movl %esp, %ebp ## printf("Enter an integer: ") pushl $cPrompt call printf addl $4, %esp ## scanf("%d", &iInput) pushl $iInput pushl $cScanfFormat call scanf addl $8, %esp ## iAbsVal = abs(iInput) pushl iInput call abs addl $4, %esp movl %eax, iAbsVal ## printf("The integer's absolute value is %d.\n", iAbsVal) pushl iAbsVal pushl $cResult call printf addl $8, %esp ## return 0 movl $0, %eax movl %ebp, %esp popl %ebp ret