5.1.2 · D1Instruction Set Architecture (ISA)

Foundations — Instruction formats and encoding

2,831 words13 min readBack to topic

This page assumes you have seen nothing. We will build every symbol the parent note Instruction formats and encoding uses — one at a time, each one anchored to a picture, each one earned before we use it. Nothing here is memorised; everything is derived.


0. The most basic object: a bit

Figure s01 below draws a row of eight bulbs: lit bulbs (butter-yellow) are 1s, dim grey bulbs are 0s. Look at the leftmost bulb — it is one bit, and the little arrow points to it. The green line underneath brackets all eight bulbs together; that grouping is what we will call a byte in a moment.

Figure — Instruction formats and encoding

1. A group of bits: binary numbers and

If one bit holds 2 possibilities, what does a group of bits hold?

Add one bit → each old pattern can now end in 0 or 1 → the number of patterns doubles. So:

  • 1 bit → 2 patterns
  • 2 bits → 4 patterns
  • 3 bits → 8 patterns
  • bits → patterns.

Figure s02 turns this into a bar chart: each bar is taller than the one before it by a factor of two, and the coral arrows between bars say "×2 again". That visual doubling is the meaning of .

Figure — Instruction formats and encoding

From a bit pattern to an actual number: positional weights

We keep saying " is a number" — let us earn that, because the whole topic leans on it.

Take (five bits). Line up positions from the right:

Add the weights where the bit is : .


2. The inverse question: and the ceiling

The parent note writes . Let us earn every symbol.

The question we are really asking: "I have different things (say 32 registers). How many bits do I need so that is at least ?"

But — you cannot have 6.64 switches. Bits are whole, and 6 bits ( patterns) is too few. We must round up to 7.

Figure s03 puts , , on a line and drops a coral marker at "need 100". You can see 64 sits left of the marker (too few) and 128 sits right (fits), so the answer must round up from to .

Figure — Instruction formats and encoding

3. A named group of bits: a field

Before we name fields we must agree how to count the bit positions — otherwise "bits 0 through 6" is ambiguous.

Figure s04 draws the 32-bit word as six rounded, pastel boxes. Notice the labels along the bottom: "high bits (left)" and "bit 0 (right)" — that is our convention made visible. The coral opcode box sits at the far right (bits 0–6); the arrow reminds you the decoder looks there first.

Figure — Instruction formats and encoding

The two field-names the parent leans on:

  • opcode — the "what job" field (add? jump? load?). Always in the same position so the decoder finds it first.
  • operand fields — the "what to do it to": register numbers, or an immediate.

4. Two special operands: register and immediate

registers bits per register field. That "5" you keep seeing is not magic — it is Section 2 applied to 32.


5. Negative immediates: two's complement and sign extension

addi x1, x2, -8 must work, so a field must be able to mean a negative number.

Building it from the positional weights of Section 1. In an unsigned -bit number every bit has weight . Two's complement changes exactly one thing: the top bit's weight becomes negative, , while every lower bit keeps its usual .

Watch it work on 4 bits (, so the top weight is ):

The range then falls straight out of the weights. The most negative value turns on only the top bit: . The most positive turns on every bit except the top: . So:

For the 12-bit immediate the parent quotes: to to . See Two's Complement and Sign Extension for the full treatment.


6. Putting the symbols together

Now every symbol in the parent's tally makes sense on sight:

  • are field widths in bits (Section 3).
  • Each came from (Sections 2 & 4).
  • The sum being exactly is the fixed budget the parent keeps stressing.

Related building topics you can now approach: Addressing Modes (how operand fields name memory), RISC vs CISC (fixed vs variable width philosophy), Pipelining (why fast fixed decode matters).


Prerequisite map

bit = one on off switch

b bits give 2 to the b patterns

positional weights map bits to a number

log base 2 undoes the doubling

ceiling rounds bits up to whole

field = named slice of bits

register number field 5 bits

immediate constant in the bits

two complement flips top weight negative

sign extension widens keeping value

Instruction format and encoding


Equipment checklist

Say each answer out loud before revealing it.

A bit stores how many possible values
Exactly two — 0 or 1.
How many bits in a byte, and in a word here
A byte is 8 bits; a word is 32 bits (4 bytes) on these machines.
How many distinct patterns fit in bits
.
What number is binary , and how
, summing the position weights where a bit is 1.
Which end is bit 0
The rightmost (lowest-weight, ) bit; higher indices go leftward.
answers what question
"2 to the what power gives ?" — it undoes .
Why the ceiling in
Bits are whole numbers, so we round up so .
What does the formula give for
— a zero-width field, since one choice carries no information.
How many bits to index 32 registers
.
What is a field
A fixed, named slice of the instruction word with an agreed meaning.
Which field's position is frozen, and why
The opcode, so decode can always find "what job" first without a chicken-and-egg problem.
What do funct3 and funct7 do
Sub-select the exact operation inside one shared opcode family (e.g. tell add from sub).
Difference between a register operand and an immediate
A register field holds a number naming a storage box; an immediate holds the constant value itself.
In two's complement, what weight does the top bit carry
(negative), while all lower bits keep .
Range of a 12-bit two's-complement immediate
to , i.e. to .
Why sign extension copies the top bit instead of padding zeros
To keep negative numbers negative; zero-padding would turn them into large positives.