Tuesday, November 2, 2010

Assembly Language Programming

Assebly Language Programming

;1;Program to display a message 20 times in different line
.model small
.stack 100h
.data
    msg1 db 'hello $'
.code
    main proc
    mov ax,@data
    mov ds,ax
    lea dx,msg1
    mov ah,9
    int 21h


    mov ah,2
    mov dx,0dh
    int 21h

    mov dx,0ah
    int 21h

    mov cx,20
    mov ah,9
    mov al,msg1

top:
    int 21h
    loop top

    mov ah,4ch
    int 21h
main endp
    end main
////////////////////////////////////////////////////////////////////////////////////
;3.Program to read a character.If its 'y' or 'Y' , display it; otherwise terminate the program
.model small
.stack 100h
.data
    cr equ 0dh
    lf equ 0ah
    msg1 db 'Enter y or Y : $'
    msg2 db 0dh,0ah,'display this : '
.code
    main proc
    mov ax,@data
    mov ds,ax
    lea dx,msg1     ;display message
    mov ah,9
    int 21h
  
    mov ah,1        ;take input as y or Y
    int 21h
  
    cmp al,'y'      ;compare with y
    je display         ;jump if equal y
  
    cmp al,'Y'      ;compare with Y
    je display         ;jump if equal Y
    jmp end       ;jump if not equal Y

display:
    mov ah,2
    mov dl,al
    int 21h
end:
    mov ah,4ch
    int 21h
main endp
    end main
/////////////////////////////////////////////////////////////////////////////
;4. Program to convert a lowercase to an uppercase
.model small
.stack 100h
.data

    msg1 db 'Enter a lower case letter:$'
    msg2 db 0dh,0ah,'In upper case is: '
    char db ?,'$'
main proc
    mov ax,@data
    mov ds,ax
  
    lea dx,msg1     ;show msg1
    mov ah,9
    int 21h
  
    mov ah,1        ;for taking input
    int 21h
    sub al, 20h     ;subtract 32 from al
    mov char,al

     lea dx,msg2     ;show msg2
    mov ah,9
    int 21h
  
    mov ah,4ch
    int 21h
main endp
    end main
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;5.Program to convert  an uppercase to an lowercase

.model small
.stack 100h
.data
    cr equ 0dh
    lf equ 0ah
    msg1 db 'enter a upper case letter:$'
    msg2 db 0dh,0ah,'in lower case it is:'
    char db ?,'$'
main proc
    mov ax,@data
    mov ds,ax
  
    lea dx,msg1     ;show message
    mov ah,9
    int 21h
    mov ah,1        ;for taking input
    int 21h
  
    add al, 20h     ;add 32 with al
    mov char,al
   
     lea dx,msg2     ;show message2
     mov ah,9
     int 21h
    mov ah,4ch      ;terminate program
    int 21h
main endp
    end main
/////////////////////////////////////////////////////////////////////////
;6.  Program to display all alphabetic characters

.model small
.stack 100h
.data
 
    s1 db 0ah, 0dh,'capital alphabetic(a - z) : $'
    s2 db 0ah, 0dh,'small alphabetic  (a - z) : $'
 
.code
      main proc
      mov ax,@data
      mov ds,ax

      lea dx,s1    ;show message s1
      mov ah,9    ;for display function
      int 21h

      mov cx,26    ;take 26 at cx for loop
      mov dl,65d    ;load 65d at dl

l_1:
    mov ah,2    ;show
        int 21h
        inc dl        ;increment dl by 1
        loop l_1    ;end of loop1

    lea dx,s2    ;show message s2
    mov ah,9
    int 21h

    mov cx,26      
    mov dl,97d    ;load 97 at dl

l_2:            ;starting of loop2
    mov ah,2
    int 21h
    inc dl        ;increment dl by 1
       loop l_2        ;end of loop2
      
    mov ah,4ch
    int 21h
        
main endp
    end main

Update of No 6:
;6.  Program to display all alphabetic characters

.model small
.stack 100h
.data
 
    s1 db 0ah, 0dh,'Alphabetic Letters are: $'
 
.code
      main proc
      mov ax,data
      mov ds,ax

      lea dx,s1    ;show message s1
      mov ah,9    ;for display function
      int 21h

      mov cx,26    ;take 26 at cx for loop
      mov dl,65d    ;load 65d at dl

l_1:
    mov ah,2    ;show
        int 21h
        inc dl        ;increment dl by 1
        loop l_1    ;end of loop1
   
    mov ah,4ch
    int 21h

main endp
    end main
/////////////////////////////////////////////////////////////

No comments:

Post a Comment

Total Pageviews