//---------------------------------------------------------------- // testdivb.s // // This interactive program tests our 'softdivb.s' function. // // // NOTE: Because this program calls external functions whose // code is in the standard C runtime library, and because it // expects to terminate via a 'ret' instruction in 'main()', // you should assemble-and-link it using this 'gcc' command: // // $ gcc testdivb.s softdivb.s -o testdivb // // // programmer: ALLAN CRUSE // written on: 22 FEB 2005 //---------------------------------------------------------------- .section .data legend: .asciz "\nThis program divides x by y \n\n" format: .asciz "%d" report: .ascii "OK, dividing %d by %d yields " .asciz "quotient %d and remainder %d \n\n" ask_x: .asciz "Please type your x value: " ask_y: .asciz "Please type your y value: " x: .int 0 y: .int 0 q: .int 0 r: .int 0 .section .text main: # show the program's legend pushl $legend # push function argument call printf # call library function addl $4, %esp # discard the argument # show prompt #1 and get reply pushl $ask_x # push function argument call printf # call library function addl $4, %esp # discard the argument pushl $x # push argument #2 pushl $format # push argument #1 call scanf # call library function addl $8, %esp # discard two arguments # show prompt #2 and get reply pushl $ask_y # push function argument call printf # call library function addl $4, %esp # discard the argument pushl $y # push argument #2 pushl $format # push argument #1 call scanf # call library function addl $8, %esp # discard two arguments # now perform the division movw x, %ax # copy dividend to AX movb y, %bl # copy divisor to BL call softdivb # do software division movb %al, q # copy quotient to storage movb %ah, r # copy remainder to storage # report the result, then exit pushl r # push argument #5 pushl q # push argument #4 pushl y # push argument #3 pushl x # push argument #2 pushl $report # push argument #1 call printf # call library function addl $20, %esp # discard all arguments ret # return to the caller .global main # entry-point is visible .end # no further statements