	.data 0x10000000
promptx: .asciiz "\nEvaluates x^y where x is the base and y is the exponent:\nx = "
prompty: .asciiz "y = "
output: .asciiz "x^y = "

	.text 0x00400000
	.globl main

main:

# Prompt for and read in x and y values

	la $a0, promptx
	li $v0, 4		# print_string (promptx)
	syscall

	li $v0, 5		# read_int (x)
	syscall

	move $s0, $v0		# $s0 = x
	
	la $a0, prompty
	li $v0, 4		# print_string (prompty)
	syscall

	li $v0, 5		# read_int (y)
	syscall

	move $s1, $v0		# $s1 = y

# Other variables and definitions

	li $s2, 1		# $s2 = z = 1
	li $s3, 0		# $s3 = i = 0
	
# Calculation

for_body:

	beqz $s1, for_end	# if(y == 0) break;
	
	and $t0, $s1, 1	# $t0 = y&1
	beqz $t0, if_skip	# if(y&1) {
	mul $s2, $s2, $s0	# 	x *= x;
if_skip:			# }
	
	addi $s3, $s3, 1	# i++
	mul $s0, $s0, $s0	# x *= x
	srl $s1, $s1, 1	# y >>= 1
for_cond:
	blt $s3, 32 for_body
for_end:

# Output
	
	la $a0, output
	li $v0, 4		# print_string (output)
	syscall
	
	move $a0, $s2		# $a0 = z
	
	li $v0, 1		# print_int (z)
	syscall

	li $v0, 10		# exit
	syscall