In: Computer Science
Greetings!!
Code:
#DATA SEGMENT
.data
prompt: .asciiz "Please enter the value of N: "
out: .asciiz "Evaluated expression = "
#CODE SEGMENT
.text
main:
#MAIN STARTS HERE
#DISPLAY PROMPT
la $a0,prompt
li $v0,4
syscall
#READ N
li $v0,5
syscall
move $t0,$v0
#EVALUATE THE EXPRESSION
mul $t1,$t0,$t0 #n*n
sub $t1,$t1,$t0 #n*n-n
addi $t1,$t1,6 #n*n-n+6
#DISPLAY THE MESSAGE
la $a0,out
li $v0,4
syscall
#DISPLAY THE RESULT
move $a0,$t1
li $v0,1
syscall
#TERMINATION
li $v0,10
syscall
Output screenshot:
Hope this helps