You are on page 1of 8

Arithmetic Instructions

Instruction E.g. Meaning Comments

Add add $s1, $s2, $s3 $1=$2+$3

Subtract sub $1,$2,$3 $1=$2-$3

Add immediate addi $1,$2,100 $1=$2+100 "Immediate" means a constant number

Add unsigned addu $1,$2,$3 $1=$2+$3 Values are treated as unsigned


integers, not two's complement
integers

Subtract unsigned subu $1,$2,$3 $1=$2-$3 Values are treated as unsigned


integers, not two's complement
integers

Add immediate addiu $1,$2,100 $1=$2+100 Values are treated as unsigned


integers, not two's complement
unsigned integers

Multiply (without mul $1,$2,$3 $1=$2*$3 Result is only 32 bits

overflow)
Multiply mult $2,$3 $hi,$low=$2*$3 Upper 32 bits stored in special register
hi. Lower 32 bits stored in special
register lo

Divide div $2,$3 $hi,$low=$2/$3 Remainder stored in special register hi.


Quotient stored in special register lo
29
Logical Instructions
Instruction E.g. Meaning
and and $1,$2,$3 $1 = $2 & $3 Bitwise AND
or or $1,$2,$3 $1 = $2 | $3 Bitwise OR
xor xor $1,$2,$3 $1 = $2 ??$3 Bitwise XOR
nor nor $1,$2,$3 $1 = ~($2 | $3) Bitwise NOR
and immediate andi $1,$2,10 $1 = $2 & 10 Bitwise AND reg, const
or immediate ori $1,$2,10 $1 = $2 | 10 Bitwise OR reg, const
xor immediate xori $1, $2,10 $1 = ~$2 &~10 Bitwise XOR reg, const
shift left logical sll $1,$2,10 $1 = $2 << 10 Shift left by constant

shift right logical srl $1,$2,10 $1 = $2 >> 10 Shift right by constant

shift right arithm. sra $1,$2,10 $1 = $2 >> 10 Shift right (sign extend)

shift left logical sllv $1,$2,$3 $1 = $2 << $3 Shift left by var

shift right logical srlv $1,$2,$3 $1 = $2 >> $3 Shift right by var

shift right arithm. srav $1,$2,$3 $1 = $2 >> $3 Shift right arith. by var

30
Labels

• Symbolic labels to point to next instructions


• Assembler will calculate the appropriate
address for the program counter to
jump/branch to the specified label

31
Control Instructions

• Jumping and branching


• Will move the program counter to point to
another instruction (line)

32
Control Instructions
Branch

33
Control Instructions
Jump

34
Services

Max no. of characters INCLUDING ‘\0’

35
Services
Service 8 - Follows semantics of UNIX 'fgets'. For specified length n,
string can be no longer than n-1. If less than that, adds newline to
end. In either case, then pads with null byte. If n = 1, input is
ignored and null byte placed at buffer address. If n < 1, input is
ignored and nothing is written to the buffer.
Service 11 - Prints ASCII character corresponding to contents of low-
order byte.
Service 13 - Three flag values: 0 for read-only, 1 for write-only with
create, and 9 for write-only with create and append. It ignores
mode. The returned file descriptor will be negative if the operation
failed. The underlying file I/O implementation. File descriptors are
tracked internally and allocated starting with 3. File descriptors 0, 1
and 2 are always open for: reading from standard input, writing to
standard output, and writing to standard error, respectively.
36

You might also like