Blog
Computer Organization & Assembly Language Past Paper 2014 – MSc IT 3rd Term UOS (IT-693)
University of Sargodha M.Sc. IT 3rd term Computer Organization & Assembly Language (IT-693) paper, 2014 exam, session 2012-14 (80 marks, 2:30 hours). The paper is retyped below, followed by solved answers for all 16 short questions and all subjective questions, including tested 8086 programs for nested loops and for printing the odd numbers from 1 to 10.
Solved answers
Q1 – Short answers (16 × 2)
i. Program Counter. A CPU register that holds the address of the next instruction to be fetched. It is increased after each fetch and changed by jumps, calls and interrupts (called IP on the 8086).
ii. Four main components. Processor (CPU – ALU and control unit), main memory, input/output modules (devices), and the system interconnection (buses) that connects them.
iii. Moore’s law. Gordon Moore (1965) observed that the number of transistors on a chip doubles about every 18–24 months. As a result computers become faster, smaller and cheaper over time.
iv. Steps in branch instruction execution. Fetch the instruction (PC → MAR, memory → IR, PC incremented) → decode → evaluate the condition from the flags (for a conditional branch) → if true, compute the target address (PC + displacement or absolute) and load it into the PC; otherwise keep the incremented PC → next fetch from the new PC.
v. Execution unit. In the 8086 the EU decodes and executes instructions. It contains the ALU, general registers (AX, BX, CX, DX), pointer/index registers (SP, BP, SI, DI), the flags register and the control circuitry. It takes instructions from the queue filled by the Bus Interface Unit.
vi. System bus and types. A bus is a shared communication path of wires that connects the CPU, memory and I/O modules. Types: data bus (carries data), address bus (carries the address of the memory/I/O location) and control bus (read, write, interrupt, clock signals). By use: system bus, local bus, expansion buses such as ISA, PCI, USB.
vii. PCI slot. A slot on the motherboard for the Peripheral Component Interconnect bus, a high-speed 32/64-bit expansion bus used to attach cards such as network, sound and graphics cards.
viii. Extra Segment register. ES is a 16-bit segment register that points to an additional data segment. It is used as the destination segment in string instructions (ES:DI in MOVS, STOS, CMPS, SCAS) and for accessing a second data area with a segment override, e.g. MOV AX, ES:[BX].
ix. Real time application. An application that must respond to events within a strict time limit, e.g. air-bag control, pacemakers, industrial robots, flight control. A late answer counts as a failure.
x. Interrupt-driven I/O. The CPU issues an I/O command and continues other work; when the device is ready it sends an interrupt and the CPU transfers the data in an ISR. No busy waiting, but every word still passes through the CPU.
xi. Instruction set. The complete collection of machine instructions a processor can execute (data transfer, arithmetic, logic, control/branch, I/O), together with their formats and addressing modes, e.g. the x86 instruction set.
xii. Nibble. A group of 4 bits (half a byte). One hexadecimal digit is one nibble, e.g. the byte 3Ah has the nibbles 3 and A.
xiii. Assembler vs debugger. An assembler translates assembly language source into machine code (object file), e.g. MASM, NASM. A debugger loads a program and lets the programmer run it step by step, set breakpoints and inspect registers and memory to find errors, e.g. DEBUG, CodeView, GDB.
xiv. High-level vs assembly language. A high-level language (C, Java) is machine independent, closer to English, one statement produces many machine instructions, and it is compiled or interpreted. Assembly language is machine specific, one instruction maps to one machine instruction, gives direct control of registers and hardware, and produces fast, small code but is harder to write.
xv. Procedures in assembly. A named block of code defined with name PROC … name ENDP, executed with CALL and returning with RET; the return address is kept on the stack. Procedures can be NEAR (same segment) or FAR (different segment).
xvi. Program with nested loops. See the program below – an outer loop of 3 rows and an inner loop printing 4 stars, using PUSH/POP to save CX.
mov cx, 3 ; outer loop: 3 rows
outer: push cx ; save outer counter
mov cx, 4 ; inner loop: 4 stars
inner: mov dl, '*'
mov ah, 2
int 21h
loop inner ; inner loop uses CX
mov dl, 0Dh
int 21h
mov dl, 0Ah
int 21h ; new line
pop cx ; restore outer counter
loop outer
mov ah, 4Ch
int 21hQ2 – Data movement, arithmetic unit and logical unit
Data movement (transfer) instructions copy data between registers, memory and I/O without changing it: MOV, XCHG, PUSH/POP, LEA, IN/OUT, string moves (MOVS, LODS, STOS). The CPU must compute the memory address, read or write memory and update registers; flags are not changed.
Arithmetic unit: the part of the ALU that performs ADD, ADC, SUB, SBB, INC, DEC, NEG, CMP, MUL/IMUL, DIV/IDIV on integers (two’s complement) using adders; multiplication by shift-and-add or Booth’s algorithm, division by restoring/non-restoring methods. It sets the flags CF, OF, ZF, SF, PF, AF. Floating-point arithmetic is done by a separate FPU.
Logical unit: performs bit-wise operations AND, OR, XOR, NOT, TEST and the shifts/rotates SHL, SHR, SAR, ROL, ROR, RCL, RCR. They are used for masking bits (AND AL, 0Fh), setting bits (OR), toggling (XOR), clearing a register (XOR AX, AX) and fast multiply/divide by 2.
The ALU takes operands from registers, performs the selected operation under control-unit signals and returns the result to a register or memory, updating the flags.
Q3 – Addressing modes
An addressing mode is the way an instruction specifies where its operand is. Examples for the 8086:
| Mode | Example | Operand is |
|---|---|---|
| Immediate | MOV AX, 25 | the constant 25 inside the instruction |
| Register | MOV AX, BX | in register BX |
| Direct | MOV AX, [1234h] | in memory at offset 1234h (DS segment) |
| Register indirect | MOV AX, [BX] | in memory at the address held in BX/SI/DI |
| Based | MOV AX, [BX+4] | at BX (or BP) + displacement – fields of a record |
| Indexed | MOV AX, [SI+10] | at SI/DI + displacement – array elements |
| Based-indexed | MOV AX, [BX+SI+2] | at BX + SI + displacement – 2-D arrays |
| Relative | JMP label | IP + displacement (jumps) |
| Implied | CLC, STC | operand implied by the opcode (carry flag) |
Immediate and register modes are fastest (no memory access); direct mode is simple but fixed; indirect, based and indexed modes let one instruction work on different memory locations, which is needed for arrays, pointers and loops.
Q4 – Odd numbers from 1 to 10 (8086 assembly)
.model small
.stack 100h
.code
main proc
mov ax, @data
mov ds, ax
mov bl, 1 ; first odd number
mov cx, 5 ; 1, 3, 5, 7, 9 -> 5 numbers
next: mov al, bl
xor ah, ah
mov dh, 10
div dh ; AL = tens digit, AH = units digit
mov bh, ah ; save units digit
cmp al, 0
je units ; all are one digit, so this always jumps
mov dl, al
add dl, '0'
mov ah, 2
int 21h ; print tens digit
units: mov dl, bh
add dl, '0'
mov ah, 2
int 21h ; print units digit
mov dl, ' '
int 21h ; print a space
add bl, 2 ; next odd number
loop next
mov ah, 4Ch
int 21h ; return to DOS
main endp
end mainOutput: 1 3 5 7 9.
The programs were assembled with NASM (same instructions) and run in an 8086 emulator: output “2 4 6 8 10”, “1 3 5 7 9” and three rows of ****.
Q5 – I/O module
An I/O module connects one or more peripheral devices to the system bus. It is needed because devices use different data formats, speeds and control methods from the CPU and memory.
- Functions: control and timing, processor communication (command decoding, data, status reporting, address recognition), device communication, data buffering, error detection.
- Communication with the processor: the CPU checks the device status through the module’s status register; the module returns ready/busy/error; the CPU sends a command (read/write) and data through the data register, using the address, data and control lines of the bus.
- Communication with the device: through control signals (e.g. read/seek), status signals (ready) and the data path, with a buffer to match speeds.
- Techniques: programmed I/O (CPU polls the status), interrupt-driven I/O (module interrupts when ready), and DMA (module transfers blocks directly to memory).
Q6 – Variable-length instruction format
Advantages: instructions use only as many bytes as they need, so programs are smaller and use memory and cache better; it is easy to provide many opcodes, many addressing modes and large immediate values/addresses; new instructions can be added later (as in x86).
Disadvantages: decoding is more complex and slower because the CPU must first find the length of each instruction; fetching may cross word or cache-line boundaries; pipelining and parallel decoding of several instructions are harder; the control unit needs more hardware. Fixed-length formats (RISC, e.g. 32-bit MIPS/ARM) are easier to fetch, decode and pipeline but waste space.
Q7 – Register organization
Intel 8086 registers (all 16-bit):
- General purpose: AX (accumulator – arithmetic, I/O, MUL/DIV), BX (base – addressing memory), CX (count – LOOP, shifts, string repeat), DX (data – I/O port, high word of MUL/DIV). Each can be used as two 8-bit halves: AH/AL, BH/BL, CH/CL, DH/DL.
- Pointer and index: SP (stack pointer), BP (base pointer – stack frames), SI (source index), DI (destination index) – used for string and array operations.
- Segment registers: CS (code), DS (data), SS (stack), ES (extra). Physical address = segment × 16 + offset (20-bit address, 1 MB).
- Instruction pointer: IP – offset of the next instruction in CS.
- Flags register: status flags CF, PF, AF, ZF, SF, OF and control flags TF, IF, DF.
Registers are visible to the programmer (user-visible) or used by the CPU internally (control and status registers such as MAR, MBR, IR, PC/IP and the PSW). Keeping data in registers avoids slow memory accesses.
