Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

MICROPROCESSORS AND MICROCONTROLLERS LAB

Regulations : AR 17
Course Code : 171EC6L07

Semester : VI Sem
Name :
Roll No :
Section :

DEPT. OF ELECTRONICS AND COMMUNICATION ENGINEERING

ADITYA ENGINEERING COLLEGE(A)


Index

MARKS AND
S. NO NAME OF THE EXPERIMENT DATE SIGNATURE

1 ARITHMETIC OPERATIONS ON 16-BIT DATA

2 MULTI BYTE ADDITION/SUBTRACTION

3 SUM OF SQUARES/CUBES OF A GIVEN N-NUMBERS

4 FINDING NUMBER OF 1’S AND NUMBER OF 0’S IN A GIVEN 8-BIT


NUMBER

5 ADDITION OF EVEN NUMBERS FROM A GIVEN ARRAY

6 AVERAGE OF N-NUMBERS
s

AVERAGE MARKS

Name of the Student

Roll Number

Signature of the Faculty Signature of the HOD

Dept Seal:
INTRODUCTION TO MASM/TASM
ASSEMBLY LANGUAGE PROGRAMMING USING MASM SOFTWARE:

The programs are written using assembly language in editor then compile it. The complier converts
assembly language statements into machine language statements/checks for errors. Then execute the
compiled program.

There are different soft wares developed by different companies for assembly language programming,
they are:

 MASM - Microsoft Company


 TASM - Bore Land Company

MERITS OF MASM:

1. Produces binary code


2. Referring data items by their names rather than by their address

HOW TO ENTER INTO MASM EDITOR:

 Click DOS BOX icon on the desktop.

 Path setting
Suppose it display path as Z:\>

Then type MOUNT C C:\ MASM then drive c is mounted as local directory C:\MASM\

Then the path is Z:\>


Then type C:
Then the path is C:\>
Then type edit i.e.; C:\>edit

Then you enter into MASM text editor


write the ALP (Assembly Language Program) in this editor
After writing the program, save the filename with .asm extension
After save the file, click on file menu then go to exit
Then exit from the editor and go to prompt.
Then type MASM filename.ASM
I.e. C:\> MASM filename.ASM or C:\> MASM filename.ASM, , ;
Then link this file using C: \>LINK filename.OBJ or C:\>LINK filename.OBJ , , ;
i.e., link the program in assembly with DOS
then debug to create exe file
C :\> debug filename. EXE
Then it display “-” on the screen
After that type ‘R’ displays the registers contents and starting step of the program.
‘T’ tracing at contents of program step by step
Suppose you need to go for break point debugging. Then type that instruction no where you need to check your register.
For example T10 it will display the contents of register after executing 10 instructions.

DEBUG:

This command utility enables to write and modify simple assembly language programs in an easy fashion. It
provides away to run and test any program in a controlled environment.

We can change any part of the program and immediately execute the program with resemble of it. We can also
run machine language (Object files) directly by using DEBUG.

DEBUG COMMANDS:

ASSEMBLE A [address] ; Assembly the instructions at a particular address

COMPARE C range address ; Compare two memory ranges

DUMP D [range] ; Display contents of memory

ENTER E address [list] ; Enter new or modifies memory contents beginning


at specific Location
FILL F range list ; Fill in a range of memory

GO G [=address] [addresses]; Execute a program in memory

HEX H value1 value2 ; Add and subtract two Hex values

INPUT I port

LOAD L [address] [drive] [first sector] [number]

MOVE M range address


NAME N [pathname] [arg list]

OUTPUT O port byte

PROCEED P [=address] [number]

QUIT Q

REGISTER R [register]

SEARCH S range list

TRACE T [=address] [value]

UNASSEMBLE U [range]

WRITE W [address] [drive] [first sector] [number]

ALLOCATE expanded memory XA [#pages]

DEALLOCATE expanded memory XD [handle]

MAP expanded memory pages XM [Lpage] [Ppage] [handle]

DISPLAY expanded memory status XS


PART- A:
8086 Assembly Language Programming using Assembler
Directives

01. ARITHMETIC OPERATIONS ON 16-BIT DATA


02. MULTI BYTE ADDITION/SUBTRACTION
03. SUM OF SQUARES/CUBES OF A GIVEN N-NUMBERS
FLOW CHART:

Initialize DS

SI

AX

AX

AX

AX Data1

DX

DX AX / BX
Exp No:

Date:
1. ARITHMETIC OPERATIONS ON 16-BIT DATA

ABSTRACT: Assembly language program to perform all arithmetic operations on 16bit data
PORTS USED: None
REGISTERS USED: AX, BX, SI
ALGORITHM:
Step1: Start
Step2: Initialize data segment
Step3: Initialize SI with some memory location
Step4: Load the given data to registers AX & BX
Step5: Perform addition and Store the result
Step6: Repeat step 4
Step7: Perform subtraction and Store the result
Step8: Repeat step 4
Step9: Perform multiplication and Store the result
Step10: Repeat step 4
Step11: Perform division and Store the result
Step12: Stop
CODE TABLE:

Physical Address
Label Hex Code Mnemonic operand Comments
Segment Offset
Address Address
PROGRAM:

ASSUME CS: CODE, DS: DATA


DATA SEGMENT
N1 EQU 8888H
N2 EQU 4444H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV SI, 5000H
MOV AX, N1
MOV BX, N2
ADD AX, BX
MOV [SI], AX
MOV AX, N1
SUB AX, BX
MOV [SI+2], AX
MOV AX, N1
MUL BX
MOV [SI+4], AX
MOV [SI+6], DX
MOV AX, N1
MOV DX, 0000
DIV BX
MOV [SI+8], AX
MOV [SI+0AH], DX
MOV AH, 4CH
INT 21H
CODE ENDS
END START

MANUAL CALCULATIONS:

RESULT:
FLOW CHART:

START

Initialize DS
Initialize Data1,
Data2
CX COUNT
BX COUNT-1

AL Data1 [BX]

AL Data1 [BX] +Data2 [BX] + CF

Data memory AL

BX BX-1
CX CX-1

NO

CX=
YES

CX COUNT
BX COUNT-1

AL Data1 [BX]

AL Data1 [BX]-Data2 [BX]-CF

Data memory AL

BX BX-1
CX CX-1

NO

YES

STOP
Exp No:
Date:
2. MULTIBYTE ADDITION AND SUBTRACTION
ABSTRACT: Assembly language program to perform multibyte addition and subtraction
PORT USED: None
REGISTERS USED: AL, BX, CX
ALGORITHM:
Step 1: Start
Step 2: Initialize data segment
Step 3: Load CX register with count
Step 4: Load BX register with No. of bytes
Step 5: Copy the contents from the memory location n1 [BX] to AL
Step 6: Perform addition with second number n2 [BX]
Step 7: Store the result to the memory location sum [BX]
Step 8: Decrement BX
Step 9: Decrement CX, if CX not equal to Zero jump to step5
Step 10: Load CX register with count
Step 11: Load BX register with no: of bytes
Step 12: Store the contents from memory location n1 [BX] to AL
Step 13: Perform subtraction with second number n2 [BX]
Step 14: Store the result to the memory location sum [BX]
Step 15: Decrement BX
Step 16: Decrement CX, if CX not equal to Zero jump to step12
Step 17: Stop
CODE TABLE:
Physical Address
Mnemonic
Segment Offset Hex
Label Operands Comments
Address Address Code
PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
N1 DB 33H, 33H, 33H
N2 DB 11H, 11H, 11H
COUNT EQU 0003H
SUM DB 03H DUP (00)
DIFF DB 03H DUP (00)
DATA ENDS
CODE SEGMENT
ORG 1000H
START:
MOV AX, DATA`
MOV DS, AX
MOV CX, COUNT
MOV BX, 0002H
CLC
BACK: MOV AL, N1 [BX]
ADC AL, N2 [BX]
MOV SUM [BX], AL
DEC BX
LOOP BACK
MOV CX, COUNT
MOV BX, 0002H
CLC
BACK1: MOV AL, N1 [BX]
SBB AL, N2 [BX]
MOV DIFF [BX], AL
DEC BX
LOOP BACK1
MOV AH, 4CH
INT 21H
CODE ENDS
END START

MANUAL CALCULATIONS:

RESULT:
FLOW CHART:

Start

Initialize DS
DX, AX 0
CX No. of Numbers
SI Offset Address

AL, BL [SI]
AX AL*BL
SI SI+1
DX AX+DX
CX CX-1

ZF=
1
NO

YES
[Memory
[M Location] DX

END
Exp No:
Date:
3. SUM OF SQUARES OF GIVEN N NUMBERS
ABSTRACT: Assembly language program to perform sum of squares of given numbers
PORT USED: None
REGISTERS USED: AX, BL and DX
ALGORITHM:
Step 1: Start
Step 2: Initialize data segment
Step 3: Load CX register with count
Step 3: Initialize AX and DX register values to zero
Step 4: Load SI with offset list
Step 5: Copy the contents from memory location SI to AL
Step 6: Copy the contents of AL to BL
Step 7: Perform multiplication between the contents of AL and BL
Step 8: Perform addition between the contents of Ax and DX
Step 9: Increment SI
Step 10: Decrement CX and jump to step 5 if no zero
Start 11: Store the result to the data memory
Step 12: Stop

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
LIST DB 02H, 03H, 04H
RES DW 01H DUP (00)
DATA ENDS
CODE SEGMENT
ORG 1000H
START:
MOV AX, DATA
MOV DS, AX
MOV CX, 0003H
XOR AX, AX
XOR DX, DX
MOV SI, OFFSET LIST
BACK: MOV AL, [SI]
MOV BL.AL
MUL BL
ADD DX, AX
INC SI
LOOP BACK
MOV [RES], DX
MOV AH, 4CH
INT 21H
CODE ENDS
END START
CODE TABLE:
Physical Address
Label Hex Code Mnemonic Comments
Segment Offset
Operands
Address Address
MANUAL CALCULATIONS:

RESULT:
PART- B:
8051 Assembly Language Programs
1. Finding number of 1’s and number of 0’s in a given 8-bit number
2. Addition of even numbers from a given array
3. Average of n-numbers
Introduction to Keil Simulation

1. Open the Keil Vision3 on desktop.

2. 2.Go to file & open new project and new file,type the program & save as file name.c.Go to Project
– Open Project and browse for saved file and open it.

3. Go to Project – Select Device for Target ‘Target1’.


4. Select ATMEL family microcontroller AT89S52 and click OK.

5. Go to project – Options for Target ‘Target1’.


6. Make sure that the oscillator frequency is 11.059MHz. Put tick mark on “use on chip ROM”. Go to
output, put tick mark on “create HEX file”. Click ok.

7. Build the target as illustrated in the figure below,check whether HEX file is created or not.
8. Running the Simulation

Having successfully built the target, we are now ready to start the debug session and run the simulator.
First start a debug session.
FLOW CHART:

Initialize
R1 00
R2 00
R7 08
DPTR Memory Address

A [DPTR]

A Rotate Left A

YES NO
CF=
1

R2 R2+1 R1 R1+1

R7 R7-1

YES NO
ZF=
1

[DPTR+1] R1
[DPTR+2] R2

STOP
Exp No:

Date:

1.Finding number of 1’s and number of 0’s in a given 8-bit number


ABSTRACT: Assembly language program to find number of 1’s and 0’s

PORTS USED: None

REGISTERS USED: R1, R2, R7, A, DPTR

ALGORITHM:

Step 1: Start
Step 2: Initialize R1 and R2 registers with zeros
Step 3: Load the value 08H into R7 register
Step 4: Initializing base address location where given number is stored
Step 5: Coping value from memory location at which DPTR is pointing
Step 6: Rotate Accumulator Left Through Carry
Step 7: if CY=1 then Jump to Step 10
Step 8: Increment the content of R1 register
Step 9: Jump to Step11
Step 10: Increment the content of R2 register
Step 11: Decrement register R7 and jump if not Zero to step 6
Step 12: Moving the content of R1 to register A
Step 13: Increment the content of DPTR register
Step 14: Moving the content of register A to external RAM
Step 15: Moving the content of R2 to register A
Step 16: Increment the content of DPTR register
Step 17: Moving the content of register A to external RAM
Step 18: Repeat step18
CODE TABLE:

Memory Label Hex Mnemonic Comments


Address Code Operands
PROGRAM:
MOV R1, #00
MOV R2, #00
MOV R7, #08
MOV DPTR, #4500
MOVX A, @DPTR
AGAIN: RLC A
JC NEXT
INC R1
SJMP HERE
NEXT: INC R2
HERE: DJNZ R7, AGAIN
MOV A, R1
INC DPTR
MOVX @DPTR, A
MOV A, R2
INC DPTR
MOVX @DPTR, A
HLT: SJMP HLT

MANUAL CALCULATIONS:

RESULT:
FLOW CHART:

Initialize
R1 No of numbers
R2 00
DPTR Memory Address

A [DPTR]

A Rotate Right A

YES NO
CF=
1

DPTR DPTR+1
R1 R1-1 R2 [DPTR] +R2

NO ZF= YES
1

[DPTR] R2

STOP
Exp No:
Date:
02. ADDITION OF EVEN NUMBERS FROM A GIVEN ARRAY
ABSTRACT: Assembly language program to find the Addition of even numbers from a
given array.
PORTS USED: None
REGISTERS USED: A, R1, R2, DPTR
ALGORITHM:
Step 1: Start
Step 2: Clear the Carry flag i.e CF=0
Step 3: Load the value 04H into R1 register
Step 3: Initializing R2 register to zero
Step 4: Initializing base address location where given number is stored
Step 5: Coping value from memory location at which DPTR is pointing
Step 6: Bit 0 of the accumulator is rotated into the carry
Step 6: Rotate Accumulator Left Through Carry
Step 7: Jump if Carry Not Set to step 9
Step 8: Transfers execution to the specified address to step 13
Step 9: Moving the content of external RAM to register A
Step 10: Adds the contents of register A and Register R2
Step 11: Moving the content of register A to external RAM
Step 12: Moving the content of register R2 to register A
Step 13: Increment the content of DPTR register
Step 14: Decrement register R1 and jump if not Zero to step 9
Step 15: Repeat step15
CODE TABLE:

Memory Label Hex Code Mnemonic Comments


Address Operands
PROGRAM:
CLR C
MOV R1, #04
MOV R2, #00H
MOV DPTR, #6000H
UP: MOVX A, @DPTR
RRC A
JNC SKIP
SJMP EXIT
SKIP: MOVX A, @DPTR
ADD A, R2
MOV R2, A
EXIT: INC DPTR
DJNZ R1, UP
MOV A, R2
MOVX @DPTR, A
HLT: SJMP HLT

MANUAL CALCULATIONS:

RESULT:
FLOW CHART:

Initialize
R1 No of
Numbers
R2 00
DPTR Memory

A [DPTR]

R2 A + R2
DPTR DPTR + 1
R1 R1-1

ZF=
1
YES NO

A R2 ÷ R1
A Quotient
B Remainder

[DPTR+1] A
[DPTR+2] B

STOP
Exp No:
Date:
03. AVERAGE OF GIVEN N NUMBERS BY USING 8051
ABSTRACT: Assembly language program to find the average of N numbers.
PORTS USED: None
REGISTERS USED: A, B, R1, R2, DPTR
ALGORITHM:
Step 1: Start
Step 2: Load the value 05H into R1 register
Step 3: Moving the content of R1 to register B
Step 4: Initializing R2 register to zero
Step 5: Initializing base address location where given number is stored
Step 6: Coping value from memory location at which DPTR is pointing
Step 6: Rotate Accumulator Left Through Carry
Step 7: Adds the content of Accumulator and content of R2 register.
Step 8: Moving the content of A to register R2.
Step 9: Increment the content of DPTR register
Step 10: Decrement register R1 and jump if not Zero to step 6
Step 11: Moving the content of register R2 to register A.
Step 12: Divide Accumulator by B
Step 13: Moving the content of register A to external RAM
Step 14: Increment the content of DPTR register
Step 15: Moving the content of B to register A
Step 16: Moving the content of register A to external RAM
Step 17: Repeat step17

PROGRAM:
MOV R1, #05
MOV B, R1
MOV R2, #00H
MOV DPTR, #5500H
UP: MOVX A, @DPTR
ADD A, R2
MOV R2, A
INC DPTR
DJNZ R1, UP
MOV A, R2
DIV AB
MOVX @DPTR, A
INC DPTR
MOV A, B
MOVX @DPTR, A
HLT: SJMP HLT
CODE TABLE:

Memory Label Hex Code Mnemonic Comments


Address Operands
MANUAL CALCULATIONS:

RESULT:

You might also like