# Live coding exercises from recap lecture
# A simple example of a program with functions
# These functions have no parameters or return values
# (except for main that returns 0)
# This code is broken!

	.data
msg_main1: 	.asciiz "I am in the main\n"
msg_main2: 	.asciiz "I am about to return from the main function\n"
msg_f1: 	.asciiz "I am in the f function\n"
msg_f2: 	.asciiz "I am about to return from the f function\n"
msg_g1:		.asciiz "I am in the g function\n"

	.text
main:
	li	$v0, 4			#printf("I am in the main");
	la	$a0, msg_main1
	syscall

	jal	f			# f()

	li	$v0, 4			#printf("I am in the main");
	la	$a0, msg_main2
	syscall

	li	$v0, 0			# set return value for main to be 0
	jr	$ra			# return from main to (__start)

f:
	li	$v0, 4			#printf("I am in the f function");
	la	$a0, msg_f1
	syscall

	jal	g			# g()

	li	$v0, 4			#printf("I am in the f function");
	la	$a0, msg_f2
	syscall
	jr	$ra			#return

g:
	li	$v0, 4			#printf("I am in the g function");
	la	$a0, msg_g1
	syscall
	jr	$ra			#return