#	Chapter 2 example
#	Reverses the order of the first four bytes (characters/letters) within a string provided by user
#	Demonstrates shifting and bitwise operations for "bit twiddling"
	
	.data
str:	.space		1024

	.text
loop:	li	$v0,8			# set up system call (read string)
	la	$a0,str			# set $a0 = address of string
	li	$a1,1024		# set $a1 = string length
	syscall				# perform syscall
	
	lw	$s0,str			# $s0 = first four letters of string
	sll	$t0,$s0,24		# move byte 0 to position 3 (bytes are ordered as 3 2 1 0)
	sll	$t1,$s0,8		# move bytes 2:0 to positions 3:1
	andi	$t1,$t1,0x00FF0000	# mask off byte 2 (originally byte 1)
	srl	$t2,$s0,24		# move byte 3 to position 0 (bytes are ordered as 3 2 1 0)
	srl	$t4,$s0,8		# move bytes 3:1 to positions 2:0
	andi	$t4,$t4,0x0000FF00	# mask off byte 1 (originally byte 2)
	or	$t0,$t0,$t1		# combine bytes 3 with 2
	or	$t0,$t0,$t2		# combine bytes 3,2 with 0
	or	$t0,$t0,$t4		# combines bytes 3,2,0 with 1
	
	li	$t1,0			# set up null character
	li	$s2,4			# 4th byte
	sb	$t1,str($s2)		# store into string (terminate after first four letters)
	
	sw	$t0,str			# store reversed bytes into first word of string
	li	$v0,4			# set up syste call 4
	syscall 			# initiate system call
	
	
