일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- html
- MacOS
- CSS
- DB
- XML
- function
- mysql
- github
- DS
- php
- Java
- web
- Class
- Algorithm
- while
- control
- MIPS
- for
- javascript
- computer
- data structure
- Linux
- python
- DoM
- instruction
- react
- DATAPATH
- system
- Pipelining
- architecture
- Today
- Total
목록MIPS (35)
YYYEJI
** C code를 기준 ** 아래 코드를 MIPS assembly code로 변환해 보겠습니다. switch (s) { case0: a = a case1: a = a + 1 case2: a + a + 2 default: a = a + 3 } C to MIPS assembly addi $t0, $zero, 1 # t0 = 1 addi $t1, $zero, 2 # t0 = 2 beq $s2, $zero, case0 # if (s == 0) goto case0 beq $s2, $t0, case1 # if (s == 1) goto case1 beq $s2, $t1, case2 # if (s == 2) goto case2 addi $s0, $zero, 3 # a = a + 3 j exit # goto exit ..
** C code를 기준 ** array에서 값을 가져오고 싶을 때 a = A[1]라고 작성을 하고, array에 저장하고 싶을 땐 A[1] = a라고 작성을 하게 됩니다. c 코드를 assembly code로 변환을 해보겠습니다. A[4] = A[8] + 4 lw $t0, 32($s0) # t0 = A[8] addi $t0, $t0, 4 # t0 = t0 + 4 = A[8] + 4 sw $t0, 16($s0) # A[4] = t0 $s0는 A[0]를 가르킵니다. 한 줄씩 살펴보면 lw $t0, 32($s0) # t0 = A[8] $t0에 A[8]의 값을 가져와서 저장하는데 32 값은 4*8입니다. (1 word가 4bytes이기 때문입니다.) addi $t0, $t0, 4 # t0 = t0 + 4 = ..
Procedure call을 할 때 stack을 사용합니다. ✓ main 함수는 caller ✓ label 함수는 callee ʷʰʸ main 함수에서 $s0 register을 사용하다가 jal instruction을 수행해서 label 함수로 갔을 때 label 함수도 $s0 register을 사용할 수도 있습니다. 이때, main 함수에서 $s0 값을 저장하지 않고 label 함수로 넘어간다면 main 함수의 $s0 값이 사라지게 됩니다. 그래서 caller 함수에서는 stack register의 값을 push하고 pop 할 수 있습니다. 위와 같이 register의 값을 저장하기 위해 stack을 사용합니다. ✓ Stack poiner ($sp)로 어느 stack의 위치가 active한지 알려줍니다..
Procedure 란 C에서 흔히 말하는 function을 말합니다. subroutine이라는 이름도 사용합니다. 즉, Procedure, function, subroutine은 함수를 의미하는 단어들 입니다. Procedure call 은 함수를 부르는 과정입니다. MIPS에서 procedure에 관련된 공간은 아래와 같습니다. ① $a0 ~ $a3 - argument ② $v0 ~ $v1 - return value ③ $ra - return address procedure call 을 할 때 사용하는 instruction은 JAL과 JR이 있습니다. ① JAL Label - function call 이 실행되면 ✓ $ra ← 104 (Current PC value) ✓ PC ← 200 (from 10..
Pseudo instruction란? 실제 instruction은 아니지만 컴퓨터가 이해할 수 있는 instruction입니다. ✓ 간결한 코딩이 가능 ✓ 생산성이 향상 ① COPY Ex) move $t0, $t1 → MIPS에서는 add $t0, $t1, $zero로 인식합니다. ② Branch if Less Than Ex) blt $t0, $t1, L → if ($t0 $t1) goto L ④ Branch if Greater (Less) Than or Equal to Ex) bge $t0, $t1, L → if ($t0 >= $t1) goto L ◡̈
LUI란? Load upper immediate instruction의 줄임말로써, 16bits보단 크고 32bits 보단 작은 상수를 어떻게 표현하냐에 대한 대답입니다. LUI $t0, 255 001111 00000 01000 0000 0000 1111 1111 ↓ 0000 0000 1111 1111 0000 0000 0000 0000 ↑ Upper ↑ ↑ Lower ↑ 이렇게 표현됩니다. 예제를 통해 더 자세히 알아봅시다. Q) What is MIPS assembly code for 32-bit constant "0x003D 0900" into $s0? ↓↓↓ solution ↓↓↓ LUI $t0, 0x003D ORI $s0, $t0, 0x0900 LUI 수행 없이 ORI를 실행시키면 상수가 덮어씌어..
OP code Function code Instruction format ↑↑↑ 위에 표들을 참고해서 문제를 푸시면 됩니다 ↑↑↑ Loop: add $t1, $s3, $s3 add $t1, $t1, $t1 add $t1, $s3, $s6 lw $t0, 0($t1) bne $t0, $s5, Exit add $s3, #s3, #s4 j Loop Exit: Q1) add $t1, $s3, $s3 0 19 19 9 0 32 Binary: 000000 10011 10011 01001 00000 100000 Hexadecimal: 0x02734820 Q2) add $t1, $st1, $t1 0 9 9 9 0 32 Q3) add $t1, $t1, $s6 0 9 22 9 0 32 Q4) lw $t0, 0($t1) 35..
MIPS에는 3개의 instruction format이 있습니다. ① R type - 6field ② I type - 4field ③ J type - 2 field Instruction format을 살펴보기 전에 용어부터 살펴봅시다. R type에서는 ✓ op - operation code (opcode) ✓ rs - first source operand ✓ rt - second source operand ✓ rd - destination operand ✓ shamt - shift amount ✓ funct - funcion code I type에서는 ✓ op - operation code (opcode) ✓ rs - source operand ✓ rt - destination operand 다음으로는..