Friday, November 9, 2012

Simple Programs

 Copy and Paste the following  Code to any Code Editor like notepad and notepad++ in any filename you want but don't forget to give an assembly program extension name. (e.g. sample.asm)

Then run the program using Assembler and Linker.


1.) Display Hello World
Code:
Title Greeting
.model small
.stack 10h
.data
    message db "Hello world Im "

.code
    mov ax,@data
    mov ds,ax

    mov ah,09h
    lea dx,message
    int 21h

    mov ah,4ch
    int 21h

end

2.) Use ASCII Code to display Characters
Code:
Title ASCII
.model small
.stack 10h
.data

    prompt db "ASCII",32,67,6Fh,144o,01100101b,'s',32,'s'

.code
    mov ax,@data
    mov ds,ax

    mov ah,09h
    lea dx,prompt
    int 21h

    mov ah,02h
    mov dl,'H'
    int 21h

    mov dl,'i'
    int 21h

    mov ah,4ch
    int 21h

end    

3.) Visual Enhancement using ASCII Code
Code:
Title Visual Enhancement
.model small
.stack 10h
.data 

    message db 205,10,13
         db "Hello,World$"
        db 200,12 dup(205),'$'

.code

    mov ax,@data
    mov ds,ax

    mov ah,09h
    lea dx,message
    int 21h

    mov ah,4ch
    int 21h

end

4.) Accepting Input
Code:
Title Input Operation
.model small
.stack 10h
.data

    Prompt db "Enter your inputs$"
    message1 db "You have press the",9
    mem_var db (?),'$'
    message2 db "Character$"

.code

    mov ax,@data
    mov ds,ax

    mov ah,2
    lea dx,prompt
    int 21h

    mov ah,1
    int 21h

    mov mem_var,al

    mov ah,2
    mov dl,10
    int 21h

    mov dl,13
    int 21h

    mov ah,9
    lea dx,message1,al,message2
    int 21h

   

    mov ah,4ch
    int 21h

end




5.)Applying Looping
Code:
Title Input Operation
.model small
.stack 10h
.data

    Prompt db "Enter your name:$",10,13
    message1 db "You have press the",10,13
    mem_var db (?),'$',13
    message2 db "Character$"

.code

    mov ax,@data
    mov ds,ax
   
    mov cx,3
back:
    mov ah,9
    lea dx,prompt
    int 21h

    mov ah,0ah
    int 21h

    mov mem_var,al
   
    mov ah,2
    mov dl,10
    int 21h

    mov dl,13
    int 21h

    mov ah,9
    lea dx,message1
    int 21h

loop back   

    mov ah,4ch
    int 21h

end
 
6.) Reverse String Input
Code:
title string input
.model small
.stack 10h
.data
    string db 5 dup(?)
    stop_string db 10,13,"$"
    prompt db "Enter the five letter word:$"
.code
    mov ax,@data
    mov ds,ax
   
    mov ah,9
    lea dx,prompt
    int 21h
   
    mov cx,5
repeat:
    mov si,cx
   
    mov ah,1
    int 21h
   
    mov string[si],al
   
loop repeat

    mov ah,9
    lea dx,string
    int 21h
   
    mov ah,4ch
    int 21h
   
end
   
7.) Using Increment and Decrement
Code:
Title Inc Dec
.model small
.stack 10h
.data
    prompt db "Type a letter: $"
.code
    mov ax,@data
    mov ds,ax
   
    mov ah,9
    lea dx,prompt
    int 21h
   
    mov ah,1
    int 21h
   
    mov bl,al
   
    mov cx,5
back:
    mov ah,2
    mov dl,10
    int 21h
   
    mov dl,13
    int 21h
   
    mov dl,bl
    int 21h
   
    ;inc bl
    dec bl
   
loop back

    mov ah,4ch
    int 21h
end



8.) Simple Arithmetic Operation
Code:
Title arithmetic
.model small
.stack 10h
.data
    prom db "Enter the 1st no.:$"
    promp db "Enter the 2nd no.:$"
    result db "The answer is$"
    num db 2 dup(?),'$'
    stop_num db,10,13,'$'
.code
    mov ax,@data
    mov ds,ax
   
    mov ah,9
    lea dx,prom
    int 21h
   
    mov ah,1
    int 21h
   
    mov num[0],al
   
    mov ah,2
    mov dl,10
    int 21h
   
    mov dl,13
    int 21h
   
    mov ah,9
    lea dx,promp
    int 21h   
   
    mov ah,1
    int 21h
   
    mov num[1],al
   
    mov bl,0
   
    add bl,num[0]
    add bl,num[1]
   
    sub bl,30h
   
    mov ah,2
    mov dl,10
    int 21h
   
    mov dl,13
    int 21h
   
    mov ah,9
    lea dx,result
    int 21h
   
    mov dl,13
    int 21h   
   
    mov ah,2
    mov dl,bl
    int 21h
   
    mov ah,4ch
    int 21h
   
end

Hope it will help to Assembly Language Programming Beginners!


Comming Soon! 

Wait for the Code of this Abstract Art made by Me..



    Thanks! for those can and will read my blog..

 Add Me on facebook!

    

2 comments:

Unknown said...

Just ask any question here and I will answer it with all of my best. :)

Unknown said...

Describe the physical address generation by considering the DS=4900H and BX=0A23H