Sie sind auf Seite 1von 12

Tampere University of Technology - Institute of Digital and Computer Systems

8404120 Computer Architectures

MIPS assembler
Spring 2004

Jouni Riihimäki
Jouni.riihimaki@tut.fi

Jouni Riihimäki / TUT / 21.1.2004


MIPS and operands

† SPIM simulator for MIPS R2000/3000 processors


† Operands
 32 registers ($1, $2, … $31)
† for arithmetic and logical operations
 230 memory locations (mem[0], mem[1],… mem[230]
† only for load/store operations
† byte addressing => subsequent addresses differ by 4 (e.g. 0,4,8 …)

Jouni Riihimäki / TUT / 21.1.2004


Addressing modes

† Virtual machine provides 6 modes (processor has only one)


 (register)
 immediate
 immediate (register)
 label
 label ± immediate
 label ± immediate (register)

Jouni Riihimäki / TUT / 21.1.2004


Arithmetic operations

† command example: add (addition)


† format: add a b c
† explanation: a = b + c

† example of use:
 add $t5 $t5 32
 this command adds 32 to register t5

Jouni Riihimäki / TUT / 21.1.2004


Logical instructions

† command example: and (logical and)


† format: and a b c
† explanation: a = b and c

† example of use:
 and $v1 $v1 $zero
 clear register v1 (zero always 0)

Jouni Riihimäki / TUT / 21.1.2004


Constant-manipulating instructions

† command example: li (load immediate)


† format: li a imm
† explanation: loads immediate value to a

† example of use:
 li $v0 4
 load register v0 with 4

Jouni Riihimäki / TUT / 21.1.2004


Comparison instructions

† command example: seq (set on equal)


† format: seq a b c
† explanation: if b = c then a = 1 else a = 0

† example of use:
 seq $v1 $v1 $v0
 set v1 to 1 if v1 equals v0, otherwise set v1 to 0

Jouni Riihimäki / TUT / 21.1.2004


Branch instructions

† command example: beq (branch if equal)


† format: beq a b label
† explanation: branch to label if a = b

† example of use:
 beq $v1 $v0 next_label
 if v1 equals v0 branch to next_label

Jouni Riihimäki / TUT / 21.1.2004


Jump instructions

† command example: jr (jump register)


† format: jr a
† explanation: jump to address pointed to by register a

† example of use:
 jr$ra
 jump to instruction whose address is in register ra

Jouni Riihimäki / TUT / 21.1.2004


Load / Store instructions

† command example: lw / sw (load word / store word)


† format: lw a address
† explanation: load word from address to register a

† example of use:
 lw $t4 ($t0)
 load word from address given in register t0 to t4

Jouni Riihimäki / TUT / 21.1.2004


Data movement instructions

† command example: move (move from register to register)


† format: move a b
† explanation: move value from register b to a

† example of use:
 move $t0 $a0
 move value from register a0 to to

Jouni Riihimäki / TUT / 21.1.2004


Other instructions

† Floating point instructions

† Exception instructions
 e.g. syscall

† NOP (no operation)

Jouni Riihimäki / TUT / 21.1.2004

Das könnte Ihnen auch gefallen