Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Pipelining
- instruction
- DoM
- DB
- computer
- javascript
- web
- html
- react
- for
- DS
- CSS
- Class
- python
- Linux
- github
- DATAPATH
- while
- function
- Algorithm
- XML
- MacOS
- php
- data structure
- Java
- mysql
- MIPS
- architecture
- control
- system
Archives
- Today
- Total
YYYEJI
[MIPS] Bit-wise AND(&)로 Logical AND(&&) 구하기 본문
728x90
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를 MIPS assembly code로 변환해 보겠습니다.
c = a && b
beq $s0, $zero, label1 # if (a==0) goto label1
beq $s1, $zero, label1 # if (b == 0) goto label1
addi $s2, $zero, 1 # c = 1
j label2
label1: addi $s2, $zero, 0 # c = 0
label2: . . .
$s0 - a
$s1 - b
$s2 - c
a나 b가 하나라도 0이면 결과는 무조건 0이기 때문에 label1으로 가서 c 값에 0(false)을 넣어줍니다.
a와 b 모두 1이면 beq instruction이 실행이 안 되면서 3번째 줄의 addi가 실행됩니다.
3번째 줄의 addi instruction은 c 값에 1을 넣어주면서 결과를 참으로 넣어주게 됩니다.
◡̈
'Computer architectures' 카테고리의 다른 글
[MIPS] Switch문 assembly code (0) | 2022.10.19 |
---|---|
[MIPS] Array에서 값을 가져오고 저장하는 Assembly code (0) | 2022.10.19 |
[CA] Simple Memory Layout (0) | 2022.10.13 |
[MIPS] Procedure Call using Stack (0) | 2022.10.10 |
[MIPS] Procedure call (0) | 2022.10.10 |