← Back to Home

Practical 5

To perform BCD addition of two 8-bit numbers from keyboard using INT 21H.

Theory

  1. What is BCD addition and how is it different from binary addition?
  2. Explain the role of INT 21H in accepting input and displaying output in 8086 assembly.
  3. Why is the DAA (Decimal Adjust after Addition) instruction used in BCD addition?
  4. Describe the steps to perform BCD addition of two 8-bit numbers using keyboard input in 8086 assembly.

Code

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

 .model small 
 .stack 100h 
 .data 
  msg1 db "Enter first BCD digit: $" 
  msg2 db 0Dh,0Ah,"Enter second BCD digit: $" 
  resmsg db 0Dh,0Ah,"Sum = $" 
 .code 
  main proc 
  mov ax, @data 
  mov ds, ax 
 
  ; Display first prompt 
  lea dx, msg1 
  mov ah, 09h 
  int 21h 
 
  ; Input first digit 
  mov ah, 01h 
  int 21h 
  sub al, 30h     ; Convert ASCII to numeric 
  mov bl, al 
 
  ; Display second prompt 
  lea dx, msg2 
  mov ah, 09h 
  int 21h 
 
  ; Input second digit 
  mov ah, 01h 
  int 21h 
  sub al, 30h 
  add al, bl 
  daa          ; BCD adjust 
  add al, 30h     ; Convert back to ASCII 
 
  ; Display result message 
  lea dx, resmsg 
  mov ah, 09h 
  int 21h 
  ; Display result 
  mov dl, al 
  mov ah, 02h 
  int 21h 
  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