4 Assembly Language Programming

Microprocessor · Unit 4 · 10 hrs

Assembly Language Programming

Exam-focused notes for Assembly Language Programming (Microprocessor, CSC167): what the TU syllabus asks and how it has actually been tested, with 28 solved past questions from this unit.

Assembly Language Programming in short

This chapter turns the 8085 (and, for the DOS-style example programs, the 8086) instruction set into working assembly language: how an instruction is written and assembled, the different ways an instruction can address its data, and the standard sequence, branching and loop patterns used to build a working program.

Assembly Language Programming: notes

Assembly instruction format

An 8085 instruction occupies one, two or three bytes. The first byte is always the opcode; a two-byte instruction adds one byte of immediate data or a port address, and a three-byte instruction adds a full 16-bit address or 16-bit immediate data as its second and third bytes. For example, MOV A, B (copy the contents of register B into register A) is a one-byte instruction with opcode 78H; MVI B, 45H (load the 8-bit constant 45H into register B) is a two-byte instruction with opcode 06H followed by the data byte; and JMP 6200H (jump to address 6200H) is a three-byte instruction with opcode C3H followed by the low-order and then the high-order byte of the address.

Instruction Types

The 8085 instruction set falls into five functional groups.

GroupPurposeExample mnemonics
Data transferMove a byte between registers, memory or immediate data, without changing the sourceMOV, MVI, LDA, STA, LXI, LDAX, STAX
ArithmeticAdd, subtract, increment, decrementADD, ADC, SUB, SBB, INR, DCR, INX, DCX, DAD
LogicalBitwise AND/OR/XOR, compare, rotate, complementANA, ORA, XRA, CMP, RLC, RRC, RAL, RAR, CMA, CMC, STC
BranchingAlter the normal sequential flow, conditionally or unconditionallyJMP, JZ, JNZ, JC, JNC, CALL, RET
Machine control / stackControl processor state or the stackNOP, HLT, DI, EI, RIM, SIM, PUSH, POP

Mnemonics

A mnemonic is the short, human-readable name assigned to an operation so that a programmer writes MOV instead of the raw binary pattern the processor actually executes. Translating each mnemonic, together with its operands, into the correct opcode byte is the assembler's job.

What this unit covers

  • Assembly instruction format
  • Instruction Types
  • Mnemonics
  • Operands
  • Macro assemblers
  • Linking
  • Assembler directives
  • Addressing Modes
  • Simple sequence programs
  • Flags
  • Branch
  • Jumps
  • While-Do
  • Repeat-Until
  • If-Then-Else and Multiple If-then Programs
  • Debugging

Simple sequence programs

2081 · 10 marks

Explain LHLD and SHLD instruction. Ten 8-bit data are stored at memory location starting from 6000H. Write an assembly program for 8085 microprocessor to calculate the sum of this data array and store the sum and carry starting from 9500H.[10]

Show solved answer

LHLD & SHLD Instructions + Sum of Data Array Program

Given

  • Number of data values: 10 (0AH)
  • Data type: 8-bit each
  • Data starting address: 6000H (so 6000H to 6009H)
  • Sum storage address: 9500H
  • Carry storage address: implied 9501H (next location)

All required data is present.


Solution

Part 1: LHLD and SHLD Instructions

LHLD (Load H-L pair Direct)

A 3-byte instruction that loads the contents of two consecutive memory locations directly into the HL register pair.

Syntax: LHLD address

Operation:

  • $L \leftarrow M[address]$
  • $H \leftarrow M[address+1]$

Example: LHLD 2200H - if 2200H = 45H and 2201H = 32H, then after execution $L = 45H$, $H = 32H$.

Size: 3 bytes, Machine cycles: 5, T-states: 16


SHLD (Store H-L pair Direct)

A 3-byte instruction that stores the contents of the HL register pair into two consecutive memory locations.

Syntax: SHLD address

Operation:

  • $M[address] \leftarrow L$
  • $M[address+1] \leftarrow H$

Example: SHLD 2302H - if $H = 32H$, $L = 45H$, then 2302H = 45H, 2303H = 32H.

Size: 3 bytes, Machine cycles: 5, T-states: 16


Part 2: Assembly Language Program

Algorithm

  1. Initialize carry register $C = 00H$
  2. Initialize counter $B = 0AH$ (10 items)
  3. Point HL to 6000H
  4. Clear accumulator ($A = 00H$)
  5. Add memory content to A; if carry occurs, increment C
  6. Advance pointer, decrement counter, repeat until zero
  7. Store sum at 9500H, carry at 9501H

Program

; Sum of 10 eight-bit data stored from 6000H
; Sum -> 9500H, Carry -> 9501H

        MVI C, 00H      ; carry counter = 0
        MVI B, 0AH      ; counter = 10
        LXI H, 6000H    ; HL points to first data
        SUB A           ; A = 0 (clear accumulator, clears CY)

BACK:   ADD M           ; A = A + [HL]
        JNC SKIP        ; if no carry, skip
        INR C           ; else increment carry register

SKIP:   INX H           ; next memory location
        DCR B           ; decrement counter
        JNZ BACK        ; repeat until counter = 0

        STA 9500H       ; store sum
        MOV A, C        ; move carry to A
        STA 9501H       ; store carry

        HLT             ; halt

Explanation

InstructionOperation
MVI C, 00HCarry counter initialized to zero
MVI B, 0AHLoop counter = 10
LXI H, 6000HHL points to first data location
SUB AClears A to 00H
ADD MAdds memory content to accumulator
JNC SKIPSkip if no carry produced
INR CIncrement carry register on overflow
INX HAdvance pointer
DCR BDecrement counter
JNZ BACKLoop until all 10 added
STA 9500HStore final sum
MOV A, CMove carry count to A
STA 9501HStore carry byte
HLTStop

Key Points

  • Register C accumulates the number of carries, forming the high byte of the 16-bit result. Since each byte is at most FFH, the maximum sum of 10 bytes is $10 \times 255 = 2550 = 09F6H$, so C never exceeds 09H: a single carry register suffices.
  • SUB A clears the accumulator and also resets the carry flag before the loop.

Result: Low byte of sum stored at 9500H, carry (high byte) stored at 9501H.

Note: the problem does not explicitly state 9501H for the carry, but "starting from 9500H" naturally implies the next byte (9501H), so that assumption is reasonable and standard.

Open this answer on its own page →

2081 · 5 marks

Write an ALP to convert the string 'computer science' to upper case using 16 bit microprocessor. [5]

Show solved answer

ALP to Convert String 'computer science' to Upper Case (16-bit Microprocessor / 8086)

Concept

In ASCII, lowercase letters range from 61H ('a') to 7AH ('z') and uppercase letters range from 41H ('A') to 5AH ('Z'). To convert lowercase to uppercase, we subtract 20H from the ASCII value of each lowercase character.

Spaces and other non-alphabetic characters are left unchanged.


Assembly Language Program

.MODEL SMALL
.STACK 100H

.DATA
    STRING DB 'computer science', '$'   ; Define the string with $ terminator
    LEN    DW 16                        ; Length of the string (16 characters)

.CODE
MAIN PROC
    MOV AX, @DATA          ; Load address of DATA segment into AX
    MOV DS, AX             ; Initialize Data Segment register

    MOV SI, OFFSET STRING  ; SI points to the start of the string
    MOV CX, LEN            ; CX = loop counter = length of string

BACK:
    MOV AL, [SI]           ; Load current character into AL

    CMP AL, 'a'            ; Compare AL with 'a' (61H)
    JB  SKIP               ; If AL < 'a', not a lowercase letter, skip

    CMP AL, 'z'            ; Compare AL with 'z' (7AH)
    JA  SKIP               ; If AL > 'z', not a lowercase letter, skip

    SUB AL, 20H            ; Convert lowercase to uppercase by subtracting 20H
    MOV [SI], AL           ; Store the converted character back into memory

SKIP:
    INC SI                 ; Move SI to point to next character
    LOOP BACK              ; Decrement CX and repeat if CX != 0

    ; Display the converted string
    MOV DX, OFFSET STRING  ; Load address of converted string into DX
    MOV AH, 09H            ; DOS function 09H: display string
    INT 21H                ; Call DOS interrupt

    MOV AX, 4C00H          ; DOS function 4CH: terminate program
    INT 21H

MAIN ENDP
END MAIN

Step-by-Step Explanation

StepInstructionPurpose
1MOV AX, @DATA / MOV DS, AXInitialize the Data Segment
2MOV SI, OFFSET STRINGSI points to first character of string
3MOV CX, LENSet loop counter to string length (16)
4MOV AL, [SI]Load each character one by one
5CMP AL, 'a' and CMP AL, 'z'Check if character is lowercase
6SUB AL, 20HConvert to uppercase (e.g., 'c' = 63H - 20H = 43H = 'C')
7MOV [SI], ALWrite converted character back
8INC SI / LOOP BACKAdvance to next character and repeat
9INT 21H (AH=09H)Display the final uppercase string

Example Conversion

CharacterASCII (Hex)After SUB 20HResult
'c'63H43H'C'
'o'6FH4FH'O'
' ' (space)20HSkipped' '
's'73H53H'S'

Output: COMPUTER SCIENCE

Open this answer on its own page →

2080 · 10 marks

Explain the working of LHLD and DAA instruction of 8085. An array containing 5 elements is stored from memory location 4000h to 4004h; write an assembly language program for 8085 microprocessor to find largest element of array and store in memory location 4005h.[10]

--- Syntax: LHLD address Size: 3 bytes (1 opcode + 2 address bytes) Operation: - LHLD loads the contents of two consecutive memory locations into the H-L register pair - The lower byte (from the specified address) is loaded into register L - The higher byte (from address+1) is loaded into registe...

Open this answer on its own page →

2080 · 5 marks

Write an assembly language program for 16 bit microprocessor to count and display number of occurrence of letter 'o' in string 'Microprocessor organization'. [5]

Count and display the number of times letter 'o' appears in the string 'Microprocessor organization'. --- --- Step Instruction Purpose ---------------------------- 1 MOV AX, @DATA / MOV DS, AX Initialize the Data Segment register 2 MOV SI, OFFSET STRING Point SI to the beginning of the string 3 M...

Open this answer on its own page →

2079 · 10 marks

Write an assembly language program to find the largest number of an array using 8 bit microprocessor. (Assume appropriate array data and address where minimum array size of 15 should be considered)[10]

Show solved answer

Assembly Language Program to Find the Largest Number in an Array (8085 Microprocessor)

Given Data (Extracted)

The question specifies no fixed numeric values, so standard exam assumptions are made:

ItemAssumed Value
Array length stored at2200H
Array data starts at2201H
Array size (minimum required)15 elements (0FH)
Result location2300H
Data typeUnsigned 8-bit numbers

Sample Array (15 elements)

AddressData
2200H0FH (count = 15)
2201H45H
2202H78H
2203H12H
2204H9AH
2205H33H
2206HFFH
2207H56H
2208H02H
2209H88H
220AH67H
220BH1CH
220CH99H
220DH44H
220EH7BH
220FH3EH

Algorithm

  1. Load count from 2200H into register C.
  2. Point HL to first data element (2201H).
  3. Move first element to A (assume it is the largest).
  4. Decrement C (first element already read).
  5. Increment HL to next element.
  6. Compare current element M with A.
  7. If M > A, update A ← M.
  8. Increment HL, decrement C.
  9. If C ≠ 0, repeat from step 6.
  10. Store A at 2300H; HALT.

8085 Assembly Program

;-----------------------------------------------
; Find Largest Number in an Array
; Length at 2200H, Data from 2201H, Result at 2300H
;-----------------------------------------------

        LDA  2200H      ; A <- array length (count)
        MOV  C, A       ; C <- count (loop counter)

        LXI  H, 2201H   ; HL -> start of array

        MOV  A, M       ; A <- first element (assume largest)
        DCR  C          ; one element already read
        INX  H          ; HL -> next element

LOOP:   MOV  B, M       ; B <- current element
        CMP  B          ; A - B ; if A < B, Carry = 1
        JNC  SKIP       ; if A >= B, keep A
        MOV  A, B       ; else A <- larger value B

SKIP:   INX  H          ; next element
        DCR  C          ; decrement counter
        JNZ  LOOP       ; repeat until C = 0

        STA  2300H      ; store largest number
        HLT             ; stop

Dry Run (with Sample Data)

ElementBA (largest)A < B?Action
1st (2201H)-45H-A = 45H
2202H78H45HYesA = 78H
2203H12H78HNoA = 78H
2204H9AH78HYesA = 9AH
2205H33H9AHNoA = 9AH
2206HFFH9AHYesA = FFH
2207H56HFFHNoA = FFH
2208H..220FH≤ FFHFFHNoA = FFH

Final Result at 2300H = FFH (255 decimal): the largest element.


Registers Used

RegisterPurpose
ACurrent largest value
BCurrent element for comparison
CLoop counter
HLMemory pointer
Open this answer on its own page →

2079 · 5 marks

Write an assembly language program for 8086 to read two strings and check whether they are same or not. [5]

This is a programming problem, not a numeric one. No numeric matrices, burst times, or reference strings are provided. - Task: Read two strings from the keyboard and check whether they are the same or not. - Processor: 8086 - Environment (implied): MS-DOS / emu8086 using DOS interrupt INT 21H. No...

Open this answer on its own page →

2078 · 10 marks

Explain LXI and CMP instruction. Write an assembly language program for 8-bit microprocessor to divide 8 bit data stored in memory location 8050 by 8 bit data stored in 8051 and store the quotient in 8052 and remainder in 8053.[10]

LXI (Load Register Pair Immediate) is a 3-byte instruction that loads 16-bit immediate data into a register pair (BC, DE, HL) or the Stack Pointer (SP). Syntax: LXI rp, 16-bit data Operation: - The low-order byte (byte 2 of the instruction) goes to the low register of the pair. - The high-order b...

Open this answer on its own page →

2078 · 5 marks

Write an assembly language program for 16 bit microprocessor to reverse the string 'This is Microprocessor' [5]

  • Target processor: 16-bit microprocessor (8086) - String to reverse: This is Microprocessor - Character count: Let me count precisely: - This = 4 - space = 1 - is = 2 - space = 1 - Microprocessor = 14 - Total = 4 + 1 + 2 + 1 + 14 = 22 characters - Number of swaps needed: $22 / 2 = 11$ No data mi...
Open this answer on its own page →

2076 · 10 marks

Write an assembly language program to find the greatest number in an array in using 8 bit microprocessor. (Assume appropriate array data and address where minimum array size of 20 should be considered.)[10]

Show solved answer

Assembly Language Program to Find the Greatest Number in an Array (8085 Microprocessor)


Problem Statement

Find the greatest (maximum) number in an array of 8-bit numbers using the 8085 (8-bit) microprocessor. The array has a minimum size of 20 elements.


Assumptions

ItemValue / Description
Array length20 (14H) stored at memory location 2200H
Array dataStarts from memory location 2201H onwards
Result storageMemory location 2300H
Data typeUnsigned 8-bit numbers

Sample Array Data (20 elements at 2201H onwards)

2200H --> 14H       ; count = 20
2201H --> 45H
2202H --> 78H
2203H --> 23H
2204H --> 99H       ; greatest
2205H --> 12H
...  (remaining 15 elements)
2214H --> 67H

Algorithm / Logic

Step 1: Load the count (length) of array into register C
Step 2: Load the first element of array into Accumulator (A)
        This is our initial "maximum" value
Step 3: Decrement counter C by 1 (since first element already loaded)
Step 4: Point HL register pair to the next element (2202H)
Step 5: LOOP:
           Load next element from memory into register B
           Compare A with B  (A - B)
           If A >= B, skip (A is still the maximum)
           If A < B, update A = B (new maximum found)
           Increment HL to point to next element
           Decrement counter C
           If C != 0, repeat LOOP
Step 6: Store the result (maximum value) into 2300H
Step 7: HLT

Assembly Language Program (8085)

        LDA  2200H      ; Load array length (20 = 14H) into Accumulator
        MOV  C, A       ; Move length/count into register C (counter)

        LXI  H, 2201H   ; Point HL to the start of array (first element)
        MOV  A, M       ; Load first element into Accumulator
                        ; Assume first element as the greatest initially

        INX  H          ; Increment HL to point to second element
        DCR  C          ; Decrement counter (one element already loaded)

LOOP:   MOV  B, M       ; Load next array element into register B
        CMP  B          ; Compare Accumulator (current max) with B
                        ; Internally performs A - B and sets flags
        JNC  SKIP       ; Jump to SKIP if A >= B (No Carry means A >= B)
                        ; i.e., current max is still greater or equal

        MOV  A, B       ; If A < B, update Accumulator with new maximum

SKIP:   INX  H          ; Increment HL to point to next memory location
        DCR  C          ; Decrement counter register C by 1
        JNZ  LOOP       ; If counter != 0, jump back to LOOP

        STA  2300H      ; Store the greatest number into memory location 2300H
        HLT             ; Stop the program

Step-by-Step Explanation of Each Instruction

InstructionOperationPurpose
LDA 2200HA <- [2200H]Load count (14H = 20) into A
MOV C, AC <- AUse C as loop counter
LXI H, 2201HHL <- 2201HPoint HL to first array element
MOV A, MA <- [HL]Load first element as initial max
INX HHL <- HL + 1Move pointer to second element
DCR CC <- C - 1Reduce count by 1 (first element done)
MOV B, MB <- [HL]Load current element into B
CMP BA - B (flags set)Compare current max with current element
JNC SKIPJump if No CarryIf A >= B, skip update
MOV A, BA <- BUpdate max if B is greater
INX HHL <- HL + 1Move to next element
DCR CC <- C - 1Decrement counter
JNZ LOOPJump if C != 0Repeat until all elements checked
STA 2300H[2300H] <- AStore the greatest number
HLTStopEnd of program

Dry Run / Trace (Partial Example)

Assume array: 45H, 78H, 23H, 99H, 12H ...

IterationA (current max)B (new element)CMP resultAction
Initial45H----A = 45H (first element)
145H78HA < B (carry set)A = 78H
278H23HA > B (no carry)A = 78H (no change)
378H99HA < B (carry set)A = 99H
499H12HA > B (no carry)A = 99H (no change)
...99H...A >= allA = 99H

Result stored at 2300H = 99H (Greatest number)


Key Notes

CMP instruction in 8085 subtracts the operand from Accumulator without storing the result, but sets the Carry Flag (CY) and Zero Flag (ZF) according to the result: if A = B, CY = 0 and ZF = 1; if A > B, CY = 0 and ZF = 0; if A < B, CY = 1 and ZF = 0.

JNC (Jump if No Carry) is used right after CMP to branch when A >= B, since the Carry flag is cleared only when no borrow was needed.

Using CMP followed by a conditional jump lets the program compare values without altering the Accumulator, which is essential here because the running maximum stored in A must be preserved across every loop iteration until it is actually replaced.

Open this answer on its own page →

2076 · 5 marks

Write an ALP for 8086 to read a string and print it in the reverse order. [5]

The program reads characters one by one from the keyboard and pushes each character onto the stack. After the Enter key (carriage return) is detected, the characters are popped from the stack (LIFO order) and printed, which produces the reverse order. --- --- Step Description ------------------- ...

Open this answer on its own page →

2075 · 10 marks

Write an assembly language program to find the smallest number in an array using 8 bit microprocessor, (assume appropriate array data and address where minimum array size of 15 should be considered.)[10]

Show solved answer

Assembly Language Program to Find the Smallest Number in an Array (8-bit Microprocessor - 8085)


Problem Understanding

  • We need to find the smallest (minimum) number in an array of 8-bit data.
  • Array size: minimum 15 elements
  • We assume:
    • Memory location 2200H stores the length of the array (count = 15 = 0FH)
    • Memory locations 2201H onwards store the array elements
    • Result (smallest number) is stored at memory location 2300H

Assumed Array Data

Memory AddressData (Hex)
2200H0FH (length = 15)
2201H45H
2202H12H
2203H78H
2204H03H
2205H56H
2206H89H
2207H21H
2208H0AH
2209H34H
220AH67H
220BH09H
220CH55H
220DH1FH
220EH72H
220FH2BH

Expected smallest value = 03H (at address 2204H)


Algorithm / Logic

Step 1: Load the count (length) of array from memory 2200H into register C
Step 2: Point HL register pair to the first element (2201H)
Step 3: Load the first element into Accumulator as the assumed minimum
Step 4: Decrement counter C by 1 (first element already loaded)
Step 5: Advance HL pointer to next element
Step 6: Compare current element (M) with Accumulator (current minimum)
        - If current element >= Accumulator, skip (no update)
        - If current element < Accumulator, update Accumulator with current element
Step 7: Decrement counter C, advance pointer
Step 8: Repeat Steps 6-7 until counter C = 0
Step 9: Store the result (Accumulator) at 2300H
Step 10: HLT

Assembly Language Program (8085 ALP)

; ============================================================
; Program  : Find Smallest Number in an Array
; Array    : Starts at 2201H, Length stored at 2200H
; Result   : Stored at 2300H
; Array Size: 15 elements (0FH)
; ============================================================

        LDA  2200H      ; Load the count (length = 0FH) into Accumulator
        MOV  C, A       ; Move count into register C (loop counter)

        LXI  H, 2201H   ; Point HL pair to the first element of array

        MOV  A, M       ; Load first element into Accumulator
                        ; Assume first element as the current minimum

        DCR  C          ; Decrement counter (first element already read)
        INX  H          ; Advance HL pointer to next element

LOOP:   MOV  B, M       ; Load next array element into register B

        CMP  B          ; Compare Accumulator (current min) with B
                        ; CMP performs A - B and sets flags
                        ; If A <= B, Carry flag = 0, so A is still smaller
                        ; If A > B,  Carry flag = 1, so B is the new minimum

        JC   UPDATE     ; Jump to UPDATE if Carry = 1 (i.e., A > B, B is smaller)
        JZ   SKIP       ; Jump to SKIP if Zero = 1  (i.e., A = B, no update needed)
        JMP  SKIP       ; Jump to SKIP if A < B (A is already smaller)

UPDATE: MOV  A, B       ; Update Accumulator with the new smaller value (B)

SKIP:   INX  H          ; Advance HL pointer to next memory location
        DCR  C          ; Decrement loop counter
        JNZ  LOOP       ; If counter not zero, repeat loop

        STA  2300H      ; Store the smallest number into memory location 2300H

        HLT             ; Stop the program

Step-by-Step Instruction Explanation

InstructionOperationPurpose
LDA 2200HA <- M[2200H]Load array length (15 = 0FH)
MOV C, AC <- ASet loop counter to 15
LXI H, 2201HHL <- 2201HPoint to first array element
MOV A, MA <- M[HL]Load first element as assumed minimum
DCR CC <- C - 1Reduce count (first element consumed)
INX HHL <- HL + 1Move to next element
MOV B, MB <- M[HL]Load current element into B
CMP BA - B (flags set)Compare current min with current element
JC UPDATEJump if Carry=1If A > B, update minimum
MOV A, BA <- BB is new minimum
INX HHL <- HL + 1Advance to next element
DCR CC <- C - 1Decrement counter
JNZ LOOPJump if C != 0Repeat until all elements checked
STA 2300HM[2300H] <- AStore final minimum
HLT--End program

Dry Run (Partial Trace)

IterationA (Current Min)B (New Element)CMP ResultAction
145H12HA > BA <- 12H (new minimum)
212H78HA < BNo change
312H03HA > BA <- 03H (new minimum)
403H56HA < BNo change
503H89HA < BNo change
603H21HA < BNo change
703H0AHA < BNo change
803H34HA < BNo change
903H67HA < BNo change
1003H09HA < BNo change
1103H55HA < BNo change
1203H1FHA < BNo change
1303H72HA < BNo change
1403H2BHA < BNo change

After the fourteenth comparison the counter in C reaches zero, the loop ends, and STA 2300H stores the accumulator.

Result: memory location 2300H holds 03H, the smallest number in the array, which matches the expected value identified with the assumed data.


Conclusion

The program treats the first element as the assumed minimum and then walks the array once with the HL pair, comparing each element against the accumulator and replacing it whenever a smaller value is found. Since every element is examined exactly once, the routine needs (n - 1) comparisons for n elements, which is 14 comparisons for the 15-element array assumed here, and it works unchanged for any array length placed in 2200H.

Open this answer on its own page →

2075 · 5 marks

Write an ALP for 8086 to read a string and display the string in uppercase. [5]

  • Read characters one by one using INT 21H, AH=01H - Convert lowercase letters (a-z) to uppercase by subtracting 20H (since ASCII difference between lowercase and uppercase is 32 = 20H) - Display each character using INT 21H, AH=02H - Stop reading when Enter key (0DH) is pressed Character ASCII (...
Open this answer on its own page →

2080.1 · 10 marks

Write an Assembly program for calculating the factorial of a number using 8085 microprocessor.[10]

The factorial of a number N is calculated as: N! = N × (N-1) × (N-2) × ... × 2 × 1 For example: 5! = 5 × 4 × 3 × 2 × 1 = 120 --- 1. Load the number N from memory 2. Initialize a result register to 1 (since 0! = 1 and 1! = 1) 3. Multiply result by N, then decrement N 4. Repeat until N becomes 1 5....

Open this answer on its own page →

2080.1 · 5 marks

Write an Assembly program to reverse the given string. [5]

The strategy uses the stack as a temporary storage structure (LIFO - Last In, First Out): 1. Read characters one by one from input and PUSH each onto the stack, counting them in CX. 2. When end of input is detected, POP characters one by one and display them. 3. Since the stack reverses the order...

Open this answer on its own page →

Addressing Modes

2081 · 5 marks

Explain different addressing modes in 8085 microprocessor. [5]

An addressing mode refers to the way in which the operand (data) of an instruction is specified. The 8085 microprocessor supports 5 types of addressing modes. --- - In this mode, the data (operand) is directly specified in the instruction itself. - The data immediately follows the opcode in memor...

Open this answer on its own page →

2080 · 5 marks

What is mean by addressing mode? Explain different addressing modes in 8085 microprocessor. [5]

An addressing mode refers to the way in which the operand (data) of an instruction is specified or accessed. In other words, it defines the method used by the CPU to identify the location of data to be operated upon. The 8085 microprocessor supports 5 types of addressing modes. --- - In this mode...

Open this answer on its own page →

2078 · 5 marks

What is mean by addressing mode? Explain all the addressing mode available in 8085 microprocessor. [5]

An addressing mode refers to the way in which the operand (data) of an instruction is specified or accessed. It defines the method used by the microprocessor to identify the location of the data to be operated upon. Different addressing modes provide flexibility in accessing data from registers, ...

Open this answer on its own page →

2075 · 5 marks

Explain the addressing modes of 8085 microprocessor with examples. [5]

An addressing mode refers to the way in which the operand (data) of an instruction is specified. The 8085 microprocessor has 5 types of addressing modes. --- In this mode, the source operand is the data itself (a constant value directly given in the instruction). - If data is 8-bit → instruction ...

Open this answer on its own page →

Flags

2081 · 5 marks

Write short notes on :a. Flags in 8085 MPU b. DMA [5]

Show solved answer

Short Notes: Flags in 8085 MPU and DMA


a. Flags in 8085 MPU

Flags are special flip-flop circuits within the Flag Register (also called the Program Status Word) of the 8085 microprocessor. They are set (1) or reset (0) automatically based on the result of arithmetic and logical operations performed by the ALU. They indicate the status of the accumulator and other registers after the completion of an operation.

The 8085 MPU uses 5 flags, arranged in an 8-bit flag register:

Bit PositionD7D6D5D4D3D2D1D0
FlagSZ--AC--P--CY

The Five Flags:

  1. Sign Flag (S)

    • Set to 1 if the result of an operation is negative (i.e., the MSB/D7 bit of the result is 1).
    • Reset to 0 if the result is positive.
  2. Zero Flag (Z)

    • Set to 1 if the result of an operation is zero.
    • Reset to 0 if the result is non-zero.
  3. Auxiliary Carry Flag (AC)

    • Set to 1 if there is a carry out from bit D3 to bit D4 (carry from the lower nibble to the upper nibble).
    • Primarily used in BCD (Binary Coded Decimal) arithmetic operations.
  4. Parity Flag (P)

    • Set to 1 if the result contains an even number of 1s (even parity).
    • Reset to 0 if the result contains an odd number of 1s (odd parity).
  5. Carry Flag (CY)

    • Set to 1 if an arithmetic operation generates a carry out from the MSB (D7) or requires a borrow.
    • Used in multi-byte addition and subtraction operations.

These flags are essential for conditional branching instructions (e.g., JZ, JNZ, JC, JNC) which allow the program to make decisions based on the result of previous operations.


b. DMA (Direct Memory Access)

DMA (Direct Memory Access) is a technique that allows I/O devices to transfer data directly to or from memory without the involvement of the CPU for each byte of data transferred.

Need for DMA:

  • Normally, data transfer between memory and I/O devices is managed by the CPU, which wastes CPU time.
  • For large and high-speed data transfers (e.g., disk drives, video, network), DMA provides a much faster and efficient method.

How DMA Works:

  1. The I/O device requests a DMA transfer by sending a signal to the DMA Controller (DMAC).
  2. The DMAC sends a HOLD request to the CPU.
  3. The CPU completes its current operation, then sends a HLDA (Hold Acknowledge) signal and releases the buses (address, data, and control buses).
  4. The DMAC takes control of the buses and transfers data directly between the I/O device and memory.
  5. After the transfer is complete, the DMAC releases the buses and the CPU resumes normal operation.

Key Components:

  • DMA Controller (DMAC): A dedicated chip (e.g., Intel 8257) that manages the transfer.
  • HOLD and HLDA pins of the 8085 are used for DMA handshaking.

Advantages of DMA:

  • Fast data transfer at memory speed.
  • CPU is free to perform other tasks (or is only briefly paused).
  • Efficient for bulk data transfers.

Disadvantage:

  • Requires additional hardware (DMAC chip), increasing system cost and complexity.

Summary Table:

FeatureFlagsDMA
PurposeIndicate ALU result statusFast memory-I/O data transfer
LocationInside 8085 Flag RegisterExternal DMAC chip
Number5 flags (S, Z, AC, P, CY)Uses HOLD/HLDA pins
UseConditional branchingBulk data transfer
Open this answer on its own page →

2080 · 5 marks

What is flag? Explain all the flags present in 8085 microprocessor. [5]

Show solved answer

Flags in 8085 Microprocessor

What is a Flag?

A flag is a single-bit flip-flop (1-bit register) that indicates the status of the accumulator or other registers after the completion of an arithmetic or logical operation. These flip-flops are set (1) or reset (0) according to the data condition of the result stored in the accumulator.

The flag register (also called the status register or F register) is an 8-bit register, but only 5 bits are used as flags in the 8085 microprocessor.


The 5 Flags of 8085 Microprocessor

The flag register layout is as follows:

Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
SZ--AC--P--CY

1. Sign Flag (S) -- Bit 7

  • Set to 1 if the MSB (bit 7) of the result is 1, indicating the result is negative.
  • Reset to 0 if the result is positive (MSB = 0).
  • Used in signed number arithmetic.

Example: If result = 10000001 (negative in 2's complement), S = 1.


2. Zero Flag (Z) -- Bit 6

  • Set to 1 if the result of the operation is zero.
  • Reset to 0 if the result is non-zero.

Example: If 05H - 05H = 00H, then Z = 1.


3. Auxiliary Carry Flag (AC) -- Bit 4

  • Set to 1 if there is a carry out from bit 3 to bit 4 (i.e., carry from the lower nibble to the upper nibble).
  • Primarily used in BCD (Binary Coded Decimal) arithmetic operations.

Example: If lower nibble addition produces a carry to bit 4, AC = 1.


4. Parity Flag (P) -- Bit 2

  • Set to 1 if the result contains an even number of 1s (even parity).
  • Reset to 0 if the result contains an odd number of 1s (odd parity).

Example: If result = 00000011 (two 1s -- even), then P = 1.


5. Carry Flag (CY) -- Bit 0

  • Set to 1 if there is a carry out from the MSB (bit 7) during addition, or a borrow during subtraction.
  • Reset to 0 if there is no carry or borrow.

Example: If FFH + 01H = 100H (carry out), then CY = 1.


Summary Table

FlagSymbolBit PositionSet When
SignS7Result is negative (MSB = 1)
ZeroZ6Result is zero
Auxiliary CarryAC4Carry from bit 3 to bit 4
ParityP2Result has even number of 1s
CarryCY0Carry out from MSB

These five flags together help the programmer make conditional decisions (using conditional jump instructions) based on the outcome of arithmetic and logical operations.

Open this answer on its own page →

2076 · 5 marks

What is flag? Explain the flags that are present in 8085 microprocessor. [5]

Show solved answer

Flag in 8085 Microprocessor

What is a Flag?

A flag is a single-bit flip-flop (1-bit register) that indicates the status or condition of the result stored in the accumulator after the completion of an arithmetic or logical operation. Flags are part of the Flag Register (also called the Program Status Word) inside the ALU. These flip-flops are set (1) or reset (0) according to the data condition of the result in the accumulator.


Flags in 8085 Microprocessor

The 8085 microprocessor has five flags arranged in an 8-bit flag register. The five flags are:

1. Sign Flag (S)

  • After an arithmetic or logical operation, if the Most Significant Bit (D7) of the result is 1, the Sign flag is set (S = 1), indicating the result is negative.
  • If D7 = 0, the flag is reset (S = 0), indicating the result is positive.
  • Example: If result = 10000001 (in 2's complement, a negative number), S = 1.

2. Zero Flag (Z)

  • If the result of an operation is zero (00H), the Zero flag is set (Z = 1).
  • If the result is non-zero, the flag is reset (Z = 0).
  • Example: If 05H - 05H = 00H, then Z = 1.

3. Auxiliary Carry Flag (AC)

  • Also called the Half Carry Flag.
  • It is set (AC = 1) when there is a carry out from bit D3 to bit D4 (i.e., carry from the lower nibble to the upper nibble) during an arithmetic operation.
  • It is primarily used in BCD (Binary Coded Decimal) arithmetic operations (DAA instruction).
  • Example: If 0FH + 01H = 10H, a carry is generated from bit 3 to bit 4, so AC = 1.

4. Parity Flag (P)

  • After an operation, if the result has an even number of 1s, the Parity flag is set (P = 1) -- indicating even parity.
  • If the result has an odd number of 1s, the flag is reset (P = 0) -- indicating odd parity.
  • Example: Result = 00000011 (two 1s, even parity), so P = 1.

5. Carry Flag (CY)

  • The Carry flag is set (CY = 1) when an arithmetic operation results in a carry out from the MSB (bit D7) during addition, or a borrow during subtraction.
  • If there is no carry or borrow, it is reset (CY = 0).
  • Example: FFH + 01H = 100H; the carry out of bit 7 sets CY = 1.

Summary Table

FlagSymbolSet (= 1) When
SignSResult is negative (D7 = 1)
ZeroZResult is zero
Auxiliary CarryACCarry from D3 to D4
ParityPResult has even number of 1s
CarryCYCarry out from D7 (MSB)

These five flags together help the programmer to make conditional decisions (using conditional jump instructions like JZ, JC, JP, etc.) based on the outcome of operations.

Open this answer on its own page →

Instruction Types

2079 · 5 marks

Explain different types of instruction group of 8085. [5]

An instruction is a binary pattern designed inside a microprocessor to perform a specific function. The entire group of instructions that a microprocessor supports is called the Instruction Set. The 8085 has 246 instructions, each represented by an 8-bit binary value called an Op-code. These inst...

Open this answer on its own page →

2078 · 5 marks

Differentiate between PUSH and POP instruction with example illustrating the use of these instruction. [5]

PUSH and POP are stack-related data transfer instructions in the 8085 microprocessor. They are used to store and retrieve data from the stack (a special region of memory that operates on the Last In First Out - LIFO principle). The Stack Pointer (SP) register keeps track of the top of the stack. ...

Open this answer on its own page →

2076 · 5 marks

Differentiate between PUSH and POP instruction with example illustrating the use of these instructions. [5]

PUSH is a data transfer instruction that copies the contents of a specified register pair onto the stack (a reserved area in memory). The Stack Pointer (SP) is decremented by 2 (since a register pair holds 16 bits = 2 bytes) before storing the data. Syntax: PUSH rp where rp is a register pair (BC...

Open this answer on its own page →

2076 · 5 marks

What is CALL operation? How does it differ with JUMP operation? [5]

The CALL instruction is used in assembly language (8085 microprocessor) to transfer program control to a subroutine (a separate block of code) located at a specified memory address. When a CALL instruction is executed, the following steps occur: 1. The current value of the Program Counter (PC) (i...

Open this answer on its own page →

2076 · 5 marks

What is instruction set? Explain various kinds of instructions of 8086 microprocessor. [5]

Show solved answer

Instruction Set and Types of Instructions in 8086 Microprocessor

Definition of Instruction Set

An instruction is a binary pattern designed inside a microprocessor to perform a specific function. The entire group of instructions that a microprocessor supports is called the Instruction Set. Each instruction is represented by a binary value called an Op-code (Operation Code).


Types of Instructions in 8086 Microprocessor

The instructions of the 8086 microprocessor are grouped into the following categories:


1. Data Transfer Instructions

These instructions transfer data between registers, memory, and I/O ports.

InstructionDescription
MOVMove data from source to destination
PUSHPush data onto the stack
POPPop data from the stack
INInput data from I/O port
OUTOutput data to I/O port
XCHGExchange contents of two operands

2. Arithmetic Instructions

These instructions perform arithmetic operations such as addition, subtraction, multiplication, and division.

InstructionDescription
ADDAdd source to destination
SUBSubtract source from destination
MULUnsigned multiplication
DIVUnsigned division
INCIncrement operand by 1
DECDecrement operand by 1

3. Logical Instructions

These instructions perform bitwise logical operations.

InstructionDescription
ANDBitwise AND of two operands
ORBitwise OR of two operands
XORBitwise XOR of two operands
NOTBitwise complement of operand
CMPCompare two operands

4. Branch / Control Transfer Instructions

These instructions alter the normal sequential flow of program execution.

InstructionDescription
JMPUnconditional jump to a particular address
JCJump if Carry Flag (CF) = 1
JE / JZJump if Equal / Zero Flag (ZF) = 1
JNCJump if CF = 0
JNE / JNZJump if Not Equal / ZF = 0
JSJump if Sign Flag (SF) = 1
CALLCall a subroutine/procedure
RETReturn from subroutine to calling program

5. Loop Instructions

These instructions repeat a block of instructions a specified number of times.

InstructionDescription
LOOPLoop until CX = 0
LOOPE / LOOPZLoop while ZF = 1 and CX != 0
LOOPNE / LOOPNZLoop while ZF = 0 and CX != 0

6. Rotate and Shift Instructions

These instructions shift or rotate the bits of an operand.

InstructionDescription
ROLRotate bits left (MSB to LSB and CF)
RORRotate bits right (LSB to MSB and CF)
RCLRotate bits left through Carry Flag
RCRRotate bits right through Carry Flag
SHL / SALShift bits left logically/arithmetically
SHR / SARShift bits right logically/arithmetically

7. Interrupt Instructions

These instructions handle interrupt operations.

InstructionDescription
INTSoftware interrupt generated by I/O operations
INTOInterrupt only if Overflow Flag (OF) = 1
IRETReturn from interrupt procedure to main program

Summary

The 8086 instruction set covers data movement, arithmetic, logic, branching, looping, bit manipulation, and interrupt handling, making it a complete and powerful instruction set for general-purpose computing.

Open this answer on its own page →

2075 · 5 marks

What is instruction set? Explain various kinds of instructions of 8085 microprocessor. [5]

Show solved answer

Instruction Set and Types of Instructions in 8085 Microprocessor

Definition of Instruction Set

An instruction is a binary pattern designed inside a microprocessor to perform a specific function. The entire group of instructions that a microprocessor supports is called the Instruction Set.

  • The 8085 microprocessor supports 246 instructions.
  • Each instruction is represented by an 8-bit binary value called the Op-code or Instruction Byte.

Types (Kinds) of Instructions in 8085 Microprocessor

The instructions of the 8085 microprocessor are classified into the following categories:


1. Data Transfer Instructions

These instructions move data between registers, memory, and I/O ports without modifying the data.

InstructionFunction
MOVMove data from one register to another
MVIMove immediate data to a register
LDALoad accumulator from memory
STAStore accumulator to memory
IN / OUTInput/Output data from/to I/O port

2. Arithmetic Instructions

These instructions perform arithmetic operations such as addition and subtraction.

InstructionFunction
ADDAdd register or memory to accumulator
ADIAdd immediate data to accumulator
SUBSubtract register or memory from accumulator
INRIncrement register by 1
DCRDecrement register by 1

3. Logical Instructions

These instructions perform logical (Boolean) operations on data.

InstructionFunction
ANAAND register with accumulator
ORAOR register with accumulator
XRAXOR register with accumulator
CMAComplement the accumulator
CMPCompare register with accumulator

4. Branch / Jump Instructions

These instructions alter the normal sequential flow of a program by jumping to a specific address, either conditionally or unconditionally.

InstructionFunction
JMPUnconditional jump to a particular address
JCJump if Carry Flag (CF) = 1
JNCJump if Carry Flag (CF) = 0
JZ / JEJump if Zero Flag (ZF) = 1
JNZJump if Zero Flag (ZF) = 0
CALLCall a subroutine/procedure
RETReturn from subroutine to calling program

5. Stack and Machine Control Instructions

These instructions control the stack operations and the overall machine state.

InstructionFunction
PUSHPush register pair onto the stack
POPPop data from stack to register pair
HLTHalt the processor
NOPNo operation (do nothing for one cycle)
EI / DIEnable / Disable interrupts

6. Rotate Instructions

These instructions rotate the bits of the accumulator left or right.

InstructionFunction
ROL / RLCRotate bits from MSB to LSB (left)
ROR / RRCRotate bits from LSB to MSB (right)
RCL / RALRotate left through Carry Flag
RCR / RARRotate right through Carry Flag

Summary Table

CategoryPurpose
Data TransferMove data between registers/memory/I/O
ArithmeticAdd, subtract, increment, decrement
LogicalAND, OR, XOR, compare, complement
Branch/JumpChange program flow conditionally or unconditionally
Stack/ControlManage stack and machine state
RotateShift/rotate bits in the accumulator

The 8085 instruction set provides a complete set of operations allowing the microprocessor to perform arithmetic, logical, data movement, and program control tasks efficiently.

Open this answer on its own page →

Jumps

2080.1 · 5 marks

Write short notes on: a. Jumps b. Accumulator [5]

--- A jump instruction in 8085 microprocessor assembly language is used to transfer program control (the program counter) to a specified memory address, either unconditionally or based on the status of certain flags (condition codes). 1. Unconditional Jump - JMP address - Always transfers control...

Open this answer on its own page →