# 3827 Homework 3, problem 1, "strncat"
#
# <your name here>, <your uni here>
#
# Invoke with, e.g., spim -file strncat.s
#	
	.text
	# $a0 : dest
	# $a1 : src
	# $a2 : n	
strncat:
	# REPLACE WITH YOUR CODE
	move	$v0, $a0	# return dest
	jr $ra

######################################################################
#
# Test harness: extend to add tests
#	
	      
	.data
hello:
	.asciiz "Hello "
	.space 256		# Space for the copied string
world:
	.asciiz "World!\n"
threeeight:
	.asciiz "3827 sucks"
	.space 256		# Space for the copied string
youin:
	.asciiz " you in with wonderful ideas\n"
newline:
	.asciiz "\n"
	
	.text
	.globl main

main:
	la	$a0, hello
	li	$v0, 4	# print_string	
	syscall
	la	$a0, world
	li	$v0, 4
	syscall			# Prints "Hello World!\n"

	la	$a0, hello
	la	$a1, world
	li	$a2, 100
	jal	strncat
	move	$a0, $v0	# Should print "Hello World!\n"
	li	$v0, 4
	syscall

	la	$a0, newline
	li	$v0, 4
	syscall

	la	$a0, hello
	sb	$zero, 6($a0)	# put back the terminator
	la	$a1, world
	li	$a2, 2
	jal	strncat
	move	$a0, $v0
	li	$v0, 4
	syscall			# Should print "Hello Wo"

	la	$a0, newline
	li	$v0, 4
	syscall

	la	$a0, threeeight
	li	$v0, 4
	syscall
	la	$a0, youin
	li	$v0, 4
	syscall		# Prints "3827 sucks you in with wonderful ideas\n"

	la	$a0, threeeight
	la	$a1, youin
	li	$a2, 100
	jal strncat
	move 	$a0, $v0
	li	$v0, 4
	syscall		# Should print "3827 sucks you in with wonderful ideas\n"
	
	la	$a0, newline
	li	$v0, 4
	syscall

	la	$a0, threeeight
	sb	$zero, 10($a0)	# put the terminator back
	la	$a1, youin
	li	$a2, 7
	jal strncat
	move 	$a0, $v0
	li	$v0, 4
	syscall		# Should print "3827 sucks you in"

	la	$a0, newline
	li	$v0, 4
	syscall	
	
	li	$v0, 10 # exit
	syscall
