You are on page 1of 24

Introduction to MASM

.model: Model is an assembler directive. It is to inform the assembler that how many
logical segments are used in the program.

.model tiny: In this model all the memory is treated as single segment.

.model small: In this model we have one code segment and one data segment.

.model large: In this model we have two code segments and two data segments.

.segment: Segment is an assembler directive. It is to tell the assembler that it is the


starting of the logical segment.

Ends: It is an assembler directive which informs the assembler that it is the end of the
segment.

Proc: Proc is used to call a subroutine.

Assume: This makes the logical segment into physical segment.

Masm: To convert the source code into object code and show errors.
Syntax: masm filename.asm

Link: To convert the object file into executable file.


Syntax: link filename.obj

Debug: To run the program.


Syntax: debug filename.exe
u: To unassembled the program.

q: To quit the program.

g: go(complete execution).

t: trace the program(step by step execution).

eds: To enter the data into data segment.

dds: To display the data from data segment.

Posted by A Chandra Shaker


Email This BlogThis! Share to Twitter Share to Facebook Share to Google Buzz
Labels: ALP, Assembly Language Programs, Macro Assembler Programs, MASM
Programs, Microprocessors and Interfacing Lab, MPI Lab
Microprocessors and Interfacing Lab - 2

MASM Programs - 1

8-bit Addition
code:-
.model small
.code
main proc
mov al,02h
mov bl,05h
add al,bl
hlt
main endp
end main

output:-
ax=0007

8-bit Addition using address location


code:-
.model small
.code
main proc
mov si,5000h
mov al,[si]
mov di,4000h
mov bl,[di]
add al,bl
hlt
main endp
end main

output:-
-eds:5000 5
-eds:4000 4

ax=0009

8-bit Subtraction
code:-
.model small
.code
main proc
mov al,12h
mov bl,21h
sub al,bl
hlt
main endp
end main

output:-
ax=00f1

8-bit Subtraction using address location


code:-
.model small
.code
main proc
mov si,2145h
mov al,[si]
mov di,5432h
mov bl,[di]
add al,bl
hlt
main endp
end main

output:-
-eds:2145 10
-eds:5432 4

ax=000c

8-bit Multiplication
code:-
.model small
.code
main proc
mov al,12h
mov bl,15h
mul al,bl
hlt
main endp
end main

output:-
ax=017a

8-bit Division
code:-
.model small
.code
main proc
mov al,10h
mov bl,02h
div bl
hlt
main endp
end main

output:-
ax=0008

16-bit Addition
code:-
.model small
.code
main proc
mov ax,0245h
mov bx,0436h
add ax,bx
hlt
main endp
end main

output:-
ax=067b

16-bit Subtraction
code:-
.model small
.code
main proc
mov ax,0245h
mov bx,0324h
sub ax,bx
hlt
main endp
end main

output:-
ax=ff21

16-bit Multiplication
code:-
.model small
.code
main proc
mov ax,0245h
mov bx,0123h
mul ax,bx
hlt
main endp
end main

output:-
ax=946f

16-bit Multiplication using address location


code:-
.model small
.code
main proc
mov si,5112h
mov ax,[si]
mov di,1224h
mov bx,[di]
mul bx
hlt
main endp
end main

output:-
-eds:5112 12 21
-eds:1224 22 13

ax=ba64

16-bit Division
code:-
.model small
.code
main proc
mov ax,0245h
mov bx,0124h
div bx
hlt
main endp
end main

output:-
ax=0001

16-bit Division using address location


code:-
.model small
.code
main proc
mov si,2432h
mov ax,[si]
mov di,5413h
mov bx,[di]
mul bx
hlt
main endp
end main

output:-
-eds:2432 44 24
-eds:5413 22 22

ax=0001

Factorial
code:-
.model small
.code
main proc
mov cl,05h
mov al,cl
dec cl
go:mul cl
loop go
hlt
main endp
end main

output:-
ax=0078

Factorial using address location


code:-
.model small
.code
main proc
mov si,2000h
mov cx,[si]
mov ax,cx
dec cx
go:mul cx
loop go
hlt
main endp
end main

output:-
-eds:2000 05 00

ax=0078

Posted by A Chandra Shaker


Email This BlogThis! Share to Twitter Share to Facebook Share to Google Buzz
Labels: ALP, Assembly Language Programs, Macro Assembler Programs, MASM
Programs, Microprocessors and Interfacing Lab, MPI Lab
Microprocessors and Interfacing Lab - 3

MASM Programs - 2

Sum of Numbers
code:-
.model small
.code
main proc
mov si,2000h
mov cl,04h
mov al,[si]
repeat:inc si
add al,[si]
loop repeat
hlt
main endp
end main

output:-
-eds:2000 08 06 0a 04 03

ax=001f

Average of Numbers
code:-
.model small
.code
main proc
mov si,2000h
mov cl,04h
mov bl,05h
mov al,[si]
repeat:inc si
add al,[si]
loop repeat
div bl
hlt
main endp
end main

output:-
-eds:2000 02 04 05 03 06

ax=0004

Sum of Squares
code:-
.model small
.code
main proc
mov si,3000h
mov cl,[si]
mov bx,00h
next:mov al,cl
mul cl
add bx,ax
dec cl
jnz next
hlt
main endp
end main

output:-
-eds:3000 04

bx=001e

Sum of Cubes
code:-
.model small
.code
main proc
mov si,3000h
mov cl,[si]
mov bx,00h
next:mov al,cl
mul cl
mul cl
add bx,ax
dec cl
jnz next
hlt
main endp
end main

output:-
-eds:3000 04

bx=0064

Ascending Order
code:-
.model small
.code
main proc
mov si,2000h
mov bl,05h
dec bl
go:mov cl,bl
repeat:mov al,[si]
inc si
cmp al,[si]
jb next
xchg al,[si]
dec si
mov [si],al
inc si
next:loop repeat
mov si,2000h
dec bl
jnz go
hlt
main endp
end main

output:-
-eds:2000 06 08 04 03 01
-dds:2000 01 03 04 06 08

Descending Order
code:-
.model small
.code
main proc
mov si,2000h
mov bl,05h
dec bl
go:mov cl,bl
repeat:mov al,[si]
inc si
cmp al,[si]
ja next
xchg al,[si]
dec si
mov [si],al
inc si
next:loop repeat
mov si,2000h
dec bl
jnz go
hlt
main endp
end main

output:-
-eds:2000 0f 03 0a 09 05

-dds:2000 0f 0a 09 05 03

Maximum of Numbers
code:-
.model small
.code
main proc
mov si,2000h
mov cl,05h
mov al,[si]
inc si
go:cmp al,[si]
jb next
jmp next1
next:mov al,[si]
next1:inc si
loop go
hlt
main endp
end main

output:-
-eds:2000 23 45 12 56 32 67

ax=0067

Minimum of Numbers
code:-
.model small
.code
main proc
mov si,3000h
mov cl,04h
mov al,[si]
inc si
go:cmp al,[si]
ja next
jmp next1
next:mov al,[si]
next1:inc si
loop go
hlt
main endp
end main

output:-
-eds:3000 23 45 12 56 32

ax=0012

Sum of Numbers
code:-
.model small
.code
main proc
mov si,2000h
mov cl,04h
mov al,[si]
repeat:inc si
add al,[si]
loop repeat
hlt
main endp
end main
output:-
-eds:2000 08 06 0a 04 03
ax=001f
Average of Numbers
code:-
.model small
.code
main proc
mov si,2000h
mov cl,04h
mov bl,05h
mov al,[si]
repeat:inc si
add al,[si]
loop repeat
div bl
hlt
main endp
end main
output:-
-eds:2000 02 04 05 03 06
ax=0004
Sum of Squares
code:-
.model small
.code
main proc
mov si,3000h
mov cl,[si]
mov bx,00h
next:mov al,cl
mul cl
add bx,ax
dec cl
jnz next
hlt
main endp
end main
output:-
-eds:3000 04
bx=001e
Sum of Cubes
code:-
.model small
.code
main proc
mov si,3000h
mov cl,[si]
mov bx,00h
next:mov al,cl
mul cl
mul cl
add bx,ax
dec cl
jnz next
hlt
main endp
end main
output:-
-eds:3000 04
bx=0064
Ascending Order
code:-
.model small
.code
main proc
mov si,2000h
mov bl,05h
dec bl
go:mov cl,bl
repeat:mov al,[si]
inc si
cmp al,[si]
jb next
xchg al,[si]
dec si
mov [si],al
inc si
next:loop repeat
mov si,2000h
dec bl
jnz go
hlt
main endp
end main
output:-
-eds:2000 06 08 04 03 01

-dds:2000 01 03 04 06 08
Descending Order
code:-
.model small
.code
main proc
mov si,2000h
mov bl,05h
dec bl
go:mov cl,bl
repeat:mov al,[si]
inc si
cmp al,[si]
ja next
xchg al,[si]
dec si
mov [si],al
inc si
next:loop repeat
mov si,2000h
dec bl
jnz go
hlt
main endp
end main
output:-
-eds:2000 0f 03 0a 09 05

-dds:2000 0f 0a 09 05 03
Maximum of Numbers
code:-
.model small
.code
main proc
mov si,2000h
mov cl,05h
mov al,[si]
inc si
go:cmp al,[si]
jb next
jmp next1
next:mov al,[si]
next1:inc si
loop go
hlt
main endp
end main
output:-
-eds:2000 23 45 12 56 32 67
ax=0067
Minimum of Numbers
code:-
.model small
.code
main proc
mov si,3000h
mov cl,04h
mov al,[si]
inc si
go:cmp al,[si]
ja next
jmp next1
next:mov al,[si]
next1:inc si
loop go
hlt
main endp
end main
output:-
-eds:3000 23 45 12 56 32
ax=0012
Logical AND
code:-
.model small
.code
main proc
mov ax,3f0f h
mov bx,0008h
and ax,bx
hlt
main endp
end main
output:-
ax=0008
Logical OR
code:-
.model small
.code
main proc
mov ax,3F0Fh
mov bx,0008h
or ax,bx
hlt
main endp
end main
output:-
ax=3f0f
Logical NOT
code:-
.model small
.code
main proc
mov ax,3F0Fh
not ax,bx
hlt
main endp
end main
output:-
ax=c0f0
Logical XOR
code:-
.model small
.code
main proc
mov ax,3F0Fh
mov bx,0008h
xor ax,bx
hlt
main endp
end main
output:-
ax=3f07
Length of String
code:-
.model small
.stack 100h
.data
a db 'chandra'
b dw $-a
.code
main proc
mov ax,@data
mov ds,ax
mov si,offset a
mov cx,b
int 21h
main endp
end main
output:-
cx=0007
Display a String
code:-
.model small
.stack 100h
.data
a db 'abcd'
b dw $-a
.code
main proc
mov ax,@data
mov ds,ax
mov si,offset a
mov cx,b
repeat:mov dl,[si]
mov ah,02h
int 21h
inc si
loop repeat
mov ah,04h
int 21h
main endp
end main
output:-
abcd
Reverse a String
code:-
.model small
.stack 100h
.data
a db 'abcd'
b dw $-a
.code
main proc
mov ax,@data
mov ds,ax
mov si,offset a
mov cx,b
add si,cx
dec si
repeat:mov dl,[si]
mov ah,02h
int 21h
dec si
loop repeat
mov ah,04h
int 21h
main endp
end main

output:-
dcba
Palindrome Number
code:-
.model small
.code
main proc
mov si,4000h
mov cl,04h
mov ax,[si]
mov bx,[si]
xchg al,ah
ror al,cl
ror ah,cl
cmp ax,bx
jc next
mov dl,00h
jz exit
next:mov dl,01h
exit:hlt
main endp
end main
output:-
-eds:4000 12 21

dx=0000
FAQ - 1
1. Define microprocessor?
A microprocessor is a multipurpose, programmable, clock-driven, register-
based electronic device that reads binary instructions from a storage
device called memory accepts binary data as input and processes data
according to instructions, and provides result as output.
2. Define microcomputer?
A computer that is designed using a microprocessor as its CPU. It
includes microprocessor, memory, and I/O.
3. Define ROM?
A memory that stores binary information permanently. The information
can be read from this memory but cannot be altered.

4. What is an ALU?
The group of circuits that provides timing and signals to all operation in
the computer and controls data flow.
5. Define small-scale integration?
The process of designing a few circuits on a single chip. The term refers
to the technology used to fabricate logic gates on a chip.
6. What is an instruction?
An instruction is a binary pattern entered through an input device in
memory to command the microprocessor to perform specific function.
7. What are the four primary operations of a MPU?
a. Memory read
b. Memory write
c. I/O read
d. I/O write
8. What do you mean by address bus?

The address bus is a group of 16 lines generally identified as A0 to


A15. The address bus is unidirectional: bits flow from MPU to peripheral
devices.

9. How many memory locations can be addressed by a


microprocessor with 14 address lines?

The 8085 MPU with its 14-bit address is capable of addressing 214
=16,384 (ie) 16K memory locations.
10. Why is the data bus bi-directional?

The data bus is bi-directional because the data flow in both directions
between the MPU and memory and peripheral devices.

You might also like