	.section	.rodata
printf_arg:
	.string "%d"
	.text
.globl main
	.type	main, @function
main:
	push $10              # push argument in stack
	call foo              # call foo function
	add $4, %esp          # restore stack pointer - pop argument
	mov $0, %eax          # set main return value
	ret                   # return
.globl print_int
	.type	print_int, @function
print_int:
	mov 4(%esp), %eax     # get argument from stack
        push %eax             # push printf second argument - the value
	push $printf_arg      # push printf first argument - "%d" string
	call printf           # call printf number was already in stack
	add $8, %esp          # restore stack pointer - pop two arguments
	ret                   # return
.globl print_char
	.type	print_char, @function
print_char:
	mov 4(%esp), %eax     # get argument from stack
	push %eax             # push argument in stack
	call putchar          # call putchar code was already in stack
	add $4, %esp          # restore stack pointer - pop argument
	ret                   # return
.globl foo
	.type	foo, @function
foo:
	mov $1, %eax          # save iterated value (i) in eax
	mov 4(%esp), %ebx     # save number of values to print (j) in ebx
	jmp foo_loop_cond     # go check the loop condition
foo_loop:
	push %eax             # save i in stack
	push %ebx             # save j in stack
	push %eax             # push i as argument in stack
	call print_int        # call the print_int function
	add $4, %esp          # restore stack pointer - pop argument of print_int
	push $32              # push space character code as argument in stack
	call print_char       # call the print_char functin
	add $4, %esp          # restore stack pointer - pop argument of print_char
	pop %ebx              # restore j from stack
	pop %eax              # restore i from stack
	add $1, %eax          # increment i
foo_loop_cond:
	cmp %ebx, %eax        # compare eax and ebx
	jle foo_loop          # jump back if eax <= ebx
	push $10              # push new line code as argument of print_char
	call print_char       # call print_char function to print new line
	add $4, %esp          # restore stack pointer - pop argument of print_char
	ret                   # return
