Sitemap
fal

fal

Computer Arithmetic

3 min readJan 10, 2025

Arithmetic and Logic Unit (ALU)

→ ALU is a core component of CPU that handle arithmetic and logical operations.

What it is for?

— for basic math (+ , — , x, ÷) = arithmetic operation

— (AND, OR, NOT, XOR) = logical operation

— for moving data bits left/right to multiply/divide = shift operation

Data Handling:

  • Data is presented to the ALU in registers.
  • Results are stored in registers.
  • Control unit sends instructions and manages data movement.
  • Flags like overflow and sign flags are set based on operation outcomes.

Integer Representation

→ Binary Format: Computers use binary (0s and 1s) to represent data.

Types of Integer Representation:

Unsigned Integers: Only positive numbers.

Signed Integers: Positive and negative numbers, represented using:

Sign-Magnitude: Uses the most significant bit (MSB) as the sign bit.

One’s Complement: Inverts all bits of a positive number to represent a negative number.

Two’s Complement: Inverts all bits of a positive number and adds 1 to represent a negative number.

Press enter or click to view image in full size

Integer Arithmetic

Negation:

Get fal’s stories in your inbox

Join Medium for free to get updates from this writer.

1.Take the Boolean complement of each bit.

2.Add 1 to get the negative version of a number.

3.The negative of a negative number returns the original number.

Addition:

  • Overflow occurs if the result of adding two numbers has the opposite sign.
Press enter or click to view image in full size

Subtraction:

  • Use two’s complement negation of the subtrahend, then add it to the minuend.

Multiplication:

  • Booth’s Algorithm: Efficiently handles multiplication, especially for signed numbers.
Press enter or click to view image in full size
Press enter or click to view image in full size

Division:

  • Restoring Division Algorithm: Handles division by repeatedly subtracting the divisor from the accumulator and shifting bits.
Press enter or click to view image in full size
Press enter or click to view image in full size

Floating-Point Representation

Components:

1.Significand: The significant digits of the number.

2.Base: The base of the number system (usually 2 for binary).

3.Exponent: Determines the scale of the number.

IEEE 754 Standard:

  • Standard for representing floating-point numbers in computers.
  • Ensures consistency and precision across different systems.

--

--