/* Compute dot product using SSE instruction */
	
/**********************************************************************/
	# Allocating 2 vectors to be multiplied
	.data

Vec1:	
	# Alignment is essential, o/w segfault!
	.align 16
	.float	1.0, 2.0, 3.0, 4.0
Vec2:	
	.float	5.0, 6.0, 7.0, 8.0

DotProd:
	.float 0.0
	
OutputSpec:	
	.string	"Dot Product: %.2f\n"
	
/**********************************************************************/

	.text
	.globl	main
	
main:
	pushl	%ebp
	movl	%esp, %ebp

	# SSE 4.1 dot product calculation
	movaps	(Vec1), %xmm1
	movaps	(Vec2),	%xmm2
	dpps	$0xf1,  %xmm1, %xmm2
	movss   %xmm2,  (DotProd)

	# Move result to FP stack
	movl    $DotProd, %eax
	flds 	(%eax)

	# Put on call stack for printf
	subl 	$4, %esp
	fstpl 	(%esp)
	
	pushl	$OutputSpec
	call	printf
	
	# Return 0 from main
	movl	$0, %eax

	# Restore stack
	movl	%ebp, %esp
	popl	%ebp

	ret

/**********************************************************************/
	
