Assembly Flashcards
What decides how much work each instruction performs in an assembly setting?
The ISA.
How many bytes does each RISC-V instruction have?
4.
TRUE/FALSE: Despite different instructions in RISC-V having different purposes, each instruction has the same encoding structure.
FALSE. Each TYPE of instruction has an instruction set with the same encoding, but different parameters may be used for each.
What is R-Type encoding? Where do parameters come from, and where does output go?
Arithmetic. Register to register.
What is I-Type encoding? Where do parameters come from, and where does output go?
Immediate arithmetic. Register and immediate to register.
What is S-Type encoding? Where do parameters come from, and where does output go?
Load/Store. Memory to register and register to memory.
What is SB-Type (or B-Type) encoding? Where do parameters come from, and where does output go?
Branching. Register or immediate to Program counter.
What is UJ-Type (or J-Type) encoding? Where do parameters come from, and where does output go?
Jump and Link. Register or immediate to Program counter.
What is U-Type encoding? Where do parameters come from, and where does output go?
Load Upper immediate. Immediate to register.
How many bits are used in B-type encoding for where to jump to? Which bits? Note that 5 bits are used for rs2, 5 bits are used for rs1, 3 bits are used for funct3, and 7 bits are used for the opcode.
12 bits are used for B-Type (gotten by 32 - total of others), and the bits used are 1:12 from 0:31. This is because the last two bits don’t actually matter in jumping (since you’ll only ever jump to a whole byte), and therefore dropping 0 is fine.
Suppose I want to save the immediate value 0xffffffff into register x3. What instructions would I need, in what order?
1 instruction (if running on code):
Addi -1 (written as 0xfff but converted automatically by the processor to carry the negative) plus x0 to x3.
Why do most instructions in RISC-V use 12-bits to store immediate values?
Performance, benchmarking.
How many bytes does each x86 instruction have?
It varies. CISC is variable-width encoding.
What rule must each instruction, RISC or CISC, follow?
The longest one must be shorter than the clock period.