일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- function
- react
- MacOS
- python
- html
- web
- Linux
- computer
- XML
- Algorithm
- while
- mysql
- data structure
- control
- Class
- DoM
- DATAPATH
- github
- DS
- Pipelining
- php
- instruction
- system
- architecture
- javascript
- MIPS
- for
- DB
- Java
- CSS
- Today
- Total
목록architecture (68)
YYYEJI

** C code를 기준 ** 아래 코드를 MIPS assembly code로 변환해 보겠습니다. i = 0; while (a[i] == k) i++; C to MIPS assembly addi $s0, $zero, 0 # i = 0 loop: sll $t0, $s0, 2 # t0 = i*4 addi $t0, $t0, $s2 # t0 = t0 + &a[0] lw $t1, 0($t0) # t1 = a[t0] bne $t1, $s1 exit # if (t1 != s1) goto exit addi $s0, $s0, 1 # i = i + 1 j loop # goto loop exit: $s0 - i $s1 - k $s2 - a[0] 코드를 하나하나 살펴보면 addi $s0, $zero, 0 # i = 0 우선 ..

** 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 = ..

Bit-wise AND 란? bit 하나하나 비교를 합니다. 1000 1010 ------------------ 1000 Logical AND 란? 숫자 자체를 크게 놓고 비교합니다. C programming을 기준으로 살펴보면 0이 아닌 숫자는 모두 true입니다. (. . -2, -1 , 1, 2, 3, 4 . . .) 1000 (8) 0001 (1) ------------- 1 (true) 0000 (0) 1010 (10) ------------ 0 (false) MIPS의 AND operation은 기본적으로 Bit-wise 연산을 수행합니다. logical and를 수행하는 MIPS instruction이 존재하나요 ˀ̣ ˀ̣ ˀ̣ 없습니다. 우리가 스스로 코드를 짜야 됩니다. 아래 C code..

간단하게 메모리 레이아웃에 대해서 설명해 드리겠습니다. Stack ↓ ↑ Dynamic data Static data Text Reserved ↑↑↑ Memory Layout ↑↑↑ ✓ Reserved는 op가 접근하는 부분으로 우리가 접근하려고 하면 error가 뜹니다. ✓ Text는 program code가 저장되어 있습니다. ✓ Static data에는 global variable이 저장되어 있습니다. ✓ Dynamic data는 heap 공간으로 새로운 공간이 malloc되고 free 되는 공간입니다. ✓ Stack은 function call이 일어날 때 사용되는 공간입니다. (automatic storage로 function에서 사용되는 register의 값들이 저장될 때 사용됩니다.) ◡̈

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..

Addressing mode에는 여러가지가 존재하는데 MIPS에는 어떤 addressing mode가 있는지 살펴봅시다. MIPS에 addressing mode는 아래와 같이 있습니다. ① Immediate addressing ② Register addressing ③ Base addressing ④ PC-Relative addressing ⑤ Pseudo-direct addressing ① Immediate addressing op rs rt imm 16 Ex) addi, andi, slti ② Register addressing op rs rt rd shamt function ✓ rs, rt, rd가 모두 register를 가리키고 있습니다. Ex) add, mult, and, slt, sll ③ B..