Q1Microprocessor and Interfaces
Question
10 marks
(a) Explain the 8086 instruction set categories. (b) Write assembly language programs for: (i) Sorting an array (ii) Finding the largest element in an array.
Answer
8086 Instruction Set Categories
The 8086 instruction set is categorized as follows:
- Data Transfer: Moves data between registers and memory (e.g., MOV, PUSH, POP, XCHG, IN, OUT).
- Arithmetic: Performs addition, subtraction, multiplication, and division (e.g., ADD, SUB, MUL, DIV, INC, DEC).
- Logical: Bitwise AND, OR, XOR, NOT, Shift, and Rotate (e.g., AND, OR, XOR, SHL, ROR).
- String Manipulation: Operations on blocks of memory bytes/words (e.g., MOVS, CMPS, SCAS, LODS).
- Control Transfer: Alters program execution flow conditionally or unconditionally (e.g., JMP, JZ, CALL, RET, LOOP).
- Processor Control: Controls CPU state and flags (e.g., STC, CLC, CLI, STI, HLT).
(i) Sorting an Array (Bubble Sort):
- MOV CX, N-1 ; Number of passes
- OUTER: MOV BX, CX ; Inner loop counter
- LEA SI, ARRAY
- INNER: MOV AL, [SI]
- CMP AL, [SI+1]
- JBE SKIP ; Jump if already sorted
- XCHG AL, [SI+1]
- MOV [SI], AL ; Swap elements
- SKIP: INC SI
- DEC BX
- JNZ INNER
- LOOP OUTER
- HLT
(ii) Finding the Largest Element:
- LEA SI, ARRAY ; Point to array start
- MOV CX, N ; Total elements
- MOV AL, [SI] ; Assume first is largest
- DEC CX ; Decrement counter
- INC SI
- NEXT: CMP AL, [SI]
- JAE SKIP ; Jump if AL >= [SI]
- MOV AL, [SI] ; Update AL with new largest
- SKIP: INC SI
- LOOP NEXT
- MOV LARGEST, AL ; Store result
- HLT