BLOGGER TEMPLATES AND TWITTER BACKGROUNDS »

Saturday 15 December 2012

Computer Language : Arithmetic Operation


Arithmetic Operation
·         Arithmetic operations are performed on 32-bits numbers held in the general purpose registers (32-bit each)
·         Two types of instruction are included in this operation :
1.      Signed arithmetic : may generate an overflow
2.      Unsigned arithmetic : never generate an overflow
Category
Instruction
Example
Meaning

                             

Arithmetic


add
add $1,$2,$3
$1 = $2 + $3
add immediate
addi $1,$2,100
$1 = $2 + 100
add unsigned
addu $1,$2,$3
$1 = $2 + $3
add immediate unsigned
addi $1,$2,100
$1 = $2 + 100
subtract
sub $1,$2,$3
$1 = $2 - $3
subtract unsigned
subi $1,$2,$3
$1 = $2 - $3
multiplication
mult $1,$2
 mflo $3
$1*$2
quotient store in $3
division
div $1,$2
mflo $3
mfhi $4
$1/$2
quotient store in $3
remainder store in $4

Example :
a.)    f = (g + h) - (i + j);                        #Assume f, g, h, i, j uses $s0, .. $s4

add $s0,$s1,$s2       # f = g + h
add $t0,$s3,$s4       # t0 = i + j
sub $s0,$s0,$t0       # f=(g+h)-(i+j)

b.)    a = c/d
a = c%d                                    #Assume a,b,c,d uses $s0…..$s4

div     $s2, $s3             # lo=c/d , hi=c%d
mflo  $s0                     #store quotient in $s0
mfhi  $s1                     #store remainder in $s1

By : Chong Lee Man   B031210367

0 comments: