leziwn.cs 2023. 9. 25. 10:01
Unsigned Numbers

 

2s-Complement Signed Integers

 

Signed Negation
  1. 숫자 뒤집기
  2. +1
  3. 부호 붙이기

 

Sign Extension
  • + --> 0
  • - --> 1

 


Representing Instructions

: Assembly language --> Binary number

  • RISC-V instructions: Encoded as 32-bit instruction words.

 

Hexadecimal

Hexadecimal

 

RISC-V R-format Instructions

R-format

  • add  destination, source 1, source 2
  • sub  destination, source 1, source 2

▶ function 7, function 3, opcode: Instruction 결정

 rd, rs1, rs2: $x0~$x31(32가지) --> 5-bit

 

R-format Example

R-format Example

 

RISC-V I-format Instructions

I-format

  • addi  destination, immediate(source)
  • lw     destination, immediate(source)

▶ rs1: source or base address

▶ immediate: constant operand or offset

  • 2s-complement, sign extended (다른 부분은 모두 unsigned)
  • 12 bits --> -2^11~(2^11-1)까지 표현 가능 (2048 bytes, 512 words)

 

I-format Example

I-format Example

 

RISC-V S-format Instructions

S-format

  • SW  source 2, immediate(source 1)

▶ rs1: base address

▶ rs2: source operand

▶ immediate: offset

  • Split so that rs1 and rs2 fields always in the same place.

 

S-format Example

S-format Example

 

Summary: R, I and S Type Instructions

R, I and S Type Instructions

 

Machine Language
  • Machine language: Binary representation used for communication within a computer system.
  • Machine code: A sequence of such instructions.
  • Instruction format: Layout of the instruction.

 

Example: Translation

A[30] = h + A[30] + 1
Translation into machine languages

 

Stored Program Computers
  • Instructions represented in binary, just like data.
  • Instructions and data stored in memory.
  • Programs can operate on programs.
  • Binary compatibility(호환성) allows compiled programs to work on different computers.

 

Example: Check Yourself

Example: Check Yourself