	.file	"sum.c"
	.intel_syntax noprefix
	.text
	.comm	_str1, 20, 2
	.def	___main;	.scl	2;	.type	32;	.endef
	.section .rdata,"dr"
	.align 4
LC0:
	.ascii "value returned by doubling procedure is %u\0"
	.text
	.globl	_main
	.def	_main;	.scl	2;	.type	32;	.endef
_main:
	push	ebp
	mov	ebp, esp
	and	esp, -16
	sub	esp, 32
	call	___main
	mov	DWORD PTR [esp+28], 2
	mov	DWORD PTR [esp+24], 3
	mov	eax, DWORD PTR [esp+24]
	mov	DWORD PTR [esp], eax
	call	_mult

#	call	myhalve

	call	mydouble
	
	push eax 				# preserve - doesnt seem to work
	mov  esi,eax 				# This DOES preserve the value!

	# print line feed character
	mov	DWORD PTR [esp+28], eax		# preserve eax?
	mov	DWORD PTR [esp], 10		# line feed character
	call	_putchar			
	mov	eax, DWORD PTR [esp+28]		# restore eax?

	# print Capital A
	mov	DWORD PTR [esp+28], eax		# preserve eax?
	mov	DWORD PTR [esp], 65		# Capital A
	call	_putchar			
	mov	eax, DWORD PTR [esp+28]		# restore eax?

	# print line feed character
	mov	DWORD PTR [esp+28], eax		# preserve eax?
	mov	DWORD PTR [esp], 10		# line feed character
	call	_putchar			
	mov	eax, DWORD PTR [esp+28]		# restore eax?

	# print the letters of the alphabet A to Z
	mov 	eax,65				# Capital A
nextit:	mov	DWORD PTR [esp+28], eax		# preserve eax?
	mov	DWORD PTR [esp], eax	
	call	_putchar			
	mov	eax, DWORD PTR [esp+28]		# restore eax?
	add	eax,1				# forgot this line first time - infinte loop
	cmp 	eax,90
	jbe     nextit

	# print line feed character
	mov	DWORD PTR [esp+28], eax		# preserve eax?
	mov	DWORD PTR [esp], 10		# line feed character
	call	_putchar			
	mov	eax, DWORD PTR [esp+28]		# restore eax?

	pop eax 				# restore - doesn't seem to work
	mov eax,esi 				# This DOES restore the value!

	# Use _printf to print the value in eax
	mov	DWORD PTR [esp+4], eax
	mov	DWORD PTR [esp], OFFSET FLAT:LC0
	call	_printf

	nop
	leave
	ret
	.section .rdata,"dr"
LC1:
	.ascii "Enter an unsigned number: \0"
LC2:
	.ascii "%u\0"
LC3:
	.ascii "Number = %u\0"
	.text
	.globl	_mult
	.def	_mult;	.scl	2;	.type	32;	.endef
_mult:
	push	ebp
	mov	ebp, esp
	sub	esp, 40

	# Enter an unsigned number
	mov	DWORD PTR [esp], OFFSET FLAT:LC1
	call	_printf

	# Use _scanf to take in an unsigned number and store in local variable DWORD PTR [ebp-12]
	lea	eax, [ebp-12]			#address of local variable into eax
	mov	DWORD PTR [esp+4], eax		
	mov	DWORD PTR [esp], OFFSET FLAT:LC2
	call	_scanf				# number returned in DWORD PTR [ebp-12]

	# Use _printf to print value of unsigned number stored in local variable DWORD PTR [ebp-12]
	mov	eax, DWORD PTR [ebp-12]
	mov	DWORD PTR [esp+4], eax
	mov	DWORD PTR [esp], OFFSET FLAT:LC3
	call	_printf

	# Move the local variable into eax to return it.
	mov	eax, DWORD PTR [ebp-12]		# local variable is stored in DWORD PTR [ebp-12]
	leave
	ret

myhalve:shr eax,1
	ret

mydouble:shl eax,1
	ret

	.ident	"GCC: (tdm64-1) 9.2.0"
	.def	_putchar;	.scl	2;	.type	32;	.endef
	.def	_printf;	.scl	2;	.type	32;	.endef
	.def	_scanf;	.scl	2;	.type	32;	.endef
