# absolute value through shift and xor # # .data promp1: .asciiz "\n Enter num: " outmsg: .asciiz "\nThe absolute value is " .globl main .text main: # read the num read: li $v0, 4 # system call code for print string la $a0, promp1 # load addr of promp1 in $a0 syscall # print prompt li $v0, 5 # system call code for read int syscall # read num into $v0 move $t1,$v0 # $t1 is num sra $t2, $t1, 31 # propagate sign through register t2 xor $t3, $t2, $t1 # t3 is xor of num and num >> 31 sub $t4, $t3, $t2 # the abs value print: li $v0, 4 # system call code for print string la $a0, outmsg # load addr of promp2 in $a0 syscall # print abs message li $v0, 1 # code to print int move $a0, $t4 # print abs syscall # exit from program li $v0, 10 # terminate execution and syscall # return control to system