/*
  Filename   : FasterCompute.s
  Authors    : Cool Students
	         who attended 11/28 make-up class
  Course     : CSCI 370
  Description: Compute (9x - 3) / 5 for an inputted "x"
	         using fewer instructions than "Compute.s"
*/

/**********************************************************/
// Data
	.data

prompt:	
	.string "Please enter x ==> "

formatSpec:	
	.string "%d"

output:	
	.string "(9x - 3) / 5 = %d\n"

/**********************************************************/
// Code
	.text
	.align 4
	.globl main

main:
	pushl %ebp
	movl %esp, %ebp

	# Print "Please enter x ==> "
	pushl $prompt
	call printf

	# Push the address of "x" and "%d" for call to scanf
	leal -4(%ebp), %eax
	pushl %eax
	pushl $formatSpec
	call scanf

	# Load "x" into eax for call to f
	movl -4(%ebp), %eax
	pushl %eax
	call f

	# Print "(9x - 3) / 5 = y"
	pushl %eax
	pushl $output
	call printf

	# Return 0 from main
	movl $0, %eax
	
	movl %ebp, %esp
	pop  %ebp
	ret

f:
	#pushl %ebp
	#movl %esp, %ebp

	#movl 8(%ebp), %eax
	movl 4(%esp), %eax
	leal -3(%eax, %eax, 8), %eax
	cltd
	movl $5, %ecx
	idivl %ecx
	
	#pop  %ebp
	ret
	
