Sunday, 13 December 2015

Assembly Program Prints The Alphabets

Write a program in 8086 assembly language that prints the alphabets from A to Z.

stack segment
stack ends
data segment
data ends
code segment
  mov ah,02h  
  mov cx,26   
  mov dl,65
lop:
  int 21h
  add dl,1   
  loop lop 
  mov ax,4c00h
  int 21h
code ends
end

Explanation of the code
CX is the counter resister which is decreases it's value by 1 every iteration of the loop "lop".
Hence Loop will be executed for 26 times and all the alphabets are printed using dl resister.

dl resister's value is 65, the ascii code for character 'A'.
Add dl,1; statement increase it's value by one to 'B' then increase by one to 'C' upto 26 times it prints all the alphabets A to Z.

Note:
For Printing Lower case Alphabets.
initialize dl by 97 - ascii code of 'a'.

No comments:

Post a Comment