Computer Organization and Arithmetic
What to remember
- A computer has an input unit, a CPU (ALU, control unit, registers), memory and an output unit, joined by buses. Instructions run in a fetch-decode-execute cycle.
- Memory forms a hierarchy: registers, cache, main memory, secondary storage. Faster means smaller and costlier.
- Binary arithmetic uses two's complement for negative numbers; know addition rules, overflow, and the IEEE 754 floating-point format.
1. Basic structure and Von Neumann model
In the Von Neumann (stored-program) model, instructions and data are kept in the same memory and the CPU fetches them one by one. The Harvard architecture uses separate memories for instructions and data. The main parts are:
- Input and output units, such as keyboard, mouse, monitor, printer.
- CPU (processor): the ALU (Arithmetic and Logic Unit) does arithmetic and logic; the Control Unit (CU) directs all operations; registers are tiny, very fast stores inside the CPU.
- Memory: primary (RAM, ROM) and secondary.
Important registers: Program Counter (PC) holds the address of the next instruction; Instruction Register (IR) holds the current instruction; Memory Address Register (MAR) holds the address to be accessed; Memory Data (Buffer) Register (MDR/MBR) holds the data moving to or from memory; Accumulator (AC) holds results of the ALU; Status/Flag register holds flags such as carry, zero, sign and overflow.
2. Buses and the instruction cycle
A bus is a set of wires that carries signals.
| Bus | Carries | Direction |
|---|---|---|
| Address bus | Memory or I/O address | One way, from CPU |
| Data bus | Data | Two way |
| Control bus | Control signals (read, write, clock) | Mostly from CPU |
The width of the address bus decides the memory size: an n-bit address bus can address 2ⁿ locations. Example: a 16-bit address bus gives 2¹⁶ = 65,536 = 64 K locations.
Instruction cycle: (1) Fetch the instruction from the address in the PC and increase the PC; (2) Decode it in the control unit; (3) Execute it; (4) store the result if needed. An interrupt is a signal that makes the CPU pause the present program and run a service routine. Clock speed is measured in hertz (MHz, GHz). Pipelining overlaps the stages of several instructions to raise throughput.
3. Instructions and addressing
An instruction has an opcode (the operation) and operands (the data or addresses). The instruction set is the full list of instructions a CPU supports. Types of architecture: CISC has many complex instructions of varying length; RISC has fewer simple, fixed-length instructions, usually one per cycle.
Addressing modes: immediate (the operand is in the instruction), direct (the address is given), indirect (the address of the address is given), register, indexed, and relative. Instruction formats by the number of addresses: zero-address (stack), one-address (uses accumulator), two-address and three-address.
4. Memory hierarchy
| Level | Speed | Size | Cost per bit |
|---|---|---|---|
| Registers | Fastest | Smallest | Highest |
| Cache | Very fast | Small | High |
| Main memory (RAM) | Fast | Medium | Medium |
| Secondary (HDD, SSD) | Slow | Large | Low |
- RAM is volatile and read-write. SRAM (static) is faster, uses flip-flops and is used for cache; DRAM (dynamic) is cheaper, uses capacitors and needs refreshing; it is used for main memory.
- ROM is non-volatile. Types: PROM (programmable once), EPROM (erased by UV light), EEPROM (erased electrically), and flash memory.
- Cache memory holds frequently used data between CPU and RAM. A hit means the data is found in cache; a miss means it is not. Hit ratio = hits ÷ total accesses. Mapping methods: direct, associative and set-associative.
- Virtual memory uses disk to extend RAM. Locality of reference (programs reuse nearby data) is why cache works.
- Access time is the time to read or write; cycle time is the minimum time between two accesses.
Units: 1 byte = 8 bits; 1 KB = 1,024 bytes; 1 MB = 1,024 KB; 1 GB = 1,024 MB; 1 TB = 1,024 GB.
5. Input-output organization
I/O can be done by programmed I/O (CPU waits and checks the device), interrupt-driven I/O (the device interrupts when ready) and DMA (Direct Memory Access), where a DMA controller moves blocks between device and memory without the CPU, freeing it for other work. Ports connect devices; examples are USB, HDMI and serial/parallel ports. Interface chips and buffers handle speed differences.
6. Binary arithmetic
Binary addition: 0+0=0, 0+1=1, 1+0=1, 1+1=10 (sum 0, carry 1), 1+1+1=11 (sum 1, carry 1).
Example: 1011 + 0110 = 10001 (11 + 6 = 17).
Binary subtraction: 0−0=0, 1−0=1, 1−1=0, 0−1=1 with a borrow of 1. Example: 1010 − 0011 = 0111 (10 − 3 = 7).
Binary multiplication is shift-and-add: 101 × 11 = 101 + 1010 = 1111 (5 × 3 = 15). Division is repeated subtraction.
Complements: 1's complement is found by flipping every bit. 2's complement = 1's complement + 1. Subtraction by 2's complement: A − B = A + (2's complement of B), and a final carry out is discarded.
Example: 7 − 5 with 4 bits. 5 = 0101; 1's complement 1010; 2's complement 1011. 0111 + 1011 = 1 0010; discard the carry, result 0010 = 2.
Signed number representation (n bits):
| Method | Range |
|---|---|
| Sign-magnitude | −(2ⁿ⁻¹−1) to +(2ⁿ⁻¹−1) |
| 1's complement | −(2ⁿ⁻¹−1) to +(2ⁿ⁻¹−1) |
| 2's complement | −2ⁿ⁻¹ to +(2ⁿ⁻¹−1) |
For 8 bits, 2's complement range is −128 to +127. In 2's complement there is only one zero. The most significant bit (MSB) is the sign bit (0 positive, 1 negative).
Overflow: in signed addition, overflow occurs when two numbers of the same sign give a result of the opposite sign. Adding a positive and a negative number never overflows. Example (8 bit): 100 + 50 = 150 exceeds 127, so overflow. For unsigned numbers, a carry out of the MSB shows overflow.
7. Floating-point and hardware adders
A floating-point number has a sign, an exponent and a mantissa (fraction). IEEE 754 single precision uses 32 bits: 1 sign bit, 8 exponent bits (bias 127) and 23 fraction bits. Double precision uses 64 bits: 1 sign, 11 exponent (bias 1023), 52 fraction. The value is (−1)^sign × 1.fraction × 2^(exponent − bias). Example: 1.0 has exponent 127 = 01111111 and fraction 0. Normalisation keeps the leading digit as 1.
Half adder adds two bits: Sum = A XOR B, Carry = A AND B. Full adder adds three bits (A, B, carry-in): Sum = A ⊕ B ⊕ Cin, Carry = AB + Cin(A ⊕ B). A full adder can be built from two half adders and an OR gate. A ripple-carry adder chains full adders; a carry-look-ahead adder is faster.
Worked examples
- 1. Memory size: A 12-bit address bus addresses 2¹² = 4,096 locations = 4 K. If each location holds 1 byte, the memory is 4 KB.
- 2. Hit ratio: 90 hits in 100 accesses give a hit ratio of 0.9. If cache time is 10 ns and main memory time is 100 ns, average access time = 0.9 × 10 + 0.1 × 100 = 19 ns (simple model).
- 3. Subtraction by 2's complement (8 bit): 25 − 10. 10 = 00001010; 1's complement 11110101; 2's complement 11110110. 25 = 00011001. Sum = 1 00001111; discard the carry, result 00001111 = 15.
- 4. Negative number: −5 in 8-bit 2's complement: 5 = 00000101; flip to 11111010; add 1 gives 11111011.
- 5. Instruction time: A 2 GHz clock has a period of 0.5 ns. An instruction that needs 4 clock cycles takes 2 ns.
- 6. Capacity: A memory of 64 K words with 16 bits per word stores 64 × 1,024 × 16 bits = 1,048,576 bits = 128 KB.
Exam traps
- Fetch happens first; the PC points to the next, not the current, instruction.
- SRAM is faster and costlier; DRAM needs refreshing.
- 1 KB is 1,024 bytes in computer memory units.
- 2's complement has one zero; sign-magnitude and 1's complement have two.
- A carry out in 2's complement subtraction is discarded, not an error.
- Address bus is one way; data bus is two way.
- RISC has fewer, simpler instructions; CISC has many complex ones.
- Cache is between CPU and RAM; virtual memory uses disk.
One-liners
- 1. The ALU performs arithmetic and logic operations.
- 2. The PC holds the address of the next instruction.
- 3. The accumulator stores ALU results.
- 4. An n-bit address bus can address 2ⁿ locations.
- 5. SRAM is used for cache; DRAM for main memory.
- 6. EEPROM is erased electrically.
- 7. DMA moves data without CPU involvement.
- 8. 2's complement = 1's complement + 1.
- 9. 8-bit 2's complement range is −128 to +127.
- 10. IEEE 754 single precision uses 32 bits.
- 11. Half adder: Sum = A XOR B.
- 12. 1 byte = 8 bits.
Practice questions
In the Von Neumann model, instructions and data are stored
- in separate memories
- only in registers
- only on the hard disk
- in the same memory
Answer
D. in the same memory
The stored-program concept uses one memory for both.
Which unit of the CPU performs arithmetic and logical operations?
- MAR
- ALU
- Cache
- Control unit
Answer
B. ALU
The Arithmetic and Logic Unit does the calculations.
The register that holds the address of the next instruction to be fetched is the
- Program Counter
- Instruction Register
- Accumulator
- MDR
Answer
A. Program Counter
The PC points to the next instruction.
The register that holds the result of ALU operations is commonly called the
- Stack pointer
- MAR
- Accumulator
- Program Counter
Answer
C. Accumulator
The accumulator keeps intermediate and final results.
The correct order of the basic instruction cycle is
- fetch, execute, decode
- decode, fetch, execute
- execute, fetch, decode
- fetch, decode, execute
Answer
D. fetch, decode, execute
The CPU fetches, decodes and then executes.
Which bus is one-directional (from the CPU to memory)?
- Address bus
- Data bus
- Both address and data bus
- None of the buses
Answer
A. Address bus
The address bus carries addresses from the CPU; the data bus is two-way.
Which memory is the fastest in the hierarchy?
- Cache
- Registers
- RAM
- Hard disk
Answer
B. Registers
Registers are the fastest and smallest.
Which type of RAM is used for cache memory?
- DRAM
- EPROM
- SRAM
- Flash ROM only
Answer
C. SRAM
SRAM is faster and costlier; DRAM is used for main memory.
Which memory needs periodic refreshing?
- EEPROM
- DRAM
- SRAM
- ROM
Answer
B. DRAM
DRAM stores bits in capacitors that leak charge.
Which ROM can be erased electrically?
- Mask ROM
- PROM
- EPROM
- EEPROM
Answer
D. EEPROM
EEPROM is electrically erasable; EPROM needs UV light.
Direct Memory Access (DMA) is used to
- convert binary to decimal
- transfer data between I/O device and memory without the CPU
- increase the clock speed
- refresh DRAM
Answer
B. transfer data between I/O device and memory without the CPU
A DMA controller moves blocks of data without CPU involvement.
How many bits make one byte?
- 4
- 16
- 8
- 2
Answer
C. 8
1 byte = 8 bits.
An address bus of 16 lines can address how many memory locations?
- 65,536
- 16,384
- 1,048,576
- 32,768
Answer
A. 65,536
2^16 = 65,536.
A 12-bit address bus can address how many locations?
- 1,024
- 8,192
- 2,048
- 4,096
Answer
D. 4,096
2^12 = 4,096 = 4 K.
The 2's complement of the 4-bit number 0101 is
- 0101
- 1111
- 1011
- 1010
Answer
C. 1011
Flip bits to 1010 and add 1 to get 1011.
The 8-bit 2's complement representation of −5 is
- 11111010
- 10000101
- 00000101
- 11111011
Answer
D. 11111011
5 = 00000101; flip to 11111010; add 1 gives 11111011.
The range of an 8-bit 2's complement number is
- −256 to +255
- −128 to +127
- −127 to +127
- 0 to 255
Answer
B. −128 to +127
Range is −2^7 to 2^7 − 1.
Binary addition 1011 + 0110 gives
- 10001
- 10101
- 01111
- 10011
Answer
A. 10001
11 + 6 = 17 = 10001.
Binary multiplication 101 × 11 gives
- 1101
- 10001
- 1111
- 1011
Answer
C. 1111
5 × 3 = 15 = 1111.
In 4-bit 2's complement, 7 − 5 is done by adding 0111 and 1011. The result after discarding the carry is
- 1100
- 0010
- 0110
- 1010
Answer
B. 0010
0111 + 1011 = 1 0010; discarding the carry gives 0010 = 2.
Overflow in signed addition occurs when
- the carry out is always 1
- the result is zero
- a positive and a negative number are added
- two numbers of the same sign give a result of the opposite sign
Answer
D. two numbers of the same sign give a result of the opposite sign
This is the standard overflow condition for signed numbers.
In 8-bit 2's complement arithmetic, adding 100 and 50 produces
- an overflow
- an underflow of 50
- a correct result 150
- a result of zero
Answer
A. an overflow
150 exceeds the maximum +127, so overflow occurs.
In IEEE 754 single precision, the number of bits used for the exponent is
- 23
- 52
- 11
- 8
Answer
D. 8
Single precision: 1 sign, 8 exponent, 23 fraction bits.
In IEEE 754 double precision, the exponent bias is
- 1024
- 255
- 1023
- 127
Answer
C. 1023
Double precision uses 11 exponent bits and bias 1023.
Sum output of a half adder is given by
- A XOR B
- A OR B
- A AND B
- A NAND B
Answer
A. A XOR B
Sum = A XOR B; Carry = A AND B.
A full adder has how many inputs?
- 3
- 2
- 4
- 1
Answer
A. 3
A, B and carry-in.
The architecture that uses a small set of simple, fixed-length instructions is
- CISC
- RISC
- VLIW only
- Harvard only
Answer
B. RISC
RISC = Reduced Instruction Set Computer.
In an instruction, the part that specifies the operation to be done is the
- address bus
- flag
- operand
- opcode
Answer
D. opcode
Opcode gives the operation; operand gives the data.
The addressing mode in which the operand is given in the instruction itself is
- direct
- immediate
- indirect
- register indirect
Answer
B. immediate
Immediate mode contains the data value.
A cache gives 90 hits in 100 accesses. Cache time is 10 ns and main memory time 100 ns. The average access time by the simple model is
- 55 ns
- 28 ns
- 19 ns
- 10 ns
Answer
C. 19 ns
0.9 × 10 + 0.1 × 100 = 19 ns.
A 2 GHz clock has a clock period of
- 5 ns
- 0.5 ns
- 2 ns
- 0.2 ns
Answer
B. 0.5 ns
Period = 1 / (2 × 10^9) s = 0.5 ns.
A memory of 64 K words with 16 bits per word has a capacity of
- 64 KB
- 256 KB
- 1 MB
- 128 KB
Answer
D. 128 KB
64 K × 2 bytes = 128 KB.
Subtracting 10 from 25 in 8 bits by 2's complement gives
- 00001111
- 11110101
- 00010101
- 00001010
Answer
A. 00001111
25 + (−10) = 15 after discarding the carry.
Which is true of the sign bit in 2's complement numbers?
- 1 in the MSB means positive
- There is no sign bit
- 1 in the MSB means negative
- The LSB is the sign bit
Answer
C. 1 in the MSB means negative
MSB 1 shows a negative number.
Consider these statements. 1. The data bus is bidirectional. 2. The address bus is bidirectional. Which is/are correct?
- 1 only
- 2 only
- Both 1 and 2
- Neither 1 nor 2
Answer
A. 1 only
The address bus is one-way, so only 1 is correct.
Consider these statements about memory. 1. SRAM is faster than DRAM. 2. DRAM needs refreshing. Which is/are correct?
- 1 only
- 2 only
- Both 1 and 2
- Neither 1 nor 2
Answer
C. Both 1 and 2
Both are correct.
Consider these statements about number representation. 1. 2's complement has only one representation of zero. 2. Sign-magnitude has two representations of zero. Which is/are correct?
- 1 only
- 2 only
- Both 1 and 2
- Neither 1 nor 2
Answer
C. Both 1 and 2
Both statements are true.
Consider these statements about the instruction cycle. 1. The PC is increased after the fetch. 2. The decode step is done by the control unit. Which is/are correct?
- 1 only
- 2 only
- Both 1 and 2
- Neither 1 nor 2
Answer
C. Both 1 and 2
Both are correct.
Consider these statements about I/O. 1. In DMA the CPU transfers each byte itself. 2. Interrupt-driven I/O avoids the CPU waiting for the device. Which is/are correct?
- 1 only
- 2 only
- Both 1 and 2
- Neither 1 nor 2
Answer
B. 2 only
In DMA the controller moves the data; only 2 is correct.
Match the memory with its feature. P. Cache Q. EPROM R. DRAM 1. UV erasable 2. Needs refresh 3. Between CPU and RAM
- P-3, Q-2, R-1
- P-2, Q-1, R-3
- P-1, Q-3, R-2
- P-3, Q-1, R-2
Answer
D. P-3, Q-1, R-2
Cache sits between CPU and RAM, EPROM is UV erasable, DRAM is refreshed.
Match the register with its role. P. PC Q. MAR R. IR 1. Holds the address to be accessed 2. Holds the current instruction 3. Holds the next instruction address
- P-3, Q-1, R-2
- P-1, Q-3, R-2
- P-3, Q-2, R-1
- P-2, Q-1, R-3
Answer
A. P-3, Q-1, R-2
PC holds the next address, MAR the access address, IR the current instruction.
Match the format with its size. P. Single precision Q. Double precision R. Byte 1. 8 bits 2. 32 bits 3. 64 bits
- P-3, Q-2, R-1
- P-2, Q-3, R-1
- P-2, Q-1, R-3
- P-1, Q-2, R-3
Answer
B. P-2, Q-3, R-1
Single = 32 bits, double = 64 bits, byte = 8 bits.
Consider these statements about cache memory. 1. It is placed between the CPU and main memory. 2. It works well because of locality of reference. Which is/are correct?
- 1 only
- 2 only
- Both 1 and 2
- Neither 1 nor 2
Answer
C. Both 1 and 2
Both statements are correct.
Consider these statements about adders. 1. A half adder adds two bits. 2. A full adder can be built from two half adders and an OR gate. Which is/are correct?
- 1 only
- 2 only
- Both 1 and 2
- Neither 1 nor 2
Answer
C. Both 1 and 2
Both are correct.
The 1's complement of the binary number 10110 is
- 10111
- 01010
- 01110
- 01001
Answer
D. 01001
Flip every bit of 10110 to get 01001.