---
# System prepended metadata

title: mips instruction set
tags: [110-2學校上課]

---

###### tags: `110-2學校上課`
# mips instruction set
## 整數系統
### addi addiu 
基本用法：addi $a0,$a1,數字
```cpp=
int a0,a1;
a0 = a1+數字
```
### add addu 
基本用法：addi $a0,$a1,$a2
```cpp=
int a0,a1,a2;
a0 = a1+a2
```
兩者差異:溢位是否會錯誤
### beq bne blt bgt 
基本用法：beq $a0,$a1,標籤
```cpp=
int a0,a1,a2;
if (狀態)
    goto 標籤

```
### beq bne blt bgt 
基本用法：beq $a0,$a1,標籤
```cpp=
int a0,a1,a2;
if (狀態)
    goto 標籤

```
### slt stli
比較設定
基本用法:
slt $a0,$a1,$a2
```cpp=
int a0,a1,a2;
a0 = a1<a2
```

## 小數系統
### add.s add.d mul.s mul.d sub.s sub.d
基本用法：addi $f0,$a=f1,數字
```cpp=
float or double a0,a1;
a0 = a1+數字
```

### beq bne blt bgt 
基本用法：beq $a0,$a1,標籤
```cpp=
int a0,a1,a2;
if (狀態)
    goto 標籤

```
### cvt.d.s  cvt.s.d
基本用法：cvt.d.s $f0,$f1,$f2
double to float or double to float

### c.le.s c.le.d
比較小數
基本用法:
slt $f1,$f2
```cpp=
double or float a1,a2;
站存器 = a1<a2
```
### bc1t
基本用法bc1t 標籤
佔存器=1 跳到標籤
## insert sort
```mips
.data
	array :.word 1,3,5,7,9,2,4,6,8,10,71,2,3,4,5,6,7,8,9,10
.text
	main:
		la $s0,array
		addi $s1,$0,1 
		for: 
			beq $s1,20,exit
			addi $s2,$0,0 
			while:
				beq $s2,$s1,BREAK
				sll $s3,$s1,2 
				sll $s4,$s2,2 
				add $s5,$s0,$s3
				add $s6,$s0,$s4
				lw $s5,($s5)
				lw $s6,($s6)
				blt $s5,$s6,insert
				addi $s2,$s2,1	
				j while
			insert:
				sll $s3,$s1,2 
				add $s5,$s0,$s3
				lw $s7,($s5)
				addi $t0,$s1,0 
				while2:
					beq $s2,$s1,end
					sll $s3,$s1,2
					addi $s4,$s1,-1
					sll $s4,$s4,2
					add $s5,$s0,$s3
					add $s6,$s0,$s4
					lw $s6,($s6)
					sw $s6,($s5)
					addi $s1,$s1,-1	
					j while2
				end:	
					sll $s3,$s1,2 
					add $s5,$s0,$s3
					sw $s7,($s5)	
					add $s1,$0,$t0
			BREAK:	
				addi $s1,$s1,1
				j for
		exit:	
				

```
## select sort
```mips
.data
	array :.word 1,3,5,7,9,2,4,6,8,10
	sort:.space 40
	ban:.space 40
.text
	main:
		la $s0,array
		la $s6,sort
		addi $s1,$0,0
		for: 
			beq $s1,10,exit
			addi $s2,$0,0 
			addi $s5,$0,9999999
			while:
				beq $s2,10,BREAK
				sll $s3,$s2,2 
				add $s4,$s0,$s3
				lw $s4,($s4)
				bgt $s4,$s5,less
				move $s5,$s4
				move $t5,$s2
				less:	
				addi $s2,$s2,1		
				j while
			BREAK:
			    sll $s7,$s1,2
			    add $s7,$s7,$s6
			    sw $s5,($s7)
			    sll $s3,$t5,2 
				add $t6,$s0,$s3
				addi $t4,$0,9999999
				sw  $t4,($t6)
				addi $s1,$s1,1 
				j for 
		exit:	
			
```