//Two-address Memory-to-register code

//Add the absolute values of every element in array DAT and 
//save the sum to SUM and print it on the screen
//Declaration 
SUM 	1	0		//Sum
NUM 	1 	9		//Number of elements in the array
DAT 	9 	10 20 30 -40 50 60 70 80 -90 	//Array of integers
END
//Instructions
	GET	 $t0 NUM		//$t0 = N
	LA   $s0 DAT		//$s0 = address of DAT
	LI 	 $a0 0			//$a0(sum) = 0
L1:	BEQZ $t0 L3			//If no remaining element, done
	GET  $t1 $s0		//Get an array element into %t1
	BGEZ $t1 L2 		//If positive, skip 
	NEG  $t1			//Else, negate $t1
L2:	ADD  $a0 $t1		//Add to $a0(sum)
	ADDI $t0 -1			//Decrease number of remaining elements
	ADDI $s0 1 			//Next element
	GOTO L1				//Next iteration
L3:	PUT	 $a0 NUM		//Save the sum to SUM
	PRNT				//Print sum on screen
	STOP			 	//Terminate program
END
//Input
//None