← Back to Home

Practical 2

Implementation of various ALU operations (ADD, SUB, MUL, DIV, AND, OR, XOR, NOT) through assembly language programming for 8086 using MASM and Debug.

Theory

  1. What is the function of the ALU in a microprocessor?
  2. Explain the difference between ADD, SUB, MUL, and DIV instructions in 8086 assembly.
  3. How does the AND, OR, XOR, and NOT operations affect the contents of a register?
  4. Describe the role of the MUL and DIV instructions in 8086.
  5. Why is it necessary to initialize the data segment register (DS) before performing operations?
  6. What is the significance of the int 21h instruction at the end of the program?

Code

Create a file named exp2.asm in Notepad and save it in D:\TASM:

.model small
.stack 100h
.data

.code
main proc
     mov ax, @data
     mov ds, ax

     ; ADD operation
     mov al, 05h
     add al, 03h   ; AL = 08h

     ; SUB operation
     sub al, 02h   ; AL = 06h

     ; MUL operation
     mov al, 04h
     mov bl, 03h
     mul bl        ; AX = AL * BL = 0Ch

     ; DIV operation
     mov ax, 0012h ; 18 in decimal
     mov bl, 06h
     div bl        ; AL = 03h, AH = remainder

     ; AND operation
     mov al, 0Fh
     and al, 0Ah   ; AL = 0Ah

     ; OR operation
     mov al, 04h
     or al, 01h	; AL = 05h

     ; XOR operation
     mov al, 07h
     xor al, 03h   ; AL = 04h

     ; NOT operation
     mov al, 0F0h
     not al        ; AL = 0Fh

     mov ah, 4ch
     int 21h
main endp
end main
    

Compilation and Execution using TASM

Inside DOSBox, compile and run:

    tasm filename.asm
    tlink filename.obj
    

Using Debug Tool

Run Debug:

td filename.exe