5. MIPS Instruction Set3

생성일: 2021년 9월 25일 오후 4:07

MIPS Instruction Set 정리된 pdf

Arithmetic Expression

1.

int f, g, h, i, j;
f = (g + h) - (i + j);

//MIPS Instructions
//assuming variables are assigned to $s0 ... $s4 respectively
add $s0, $s1, $s2    # $s0 = g + h
add $s1, $s3, $s4    # $s1 = i + j
sub $s0, $s0, $s1    # f = (g + h) - (i + j)

2.

if (i == j)
	i++;
j--;

//MIPS Instructions
//assuming $s1 stores i, $s2 stores j
		bne  $s1, $s2, L1    # branch if !(i == j)
		addi $s1, $s1, 1     # i++
L1: addi $s2, $s2, -1    # j--

3.

if(i == j)
	i++;
else
	j--;
j += i;

//MIPS Instructions
			bne  $s1, $s2, ELSE    # branch if !(i == j)
			addi $s1, $s1, 1       # i++
			J NEXT                 # jump over else 
ElSE: addi $s2, $s2, -1      # else j--
NEXT: add  $s2, $s2, $s1     # j += i

4.

if ( i == j || i == k)
	i++;
else
	j--;
i = i + k;

//MIPS Instructions
		  beq  $s1, $s2, IF
		  bne  $s1, $s3, ELSE
IF:   addi $s1, $s1, 1
			J NEXT
ELSE: addi $s2, $s2, -1
NEXT: add  $s1, $s1, $s3

좋은 웹페이지 즐겨찾기