Assemblers Chapter 1 and 2

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which factor most directly influences the number of operations an algorithm requires?

  • The speed of the processor.
  • The efficiency of the chosen algorithm. (correct)
  • The system's input/output capabilities.
  • The programming language used.

How does the control component of a computer system manage data flow?

  • By providing the physical pathways for data transfer.
  • By executing arithmetic operations.
  • By directing signals to orchestrate operations in the datapath, memory, and I/O. (correct)
  • By storing data for later retrieval.

Why is abstraction considered a valuable tool in computer design?

  • It enhances the speed of processors.
  • It reduces the need for memory.
  • It simplifies design by hiding lower-level details. (correct)
  • It increases the complexity of algorithms.

In the context of RISC-V architecture, what does the 'ra' register primarily store?

<p>The return address for function calls. (B)</p> Signup and view all the answers

What is the primary role of the opcode in the RISC-V instruction format?

<p>To indicate the instruction's format and type. (A)</p> Signup and view all the answers

Which addressing mode involves the operand being located at a memory address calculated by summing a register's value and a constant?

<p>Base or displacement addressing. (B)</p> Signup and view all the answers

When calling a procedure in RISC-V, what is the typical first step?

<p>Loading parameters into argument registers. (A)</p> Signup and view all the answers

Why might a compiler need to spill registers to memory?

<p>When a procedure requires more registers than available argument registers. (A)</p> Signup and view all the answers

What is the role of the Frame Pointer (fp) in RISC-V memory layout?

<p>To indicate the location of saved registers and local variables. (B)</p> Signup and view all the answers

Under what condition will the sc.w instruction fail in an atomic exchange operation?

<p>If the memory location reserved by <code>lr.w</code> has been modified. (B)</p> Signup and view all the answers

What is the primary function of a compiler?

<p>To transform high-level language into assembly language. (B)</p> Signup and view all the answers

What is the purpose of a Linker/Link Editor?

<p>To combine object modules and resolve undefined labels. (B)</p> Signup and view all the answers

How do Dynamically Linked Libraries (DLLs) contribute to program execution?

<p>By linking library routines only when the program runs. (C)</p> Signup and view all the answers

What is the role of the Java Virtual Machine (JVM) in executing Java bytecode?

<p>To read and run Java bytecode. (B)</p> Signup and view all the answers

In binary representation, what does the term '2's complement' refer to?

<p>A method for representing signed integers. (C)</p> Signup and view all the answers

During the shift and add multiplication algorithm, what operation is performed when the last bit of the multiplier is 1?

<p>The multiplicand is added to the product. (D)</p> Signup and view all the answers

In Booth's algorithm, what action is taken for a sequence of 1s in the multiplier?

<p>Rewrite the sequence using the bits immediately before and after the sequence. (C)</p> Signup and view all the answers

During the restoring division algorithm, what is done if the remainder is negative after subtracting the divisor?

<p>The divisor is added back to the remainder. (A)</p> Signup and view all the answers

When does overflow occur in addition/subtraction operations?

<p>When the result exceeds the maximum representable value. (B)</p> Signup and view all the answers

In floating-point representation, what is the purpose of the exponent?

<p>To indicate the magnitude or scale of the number. (C)</p> Signup and view all the answers

Flashcards

Algorithm

Affects the number of operations required to solve a problem.

Programming Language, Compiler, Architecture

Impacts machine instructions per operation.

Processor & Memory System

Affects the speed of execution.

Input/Output (I/O) System

Determines how fast I/O operations occur.

Signup and view all the flashcards

Little Endian

Lowest address stores the least significant byte.

Signup and view all the flashcards

Big Endian

Lowest address stores the most significant byte.

Signup and view all the flashcards

Opcode

Combined with funct7/3 to indicate instruction format/type.

Signup and view all the flashcards

Immediate addressing

Constant value within the instruction itself.

Signup and view all the flashcards

Register addressing

Operand is a register.

Signup and view all the flashcards

Base or displacement addressing

Address is sum of register and constant in the instruction.

Signup and view all the flashcards

PC-relative addressing

Branch address is sum of PC and constant.

Signup and view all the flashcards

Compiler

Transforms high-level code into assembly language.

Signup and view all the flashcards

Assembler

Converts assembly language into machine code.

Signup and view all the flashcards

Linker/Link Editor

Combines assembled programs and resolves labels.

Signup and view all the flashcards

Dynamically Linked Libraries (DLLs)

Library routines that connect to a running program.

Signup and view all the flashcards

Loader

Places a program into memory for execution.

Signup and view all the flashcards

Java Virtual Machine (JVM)

Reads and runs Java bytecode.

Signup and view all the flashcards

Just-In-Time compiler (JIT)

Special compiler that works while program is running.

Signup and view all the flashcards

Arithmetic Logic Unit (ALU)

Performs addition, subtraction, and logical operations.

Signup and view all the flashcards

Multiplicand

First number to be multiplied.

Signup and view all the flashcards

Divisor

Number that does the dividing.

Signup and view all the flashcards

Quotient

Main result after the division calculation.

Signup and view all the flashcards

Remainder

Amount left after performing division.

Signup and view all the flashcards

Study Notes

  • Assemblers Notes provides information on equations, RISC-V operations, and registers covered in Chapters 1 and 2.

Chapter 1: Equations

  • MIPS = IC / (t x 10^6)
  • t = (IC x CPI) / CR
  • CC = CPI x IC
  • Power = (1/2)(capacitive load)(voltage)^2(frequency switch)
  • timproved = (toriginal) / (improvement factor) + tunaffected
  • speedup = (toriginal) / (timproved)
  • cost/die = cost/wafer / (dies/wafer) x yield
  • dies/wafer = wafer area / die area
  • yield = (1 + (defects density x die area) / 2)^-1
  • SPECratio = treference / ttarget

Chapter 1: Definitions

  • CC (Clock Cycles): The number of clock cycles
  • CPI (Cycles Per Instruction): The number of cycles per instruction, a whole number.
  • IC (Instruction Count): Number of instructions
  • MIPS (Millions of Instructions Per Second): Measures computer performance
  • CR (Clock Rate): Measured in GHz (1 GHz = 1 x 10^9 Hz), frequency.
  • Power: Measured in Watts (1 MW = 1 x 10^6 W)
  • SPECratio: A higher ratio is better, compute geometric mean to find overall ratio
  • Capacitive Load: Measured in farads (F)

CPU Performance Factors

  • Algorithm: Affects the number of operations
  • Programming Language, Compiler, Architecture: Affects the number of machine instructions per operation.
  • Processor & Memory System: Affects the speed of operation execution involving data movement between the CPU and memory
  • Input/Output (I/O) System (includes OS): How fast I/O operations are executed by peripheral systems like monitors or printers.
  • Hardware: Includes the processor, memory, and I/O controllers as five main components.
  • Input: mechanism writes data to memory, examples include Touchscreens (resistive and capacitive types, capacitive allows multiple touches simultaneously, is used more, and is more durable)
  • Output: mechanism conveys computation results, examples include Liquid Crystal Display (LCD) screen made up of pixels (picture elements)
  • Memory: Used by the Central Processor Unit (CPU) to get instructions and data
  • Datapath: Performs computations as the path data takes
  • Control: Sends signals determining data path operations, memory usage, and input/output, managing data flow and memory access.
  • Integrated Circuit (IC): Combines dozens to millions of transistors

Seven Great Ideas In Computer Architecture

  • Use abstraction to simplify design by hiding lower-level details for a simpler model.
  • Make the common case fast to optimize performance.
  • Use parallelism to divide tasks into smaller chunks executed on different processors, increasing step speed.
  • Use pipelining as a type of parallelism to execute multiple instructions/steps simultaneously, eliminating the waiting period for the first step to complete.
  • Use prediction, guess on conditional statements (if/else) and begin the steps with your prediction and if correct, it will already be started when true/false is determined.
  • Use hierarchy of memories for efficient data storage and retrieval.
  • Use dependability via redundancy to ensure system reliability.

Chapter 2 - RISC-V ISA

  • Little Endian: Least significant byte stored in lowest address, used by RISC-V.
  • Big Endian: Most significant byte stored in lowest address, used by MIPS.

RISC-V Registers and Purposes

Register Name Number Use Preserved on Call?
zero x0 The constant value 0 N/A
ra x1 Return address (link register) Yes
sp x2 Stack pointer Yes
gp x3 Global pointer Yes
tp x4 Thread pointer Yes
t0-t2 x5-x7 Temporaries No
s0-s1 x8-x9 Saved registers and local variables for a given procedure Yes
a0-a7 x10-x17 Arguments/results No
s2-s11 x18-x27 Saved registers Yes
t3-t6 x28-x31 Temporaries No

RISC-V Instruction Types

  • opcode: 7 bits; combined with funct7 (7 bits) and funct3 (3 bits) specifies instruction format/type.
  • rs: 5-bit source register.
  • rd: 5-bit destination register
  • immediate: a 12-bit constant value

Instruction Types

Name Field Description
R-type funct7, rs2, rs1, funct3, rd, opcode Arithmetic instruction format
I-type immediate [11:0], rs1, funct3, rd, opcode Loads & immediate arithmetic
S-type immed[11:5], rs2, rs1, funct3 immed[4:0], opcode Stores
SB-type immed[12,10:5], rs2, rs1, funct3 immed[4:1,11], opcode Conditional branch format
UJ-type immediate [20,10:1, 11, 19:12], rd, opcode Unconditional jump format
U-type immediate[31:12], rd, opcode Upper immediate format
  • R-Type: register-based arithmetic and logical operations such as add, sub, sll, slt, sltu, xor, srl, sra, or, and.
  • I-Type: loads and immediate versions of arithmetic functions such as addi, slti, sltiu, xori, ori, andi, lb, lh, lw, lbu, lhu, jalr, alli, srli, srai.
  • J-Type/UJ-Format: unconditional jump format (jal), similar to U-type and has a 20-bit immediate
  • U-Type: upper immediate format (lui), has a 20-bit immediate.
  • S-Type: stores data (sb, sh, sw).
  • B-Type: conditional branch format (beq, bne, blt, bge, bltu, bgeu), similar to S-Type, immediate number is multiplied by two and target address is immediate * 2 + PC.

Addressing Modes

  • Immediate addressing: operand is constant within instruction (e.g., addi).
  • Register addressing: operand is a register (e.g., add).
  • Base or displacement addressing: operand's memory location is the sum of a register and a constant (e.g., lw).
  • PC-relative addressing: branch address is the sum of the PC and a constant (e.g., beq or jal).

Procedures - Calls and Returns, Stack Operations

  • Procedure: subroutine performing task based on parameters.

Calling Convention

  1. Load parameters into registers (a2-a7 in x12-x17).
  2. Transfer control to procedure/call (jal zero, ProcedureLabel).
  3. Acquire storage (move data to memory on the stack).
    • Spilling Registers to Memory: Compiler needs more registers, involves decrementing sp, loading return address/parameters, and remembering to restore them.
  4. Perform procedure instructions.
  5. Place result in register (a0, a1 in x10, x11).
  6. Return to place of call (jalr zero, O(ra)).

RISC-V Memory Layout

  • Frame Pointer: (stored in x8 or as fp) denotes saved registers/local variables location.
  • Stack Pointer: denotes the most recently allocated address in a stack that shows where registers should be spilled or where old register values can be found (x2 or sp in RISC-V)
  • Global Pointer: register pointing to the static area (static/outside procedure variables)
  • Heap: dynamic data structures, grows upwards in memory

Synchronization (Atomic Exchange)

  • Data Race: different threads accessing same memory location.
  • Atomic Exchange/Swap: interchanges a register's value with a memory value.
  • Ir.w and sc.w are used to atomically load and conditionally write a word, ensuring synchronization.

Translation from HLL to Machine Code

  • Compiler: transforms a high-level language program into assembly language.
  • Compiler Optimization: improves code performance and efficiency.
  • Assembly Language: symbolic language translated into binary machine language by assembler.
  • Assembler: converts assembly language instructions into machine code.
  • Linker/Link Editor: Combines separately assembled object modules, resolves undefined labels, creates executable file.
  • Object Module: header, text segment, data segment, relocation information, symbol table, debugging information.
  • Executable File: complete program format with all references resolved for execution.
  • Symbol Table: maps label names to their corresponding memory addresses.
  • Dynamically Linked Libraries (DLLs): library routines linked during execution.
  • Loader: systems program places object program into main memory for execution.
  • Basic Block: sequence of instructions without branches.

Java Translation

  • Java bytecode: Instructions read by the JVM to run Java programs on any platform
  • Java Virtual Machine (JVM): Runs Java bytecode.
  • Just-In-Time compiler (JIT): compiles bytecode into native code during runtime for faster execution.

RISC-V Coding

  • Translation of if-and-else branches, while/for loops
  • Procedures calls/returns, and stack operations
  • Analyzing and writing RISC-V code (4-10 lines)
  • Loading 32-bit immediate values into RISC-V registers, including using lui and addi instructions.

Chapter 2 - Numeric and Data Representation

  • Includes unsigned numbers, binary/decimal/hexadecimal conversions.

Numeric Concepts

  • Binary to decimal conversion: mod 2, divide by two, work bottom to top.
  • Binary to hex conversion: each set of 4 bits is one hex digit.
  • 2's complement: switch bits and add one to convert from negative to positive or vice versa.
  • Overflow problem: Addresses when results exceed representation limits.
  • Characters and strings, using the ASCII table
  • Strings: arrays of characters, length tracked by null or length
  • Bit-Extension: extend with zeros (unsigned)

Chapter 3: Multiplication

  • multiplicand: the first number
  • multiplier: the second number

Shift and add multiplication

  1. Adds the multiplicand to the product.
  2. Shifts the multiplicand left.
  3. Shifts the multiplier right.
  • signed multiplication: converting to unsigned, then converting its sign at the end.
  • Optimized multiplication: stores product register on the left, multiplier on the right

Booth's Algorithm

  • Handles consecutive ones in the multiplier efficiently.
  • Involves shift right arithmetic (sra) that handles the sign extension upon shifting right.

Action Table

  • Employs rewriting sequences of 1s to optimize multiplication.

Division

  • Division algorithm: dividend, divisor, quotient, remainder
  • Restoring division: after subtracting divisor if remainder permits.
  • Optimized division: initialized to the right for the dividend.
  • Signed division involves unsigned division then restoring the sign at the end.
  • Floating-point representation: balancing range and precision.
  • Normalized Scientific Notation: Includes significand and exponent

Floating points

  • S: significand (one non-zero digit/bit and the fraction/bit fraction)
    • 1.0 <= significand < 2.0
  • B: base 10 or 2
  • E: exponent
    • add bias number to actual exponent to make it unsigned
  • Single Precision (32 bit) - float
    • S Exponent Fraction (8 bits) (23 bits)
      • bias = 127
      • exponent range: -126 to 127
    • total range: 12^-126 to 22^127 o decimal precision: 6 digits past the decimal
  • Double Precision (64 bit) - double
    • S Exponent Fraction (11 bits) (52 bits) o bias = 1023 o exponent range: -1022 to 1023
    • total range: 12^-1022 to 22^1023
    • o decimal precision: 16 digits past the decimal
  • Half Precision
    • S Exponent Fraction1 (5 bits) (10 bits)

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser