[컴퓨터구조] Logical operations

2023. 4. 14. 17:21· SKKU SW/Computer Architecture
Operation C JAVA RISC-V
Bitwise AND & & and, andi
Bitwise OR | | or, ori
Bitwise XOR ^ ^ xor, xori
Bitwise NOT ~ ~ xor, xori
Shift left << << slli
Shift right >> >>> srli

 

<AND Operations>

and x9, x10, x11

 

<OR Operations>

or x9, x10, x11

 

<XOR Operations>

xor x9, x10, x11

쉽게 생각하면 같으면 0, 다르면 1

if x11 = -1 (0xFFFFFFFF), x9 = ~x10

(x11이 모든 비트가 다 1이라면 xor 연산을 통해 1은 0으로 0은 1로 바뀔 것이기 때문)

 

<NOT Operations>

RISC-V has xori

a XORI -1 == NOT a

 

Pseudo-instruction: not

not x10, x11

-> xori x10, x11, -1

 

<Basic Shifting>

Shift types

1. Logical(or unsigned) shift

Logical shifts are useful to perform multiplication or division of unsigned integer by powers of two

2. Arithmetic(or signed) shift

Logical shifts are useful to perform multiplication or division of signed integer by powers of two

shift left의 경우는 같은데, shift right는 logical, arithmetic 각각의 값이 다르니 주의할 것.

 

Shift directions

1. Left (multiply by powers of 2)

2. Right (divide by powers of 2)

 

<Shift operations>

slli, srli

(shift left logical operation with immediate value, shift right logical operation with immediate value)

ex) slli rd, rs1, 4

 

srai

(shift right arithmetic) - extend the sign bit

useful for dividing 2's complement numbers

 

주의: slai는 존재하지 않는다.

앞서 설명했듯이, left shift는 shift, arithmetic의 결과가 동일하기 때문이다.

 

sll, srl, sra

ex) sll rd, rs1, rs2

(rs1의 값을 rs2만큼 왼쪽으로 shift해서 rd에 저장)

여기서도 마찬가지로 sla는 존재하지 않는다.

shift by the amount held in the lower 5 bits of register rs2

이게 무슨 말이나면 rs2 값의 앞부분은 잘라 먹고 lower 5 bits만 가져와서 그만큼 shift한다는 거다.

 

이전 글에서 공부했던 load operation인 li도 함께 적용해서 보자면

li x10, 200

li x11, 100

sll x12, x10, x11

일단 200을 x10에 저장, 100을 x11에 저장한뒤

100 = 64 + 32 + 4 니까 이를 32비트로 나타내면 0000 0000 0000 0000 0000 0000 0110 0100

그 중 하위 5비트만 가져온다면 00100 -> 10진수로 나타내면 4

x10에 저장되어 있는 200을 4만큼 left shift하겠다는 뜻!

 

200 = 128 + 64 + 8 이니까 0000 0000 0000 0000 0000 0000 1100 1000

이를 4만큼 left shift 하면?

0000 0000 0000 0000 0000 1100 1000 0000

사실 이렇게 하나씩 계산할 필요 없이 4만큼 left shift는 2^4, 즉 16을 곱한 것과 같으므로

200 x 2^4 = 3200으로 계산하면 된다.

 

shift right arithmetic 값은 "round down"한다.

'SKKU SW > Computer Architecture' 카테고리의 다른 글

[컴퓨터구조] RISC-V Instruction Formats(2)  (0) 2023.04.15
[컴퓨터구조] RISC-V Instruction Formats(1)  (0) 2023.04.14
[컴퓨터구조] Immediate Operands, Load Immediate Value  (0) 2023.04.14
[컴퓨터구조] 명령어(instruction) / 명령어집합(instruction set) 그리고 간단한 arithmetic operation  (0) 2023.04.14
1.0E6이 뭐야  (0) 2023.04.14
'SKKU SW/Computer Architecture' 카테고리의 다른 글
  • [컴퓨터구조] RISC-V Instruction Formats(2)
  • [컴퓨터구조] RISC-V Instruction Formats(1)
  • [컴퓨터구조] Immediate Operands, Load Immediate Value
  • [컴퓨터구조] 명령어(instruction) / 명령어집합(instruction set) 그리고 간단한 arithmetic operation
효딩
효딩
개ㄱ발은 기세다. 줄여서 객기.
효딩
hyoding
효딩
전체
오늘
어제
  • 분류 전체보기 (245)
    • SKKU SW (30)
      • Computer Architecture (14)
      • Database (4)
      • Computer Network (3)
      • Operating System (7)
      • Mobile App Programming (2)
    • SuperCoding (68)
    • CS (8)
    • Web Programming (19)
    • Cloud (13)
    • Languages (45)
      • Python (8)
      • Java (37)
    • Supporters (8)
      • MoteMote (6)
      • NHN Cloud (2)
    • Certification (27)
      • Network Advisor (14)
      • ADsP (10)
      • Engineer Information Proces.. (3)
    • Finance (9)
      • 경제금융용어 (3)
    • Woori FISA (14)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 서버개발
  • 네트워크관리사2급
  • 앱개발
  • 클라우드
  • Kotlin
  • AWS
  • 우리FISA
  • 인프라
  • 클라우드서비스개발
  • 네트워크관리사 커트라인
  • apppaas
  • 글로벌소프트웨어캠퍼스
  • 네트워크관리사2급 공부방법
  • 우리에프아이에스
  • nhn cloud
  • 네트워크관리사 후기
  • 서버생성
  • 봐
  • K-디지털트레이닝
  • 네트워크관리사 준비물
  • 인프라개발
  • 클라우드 서비스
  • rds local 접속
  • 우리fis아카데미
  • 서버배포
  • 코틀린
  • 코틀린문법
  • 네트워크관리사
  • 네트워크관리사2급 필기
  • 네트워크관리사 합격

최근 댓글

최근 글

hELLO · Designed By 정상우.v4.2.2
효딩
[컴퓨터구조] Logical operations
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.