Assembly Language, Past Papers, UOS Main Campus

Computer Organization & Assembly Language Past Paper 2026 – BS IT 4th Semester UOS (CMPC-5209)

ProgramBS IT
Semester4th
Year2026
Course codeCMPC-5209
AnswersSolved ✓

University of Sargodha AD/BS IT 4th semester Computer Organization & Assembly Language (CMPC-5209) paper, 2026 exam (40 marks, 2:30 hours). Solved answers are given below for all 8 short questions and all five long questions: 80×86 addressing modes, program layout and segments, argument passing between modules, macros vs structures, and hardware/software interrupts with the interrupt vector table.

Solved answers

Q1 – Short answers (8 × 2)

i. Address, data and control bus: The address bus (one-way, CPU → memory/I-O) carries the address of the memory location or port to be accessed; its width fixes the addressable memory (20 lines in 8086 = 1 MB). The data bus (two-way) carries the actual data/instructions (16 bits in 8086). The control bus carries control and timing signals such as RD, WR, M/IO, clock, interrupt and reset.

ii. General-purpose vs flags register: General-purpose registers (AX, BX, CX, DX and their 8-bit halves, plus SI, DI, BP, SP) hold operands, addresses and results during processing. The flags register is a special 16-bit register whose individual bits show the status of the last result (CF, ZF, SF, OF, PF, AF) or control the CPU (IF, DF, TF); it is tested by conditional jumps, not used for general data.

iii. Direct vs register indirect addressing: In direct addressing the memory address (offset) is written in the instruction itself: MOV AX, [1234h] or MOV AX, var1. In register indirect addressing the offset is held in a register (BX, SI, DI or BP): MOV AX, [BX], so the same instruction can access different locations by changing the register (useful for arrays).

iv. Data definition directives: DB (define byte, 1 byte) and DW (define word, 2 bytes); others are DD (4 bytes), DQ (8 bytes) and DT (10 bytes). Example: num DB 25, total DW 1000h.

v. Signed vs unsigned arithmetic: Unsigned instructions treat all bits as magnitude: MUL, DIV, and comparisons with JA/JB/JAE/JBE; overflow is shown by CF. Signed instructions use two’s complement where the MSB is the sign: IMUL, IDIV, CBW/CWD (sign extension) and JG/JL/JGE/JLE; overflow is shown by OF. ADD/SUB are the same for both – only the flags are interpreted differently.

vi. Combining assembly and C: C gives fast development, portability and readability, while assembly is used for the few parts that need maximum speed, small size or direct hardware access (device drivers, interrupt handlers, boot code, special CPU instructions). They are combined by inline assembly (asm { }) or by linking separate C and assembly modules.

vii. String instructions: Instructions that process a block (string) of bytes or words in memory using SI (source, DS:SI) and DI (destination, ES:DI), which automatically increment or decrement according to DF; they can be repeated with REP/REPE/REPNE using CX as counter. Examples: MOVSB (copy), CMPSB (compare), SCASB (scan), LODSB, STOSB.

viii. TSR program: A Terminate and Stay Resident program ends but keeps its code in memory (DOS INT 21h function 31h, or INT 27h). Before exiting it changes an interrupt vector (e.g. keyboard INT 09h or timer INT 1Ch) to point to its own routine, so the routine runs whenever that interrupt occurs – e.g. pop-up utilities, clocks, keyboard hooks.

Q2 – Addressing modes of 80×86 with examples

An addressing mode is the way an instruction specifies the location of its operand. The 8086 computes a memory address as Physical address = Segment × 10h + Effective address (offset).

ModeHow the operand is foundExample
RegisterOperand is in a registerMOV AX, BX
ImmediateOperand is a constant in the instructionMOV CX, 5
DirectOffset given directly in the instructionMOV AL, [2000h] / MOV AX, total
Register indirectOffset in BX, SI, DI or BPMOV AX, [SI]
BasedBase register (BX or BP) + displacementMOV AX, [BX+4]
IndexedIndex register (SI or DI) + displacementMOV AL, arr[SI]
Based-indexedBase + indexMOV AX, [BX+SI]
Based-indexed with displacementBase + index + displacementMOV AX, [BX+DI+6]
StringImplicit DS:SI and ES:DIMOVSB
I/O port (direct / indirect)Port number in instruction or in DXIN AL, 60h / OUT DX, AL
Relative (for jumps)Target = IP + signed displacementJNZ next

Example – sum of an array using indexed addressing:

.DATA
arr  DB 4, 7, 2, 9, 3
sum  DB ?
.CODE
     MOV  SI, 0          ; index
     MOV  CX, 5          ; count
     MOV  AL, 0          ; register + immediate modes
L1:  ADD  AL, arr[SI]    ; indexed mode
     INC  SI
     LOOP L1             ; relative mode
     MOV  sum, AL        ; direct mode   (sum = 25)

Q3 – Layout of an 80×86 assembly program

A program is divided into segments: a stack segment (return addresses, saved registers, parameters), a data segment (variables and constants) and a code segment (instructions); an extra segment (ES) may be used for strings. Using simplified directives (MASM/TASM):

.MODEL SMALL             ; memory model: one code + one data segment
.STACK 100h              ; 256-byte stack segment

.DATA                    ; data segment – declarations
msg     DB 'Hello UOS$'  ; string ($ ends it for INT 21h/09h)
num1    DB 10            ; byte
total   DW 0             ; word
arr     DW 5 DUP(0)      ; array of 5 words set to 0
LIMIT   EQU 100          ; constant (no memory used)

.CODE                    ; code segment
MAIN PROC
        MOV AX, @data    ; initialise DS
        MOV DS, AX

        MOV AH, 09h      ; display string
        LEA DX, msg
        INT 21h

        MOV AH, 4Ch      ; return to DOS
        INT 21h
MAIN ENDP
END MAIN                 ; end of program, entry point

With full segment definitions the same layout is written with SEGMENT/ENDS and ASSUME:

STACK1 SEGMENT STACK
        DW 128 DUP(?)
STACK1 ENDS
DATA1  SEGMENT
msg    DB 'Hello UOS$'
DATA1  ENDS
CODE1  SEGMENT
       ASSUME CS:CODE1, DS:DATA1, SS:STACK1
START: MOV AX, DATA1
       MOV DS, AX
       ; ... program ...
       MOV AH, 4Ch
       INT 21h
CODE1  ENDS
       END START

Data declarations: name directive initial-value – DB, DW, DD, DQ, DT; ? for uninitialised; DUP for arrays; strings in quotes with DB; EQU or = for named constants. Memory models: TINY, SMALL, MEDIUM, COMPACT, LARGE, HUGE.

Q4 – Argument passing between separate assembly modules and libraries

Large programs are split into modules that are assembled separately and joined by the linker. A module makes a procedure or variable visible with PUBLIC, and another module uses it with EXTRN name:type (e.g. EXTRN SUM:NEAR). Arguments are passed in these ways:

  • Through registers: the caller loads values (e.g. AX, BX, CX) before CALL and the result returns in AX. Fastest, but limited by the number of registers; DOS/BIOS services work this way.
  • Through global (shared) memory variables: variables declared PUBLIC in one module and EXTRN in the others. Simple but makes modules dependent on each other and is not re-entrant.
  • Through the stack: the caller PUSHes arguments and then CALLs; the procedure sets BP = SP and reads them at [BP+4], [BP+6]… (near call). Works for any number of arguments, supports recursion, and is the method used by high-level languages.
  • By value or by reference: a copy of the value is passed, or its address (offset) is passed (e.g. LEA + PUSH) so the procedure can change the original variable or array.
  • Parameter block: arguments are placed in a block of memory and only its address is passed in a register.
; ---- module 1 (main.asm) ----
EXTRN ADDTWO:NEAR
        PUSH a          ; 1st argument
        PUSH b          ; 2nd argument
        CALL ADDTWO     ; result in AX
; ---- module 2 (add.asm) ----
PUBLIC ADDTWO
ADDTWO  PROC NEAR
        PUSH BP
        MOV  BP, SP
        MOV  AX, [BP+6] ; a
        ADD  AX, [BP+4] ; b
        POP  BP
        RET  4          ; callee removes 2 arguments (Pascal/stdcall)
ADDTWO  ENDP

Calling conventions with libraries/C: in the C convention (cdecl) arguments are pushed right-to-left, the caller removes them (ADD SP, n), the result returns in AX (DX:AX for 32-bit), and names usually get a leading underscore (_sum). In the Pascal/stdcall convention the callee removes them with RET n. The procedure must preserve BP, SI, DI, DS and SS. Routines placed in object libraries (.LIB) are linked the same way.

Q5 – Macros vs structures in x86 assembly

Macro: a named block of instructions defined once and expanded (copied with parameters substituted) by the assembler wherever its name is used.

PRINT  MACRO msg           ; definition
       MOV AH, 09h
       LEA DX, msg
       INT 21h
ENDM
       PRINT greet         ; invocation – expanded at assembly time

Structure: a template that groups related data fields of different sizes under one name (like a C struct). It reserves no memory until a variable of that type is declared; fields are accessed with the dot operator, which the assembler converts to fixed offsets.

STUDENT STRUC              ; definition (template)
  roll   DW ?
  marks  DB ?
  grade  DB 'F'
STUDENT ENDS

s1  STUDENT <101, 78, 'A'> ; declaration: 4 bytes reserved
    MOV AL, s1.marks       ; access = [s1 + 2]
    MOV BX, OFFSET s1
    MOV AL, [BX].grade     ; access through a pointer = [BX + 3]
PointMacroStructure
PurposeReuse a group of instructions (code)Organise related data (record layout)
Syntaxname MACRO params … ENDMname STRUC … ENDS, then var name <values>
Execution mechanismExpanded inline at assembly time; no CALL/RETNothing executes; field names become offsets used in addressing
MemoryEvery use adds a copy of the code (larger program)Memory used only by declared variables
ParametersTakes arguments, LOCAL labelsHas fields with default values
SpeedFast – no call overheadAccess as fast as any memory operand

(A macro also differs from a procedure: a procedure exists once in memory and is reached by CALL/RET, saving space but adding overhead.)

Q6 – Hardware and software interrupts and the IVT

An interrupt is a signal that makes the CPU suspend the current program, run an interrupt service routine (ISR), and then return. On an interrupt the 8086 pushes FLAGS, CS and IP, clears IF and TF, loads the new CS:IP from the IVT, and the ISR ends with IRET, which pops IP, CS and FLAGS.

  • Hardware interrupts come from external devices through pins. INTR is maskable (enabled/disabled by STI/CLI via IF) and is normally connected through the 8259 PIC – e.g. timer (INT 08h), keyboard (INT 09h). NMI is non-maskable (type 2) for critical events like power failure or memory parity error.
  • Software interrupts are caused by the INT n instruction in a program to request services – BIOS (INT 10h video, INT 16h keyboard, INT 13h disk) and DOS (INT 21h, e.g. AH = 09h display string, AH = 4Ch exit) – plus INTO (overflow) and INT 3 (breakpoint).
  • Exceptions (internal) are generated by the CPU itself: type 0 divide error, type 1 single-step (TF), type 4 overflow with INTO.

Interrupt Vector Table (IVT): the first 1 KB of memory, addresses 00000h–003FFh, holds 256 vectors (types 0–255). Each vector is 4 bytes – the ISR’s IP (offset, low word) followed by its CS (segment) – so the vector of interrupt type n is at physical address 4 × n. Example: INT 21h → 4 × 21h = 84h, so IP is at 00084h and CS at 00086h. Types 0–4 are reserved for the CPU (divide error, single step, NMI, breakpoint, overflow), others for BIOS, DOS and users. Programs can read/change vectors with INT 21h functions 35h and 25h (as TSRs do).

Address   Contents
00000h    IP of INT 0   (divide error)
00002h    CS of INT 0
00004h    IP / CS of INT 1  (single step)
00008h    IP / CS of INT 2  (NMI)
...
00084h    IP / CS of INT 21h (DOS services)
...
003FCh    IP / CS of INT 0FFh
Save this paper for offline studyDownload the question paper, or save the paper together with all solved answers as a PDF.
↓ Download Paper (JPG)

About Saif R

An educator and technology enthusiast passionate about empowering students through quality education and digital learning. Dedicated to making academic resources and opportunities accessible to everyone.