### ------------------------------------------------------------------ ### absval.s ### Author: Bob Dondero ### Immediate, Register, and Simple Memory Operands ### Function Return Values ### ------------------------------------------------------------------ .section ".rodata" cPrompt: .asciz "Enter an integer: " cScanfFormat: .asciz "%d" cResult: .asciz "The integer's absolute value is %d.\n" ### ------------------------------------------------------------------ .section ".data" ### ------------------------------------------------------------------ .section ".bss" iInput: .skip 4 iAbsVal: .skip 4 ### ------------------------------------------------------------------ .section ".text" ## ----------------------------------------------------------- ## int main(int argc, char *argv[]) ## Read an integer from stdin, and write its absolute value ## to stdout. ## ----------------------------------------------------------- ## Formal parameter offsets: .equ ARGC, 8 .equ ARGV, 12 .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