	.section	.text
	.intel_syntax
	.global	div
	.type	div, @function
div:
	push	%ebp
	mov	%ebp, %esp
	push	%ebx			# Callee-saved register
# The DIV instruction always divides the 64 bits value accross EDX:EAX by a value,
# but in this procedure the dividend will never be greater than 32 bits so EDX is
# cleared. 
	mov	%edx, 0			# Clear dividend
	mov	%eax, [%ebp + 12]	# Dividend
	mov	%ebx, [%ebp + 16]	# Divisor
	div	%ebx
# The caller is expected to pass (as the very first parameter, before the formal
# parameters) the address of the record receptacle when calling a procedure that
# returns a record, like this one.
	mov	%ecx, [%ebp + 8]	# Get address of record
	mov	[%ecx], %eax		# Quotient
	mov	[%ecx + 4], %edx	# Remainder
	mov	%eax, [%ebp + 8]	# Return address of record
	pop	%ebx
	pop	%ebp			# Leave
	ret	4			# Return to calling procedure and pop 4 bytes from stack
