	.data
promote_x:	.asciiz "x="
promote_y: 	.asciiz "y="	
output:    	.asciiz "x+y = "
return:		.asciiz "\n"
	.text 0x00400000

main:				#int main() {
	# $s0 is x		#int x,y,z;
	# $s1 is y
	# stroe z in $a0 before it is printed
				#/* input */
	la $a0, promote_x	#printf("x=");
	li $v0, 4
	syscall
	li $v0, 5		#scanf("%d",&x);
	syscall
	move $s0, $v0

	la $a0, promote_y	#printf("y=");
	li $v0, 4
	syscall
	li $v0, 5		#scanf("%d",&y);
	syscall
	move $s1, $v0			
				
	la $a0, output		#printf("x+y =");
	li $v0, 4
	syscall

	#add $a0, $s0, $s1	#z=x+y;

	#$t0 is xi			#int xi,yi,ci,zi,i;
	#$t1 is yi
	#$t2 is ci
	#$t3 is zi
	#$t4 is i 

	move $t2, $zero			#ci=0;
	move $a0, $zero			#z=0;

	li   $t4, 1			#i=1;
while:	beq  $t4, $zero, end_while	#while: if(i!=0) {
	andi $t0, $s0, 1		#	xi=x&1;
	srl  $s0, $s0, 1		#	x=x>>1;
	andi $t1, $s1, 1		#	yi=y&1;
	srl  $s1, $s1, 1		#	y=y>>1;

	xor  $t3, $t0, $t1		#	zi=xi^yi^ci;
	xor  $t3, $t3, $t2

	and  $t7, $t0, $t1		#	$t7 = xi&yi
	and  $t8, $t1, $t2		#	$t8 = yi&ci
	and  $t9, $t0, $t2		#	$t9 = xi&ci

	or   $t2, $t7, $t8		#	ci=(xi&yi)|(yi&ci)|(xi&ci);
	or   $t2, $t2, $t9
	
	beq  $t3, $zero, end_if		#	if(zi!=0) z = z|i;
	or   $a0, $a0, $t4
end_if:					#
	sll  $t4, $t4, 1		#	i=i<<1;
	j    while			#	goto while;
					#}
end_while:

	li $v0, 1		#printf("%d",z);	
	syscall			
	la $a0, return		#printf("\n");
	li $v0,4
	syscall

	li $v0, 10		#} exit
	syscall