introduction:

Assembly language are a family of low level languages for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to make a program. A utility program called an Assembler is used to translate assembly language statements into the target computer’s machine code. Using an assembler it is very easy to write and execute programs.

Assembler Programming

To build assembler program using MASM program is a different program structure than from using debug program.

A Directive tells the assembler to do something when translating your program to machine code. It’s important to know all assembler directives.

.MODEL SMALL: Assembler directive that defines the memory model to use in the program. (Up to 64KB)

.STACK: Assembler directive that reserves a memory space for instruction in the stack.

.CODE: Assembler directive that defines the program instructions.

Lets understand all these things by solving some problems

Write a program to display “Hello World” on screen

.model small
.stack 100h
.data
message db ‘Hello World’,’$’        ;string that we have to display on screen
.code
mov ax,@data                              ;by using .data our data will store somewhere in data segment
                                                     ;to retrieve it we will @data and store it it ax
mov ds,ax
mov dx,offset message                ;this command is used to display string given in message
mov ah,09h                                  ;this command is used to display string
int 21h

mov ax,4c00h
int 21h
end

Output:

Note: ‘$’ is used to terminate the string

Write a program to display “*****” on screen.

.model samll
.stack
.code
mov cl,05h           ;act as loop and run 5 times
new:                     ;function name
mov dl,’*’
mov ah,2h
int 21h

dec cl                ;decremented the loop
jnz new             ;calling back loop in function if not-equal to zero
mov ah,4ch
int 21h
end

Output:

Write a code enter 5 number and find there sum

.model small

.stack 100h

.data

msg1 db ‘Enter a number’,’$’        ;entering a string ‘$’ is used to terminate the string

.code

mov ax,@data

mov ds,ax

mov cl,05h

mov dx,offset msg1

mov ah,9h

int 21h

new:

mov ah,1h

int 21h

add bl,al

sub bl,30h

dec cl

jnz new

add bl,30h

mov dl,bl

mov ah,2h

int 21h

mov ax,4c00h

int 21h

ret

Write a program to enter two numbers and find there product

.model small

.stack 100h

.code

mov ah,1h               ;entering first number

int 21h

mov bl,al

mov ah,1h                ;entering 2nd number

int 21h

mov cl,al

sub cl,30h                 ;subtracting 30h from cl we obtain ascii value of that number

new:

add bh,bl

sub bh,30h

dec cl

jnz new

add bh,30h

mov dl,bh

mov ah,2h

int 21h

end