# make symbols visible to other source files
.globl read
.globl write
.globl open
.globl close
.globl exit
.globl _start

# for linux syscall numbers, see: https://chromium.googlesource.com/chromiumos/docs/+/master/constants/syscalls.md

# for most of the below functions, we are depending on the C compiler to compile our C code into assembly which 
# leaves arugments in (x86: %rdi, %rsi, %rdx) (MIPS: $a0, $a1, $a2), so we just forward to the syscall

# see beside the x86 assembly code for equivalent MIPS instructions.

	.text
_start:
	popq	%rdi		# 	pop	$a0
	movq	%rsp, %rsi	# 	move	$a1, $sp
	callq	main		# 	jal	main
	mov	%rax, %rdi	# 	move	$a0, $v0
	callq	exit		# 	jal	exit

exit:
	mov	$60, %rax	# 	li 	$v0, 17
	syscall			# 	syscall

	# does not return

read:
	mov	$0, %rax	# 	li	$v0, 13
	syscall			# 	syscall
	ret			# 	jr	$ra

write:
	mov	$1, %rax	# 	li	$v0, 14
	syscall			# 	syscall
	ret			# 	jr	$ra

open:
	mov	$2, %rax 	# 	li	$v0, 15
	syscall			# 	syscall
	ret			# 	jr	$ra

close:
	mov	$3, %rax	#	li	$v0, 16
	syscall			# 	syscall
	ret			# 	jr	$ra

