0% found this document useful (0 votes)
98 views87 pages

MPMC Manual - Ar17

The document provides information on assembly language programming using MASM software. It discusses entering the MASM editor, compiling and linking programs, and debugging programs using the DEBUG utility. It also outlines 12 experiments involving arithmetic operations, sorting, interfacing with ports, and other tasks using 8086 and 8051 assembly language. Flowcharts are provided for multi-byte addition/subtraction and arithmetic operations on 16-bit data.

Uploaded by

Sowmya Chowdary
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views87 pages

MPMC Manual - Ar17

The document provides information on assembly language programming using MASM software. It discusses entering the MASM editor, compiling and linking programs, and debugging programs using the DEBUG utility. It also outlines 12 experiments involving arithmetic operations, sorting, interfacing with ports, and other tasks using 8086 and 8051 assembly language. Flowcharts are provided for multi-byte addition/subtraction and arithmetic operations on 16-bit data.

Uploaded by

Sowmya Chowdary
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 87

MICRO PROCESSORS & MICRO CONTROLLERS

LAB MANUAL
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

1. Arithmetic operations on 8 bit & 16 Bit, Multi-byte


addition/subtraction using 8086 MASM software.

2. Sum of squares/cubes of a given n-numbers using 8086


MASM software.

3. Addition of n-BCD numbers using 8086 MASM software.


4. Factorial of given n-numbers using 8086 MASM software.
5. Sorting using 8086 MASM software.
6. Interfacing of 8086 using Software Interrupt Application.
7. Interfacing of D/A through Intel 8255.
8. Keyboard and Display Interface through Intel 8279.
9. Find number of 1’s and number of 0’s in a given 8-bit number
Using 8051 KEIL software.

10. Addition of even numbers from a given array Using 8051


KEIL software.

11. Interfacing of 8051 using Switches and LEDs.


12. Interfacing of 8051 using Stepper Motor Interface.
FLOW CHART:
START

Initialize DS
AL Data1
BL Data2

AL AL+BL

Data Memory AL

AL Data1

AL AL-BL

Data Memory AL

AL Data1

AX AL*BL
Data Memory AX

AL Data1
AH 00H

AX AX / BL
Data Memory AX

STOP
Exp No:

Date:

1.ARITHMETIC OPERATIONS ON 8-BIT DATA

ABSTRACT: Assembly language program to perform all arithmetic


operations on 8-bit data
PORTS USED: None
REGISTERS USED: AX, BL
ALGORITHM:
Step1: Start
Step2: Initialize data segment
Step3: Load the given data to registers AL& BL
Step4: Perform addition and Store the result
Step 5: Repeat step 3
Step6: Perform subtraction and Store the result
Step7: Repeat step 3
Step8: Perform multiplication and Store the result
Step9: Repeat step 3
Step10: Perform division and Store the result
Step11: stop.
Physical Address
Label Hex Code Mnemonic operand Comments
Segment : Offset
Address Address
PROGRAM:

ASSUME CS: CODE, DS: DATA

DATA SEGMENT
N1 EQU 04H
N2 EQU 06H
RESULT DB 06H DUP (00)
DATA ENDS

CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX
MOV AL, N1
MOV BL, N2
ADD AL, BL
MOV [RESULT], AL
MOV AL, N1
SUB AL, BL
MOV [RESULT+1], AL
MOV AL, N1
MUL BL
MOV [RESULT+2], AL
MOV [RESULT+3], AH
MOV AL, N1
MOV AH, 00H
DIV BL
MOV [RESULT+4], AL
MOV [RESULT+5], AH
MOV AH, 4CH
INT 21H
CODE ENDS
END START
MANUAL CALCULATIONS:
RESULT:
FLOW CHART:

START

Initialize DS
SI 5000H
AX Data1
BX Data2

AX AX+BX

[SI] AX

AX Data1

AX AX-BX

[SI+2] AX

AX Data1

AX, DX AX*BX
[SI+4] AX
[SI+6] DX

AX Data1
DX 0000H

AX, DX DX AX / BX
[SI+8] AX
[SI+0AH] DX

STOP
Exp No:

Date:
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
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:
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=0

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

CX=0

YES

STOP
Exp No:

Date:
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

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
Physical Address
Mnemonic
Segment Offset Hex
Label Operands Comments
Address Address Code
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:
2. 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
Physical Address
Label Hex Code Mnemonic Comments
Segment Offset
Operands
Address Address
MANUAL CALCULATIONS:

RESULT:
FLOW CHART:

START

Initialize DS
BX ,AX Data
CX (Data-1)

BX BX-1
AX AX*BX
CX CX-1

NO
ZF=1

YES

END
Exp No: Date:

3.ADDITION OF N-BCD NUMBERS USING 8086 MASM


SOFTWARE

ABSTRACT: Assembly language program to perform addition of n-BCD numbers using 8086
MASM software.s
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
Physical Address
Label Hex Code Mnemonic Comments
Segment Offset
Operands
Address Address
PROGRAM:

ASSUME CS:CODE, DS:DATA


DATA SEGMENT
NUM DB 05H,12H,52H,77H,45H,22H
RESULT DW 01H DUP(00)
DATA ENDS

CODE SEGMENT
START:MOV AX,DATA
MOV DS,AX
XOR BX,BX
XOR AX,AX
MOV CL,NUM[BX]
INC BX
MOV AL,NUM[BX]
BACK: INC BX
ADD AL,NUM[BX]
DAA
JNC AGAIN
INC AH
AGAIN:LOOP BACK
MOV [RESULT],AX
MOV AH,4CH
INT 21H
CODE ENDS
END START

RESULT:
FLOW CHART:

START

Initialize DS
BX ,AX Data
CX (Data-1)

BX BX-1
AX AX*BX
CX CX-1

NO
ZF=1

YES

END
Exp No:
Date:
4. FACTORIAL OF GIVEN NUMBER

ABSTRACT: Assembly language program to find factorial of given number


PORT USED: None
REGISTERS USED: AX, CX
ALGORITHM:
Step 1: Start
Step 2: Initialize data segment
Step 3: Initialize AX and CX register values to zero
Step 4: Increment the content of AX register
Step 5: Copy the given number into CL register
Step 6: Compare the contents of CL register with 01H
Step 7: Jump if equal to step 10
Step 8: Multiply the contents of AX register with CL register
Step 9: Decrement CX and jump to step 8 if no zero
Step 10: Store the result to the data memory
Start 11: Stop

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
N DB 02H
FACT DW ?
DATA ENDS
CODE SEGMENT
ORG 1000H
START:
MOV AX, DATA
MOV DS, AX
XOR AX, AX
XOR CX, CX
INC AX
MOV CL, N
CMP CL, O1H
JE RES
BACK: MUL CL
LOOP BACK
RES : MOV [FACT], AX
MOV AH, 4CH
INT 21H
CODE ENDS
END START
Physical Address
Label Hex Code Mnemonic Comments
Segment Offset
Operands
Address Address
MANUAL CALCULATIONS:

RESULT:
FLOW CHART:

START

Initialize DS
CX Count
DX Count

SI Offset list
CX DX

AL [SI]
SI SI+1
Compare AL, [SI]

CF=1
YES

NO
[SI] AL
SI SI-1
[SI] AL

CX CX-1

NO

CX=0

YES

DX DX-1

NO
DX=0

YES

STOP
Exp No:

Date:
5. SORTING OF ‘N’ NUMBERS
ABSTRACT: Assembly language program to do sorting of numbers in a given series
PORT USED: None
REGISTERS USED: CX, DX, AL, SI
ALGORITHM:
Step 1: Start
Step 2: Initialize data segment
Step 3: Load CX register with count
Step 4: Copy the contents from CX to DX
Step 5: Load SI with offset list
Step 6: Copy the contents from DX to CX
Step 7: Move the contents from memory location SI to AL
Step 8: Increment SI
Step 9: Compare AL contents with [SI]
Step 10: Jump to step15 if carry
Step 11: Exchange the contents of AL with [SI]
Step 12: Decrement SI
Step 13: Move the contents from AL to memory location SI
Step 14: Increment SI
Step 15: Decrement CX and jump to step7 if no zero
Step 16: Decrement DX and jump to step5 if no zero
Step 17: Stop

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
LIST DB 56H, 12H, 72H, 32H
COUNT EQU 0003H
DATA ENDS
CODE SEGMENT
ORG 1000H
START:
MOV AX, DATA
MOV DS, AX
MOV CX, COUNT
MOV DX, CX
AGAIN: MOV SI, OFFSET LIST
MOV CX, DX
BACK: MOV AL, [SI]
INC SI
CMP AL, [SI]
JC NEXT
XCHG [SI], AL
DEC SI
Physical Address
Mnemonic
Segment Offset Hex
Label Operands Comments
Address Address Code
MOV [SI], AL
INC SI
NEXT: LOOP BACK
DEC DX

MANUAL CALCULATIONS:

RESULT:
FLOW CHART:

START

AL 13H
AH 00H
Interrupt 10H

AH 00H
Interrupt 10H

Compare AL, ‘q’

YES
ZF=0

NO

BL 0FH
AH 14
Interrupt 10H

STOP
Exp No: Date:

1(A). READING KEYBOARD BUFFERED WITH ECHO


ABSTRACT: To Read the Keyboard Buffered with Echo.
REGISTERS USED: AH, AL, SI
PORTS USED: None.
ALGORITHM:
Step 1: Start.
Step 2: Load the number 13h into AL register
Step 3: Initialize the AH register with 00h
Step 4: Display interrupt
Step 5: Initialize the AH register with 00h
Step 6: Key board Interrupt
Step 7: Compare the data in AL register with character ‘q’
Step 8: If equal to zero go to step 12
Step 9: Move the number 0Fh into BL register
Step 10: Move the number 14 into AH register
Step 11: Keyboard Interrupt
Step 12: Load the number 4C in AH register.
Step 13: Stop
MANUAL CALCLATIONS:
PROGRAM:
ASSUME CS: CODE
CODE SEGMENT
ORG 1000H
START: MOV AH, 00H
MOV Al, 13H
INT 10H
BACK: MOV AH, 00H
INT 16H
CMP AL, ‘q’
JE EXIT
MOV BL, 0FH
MOV AH, 14
INT 10H
JMP BACK
EXIT: MOV AH, 4CH
INT 21H
CODE ENDS
END START
Physical Address
Label Hex Code Mnemonic Comments
Segment Offset
Operands
Address Address
RESULT:
FLOW CHART:

START

AL 13H
AH 00H
Interrupt 10H

AH 00H
Interrupt 10H

Compare AL, ‘q’

YES
ZF=0

NO

BL 0FH
AH 14
Interrupt 10H

STOP
Exp No: Date:
1(b) READING KEYBOARD BUFFERED WITHOUT ECHO

ABSTRACT: To read the string or character from keyboard without ECHO by


using BIOS Commands.
REGISTERS USED: AH, AL, SI
PORTS USED: None.

ALGORITHM:
Step1: Start
Step2: Initialize SI with Offset Result.
Step3: Initialize AH with 00h

Step4: Keyboard Interrupt

Step5: Compare AL with character q.

Step6: Copy the contents AL into SI register.

Step7: If equal to zero go to step 10

Step8: Increment SI.

Step9: Go to step 3 without condition.

Step10: Terminate the program.

Step11: Stop.
MANUAL CALCLATIONS:
PROGRAM:

ASSUME CS: CODE, DS: DATA


DATA SEGMENT
ORG 3000h

RESULT DB 50h DUP (00)


DATA ENDS

CODE SEGMENT
ORG 1000h

START: MOV SI, OFFSET RESULT


BACK: MOV AH, 00h

INT 16h

CMP AL, ‘q’


MOV [SI], AL
JE EXIT
INC SI

JMP BACK

EXIT: MOV AH, 4Ch

INT 21h
CODE ENDS
END START
Physical Address
Label Hex Code Mnemonic Comments
Segment Offset
Operands
Address Address
RESULT:
FLOW CHART:

START

DX Addr. Of CWR

AL 80

[DX] AL

DX Addr. Of Port-A

AL 00

CX FFH

CX=0
NO

YES
Exp No:
Date:
DIGITAL TO ANALOG CONVERTER

GENERATION OF WAVE FORMS:


AIM: program to generate the following wave forms:
• Triangular wave forms
• Saw tooth wave forms
• Square wave

REGISTERS USED: general purpose registers: AL, DX, and CX

PORTS USED: Out (port-B)


CONNECTION: J4 of ESA 86/88 to J1 DAC interface.

ALGORITHM: (FOR TRIANGULAR WAVE):


Step 1: Start
Step 2: Initialize the control word register with all ports as simple I/O mode
Step 3: Load Maximum Amplitude value to CX register.
Step 4: Load 00 to AL register.
Step 5: Initialize the port A address.
Step 6 : Locate the contents of AL to DX register.
Step 7: Increment the value in AL by one.
Step 8: Locate AL contents to DX register.
Step 9: Decrement the value of CX register by one and go to step 6 if CX not equal to zero.
Step 10: Load 00FF to CX register.
Step 11: Decrement the value of AL by one.
Step 12: Locate the contents in AL register to DX register.
Step 13: Decrement the value of CX by one and go to step 12 if CX not equal to zero.
Step 14: Otherwise move to step 3
Step 15: Stop.
Physical Address
Label Hex Code Mnemonic Comments
Segment Offset
Operands
Address Address
RESULT:
Exp No:
Date:

8. Keyboard and Display Interface through Intel 8279

Aim: To Display String Through interfacing 8279

REGISTERS USED: AX ,BX.CX.DX.SI

PORTS USED: command port, data port

CONNECTIONS: 8279 study card P1 to J2 of ESA 86/88 study card adapter.

DESCRIPTION: 8279 study card provides keyboard as well as display section. this section features size
8 digit seven segment displays while the keyboard connections comprises a 4x4 matrix hex a pad and
associated circuitry The options for using shift and control keys during key scanning are also provided.
The interface has 3 connections P1, J1 & J4 to interface the card with ESA 86/88E trainers. Connect the 50
pin FRC connectors P1 to connector J2 to ESA 86/88E study card adapter.

::
MANUAL CALCULATIONS:

ALGORITHM:
Step1: Start

Physical Address
Label Hex Mnemonic Comments
Step2: Load SI with memory location
Code Operands
Step3: Move 10 to AL register
Step4: Load CX with count
Step5: Initialize the command word register i.e., 0FF42
Step6: Locate the contents in AL register to DX register using port out
Step7: Move D3 to AL register
Step8: Locate the contents in AL register to DX register using port out

Step9: Move 90 to AL register


Step10: Locate the contents in AL register to DX register using port out
Step11: Initialize the data register address i.e., 0FF40
Step12: Move the content SI to AL register
Step13: Locate the contents in AL register to DX register using port out
Step14: Create Display

Step15: Increment the value of SI

Step16: Decrement the counter and go to step 11 until CX=0

Step17: Jump to location step 5

ALGORITHM FOR DELAY:

Step1: Load DX register with 0FFFFh

Step2: Decrement DX

Step3: Repeat step 2 till DX is zero

Step4: Return to main program


Segment Offset
Address Address

CODE TABLE

PROGRAM:
START: MOV SI, 2000H
MOV CX, 0008H
MOV AL, 10
MOV DX, 00F42
OUT DX,AL
MOV AL,0D3
OUT DX,AL
MOV AL,90
OUT DX,AL
NEXT: MOV DX,0FF40
MOV AL,[SI]
OUT DX,AL
CALL DELAY
INC SI
LOOP NEXT
JMP START
DELAY PROGRAM:
MOV DX.0FFFFH
BACK: DEC DX
JNZ BACK
RET

INPUT DATA:

SEGMENT ADDRESS OFFSET ADDRESS DATA INPUT

2000 00 77 F3 60 87 E6 77

RESULT:
FLOW CHART:

START

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:
9.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

RESULT:
FLOW CHART:

START

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=1 YES

[DPTR] R2

STOP
Exp No: Date:
10. 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
MANUAL CALCULATIONS:
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
CODE TABLE:

Memory Label Hex Mnemonic Comments


Address Code Operands
RESULT:
Exp No: Date:

11. LED INTERFACING

#include <reg51.h>

sbit LED = P2^0; // Bling the single LED connected to P2.0

void DELAY(void);

void main(void)

while(1)

LED = 1; /* Turn ON the LED connected to P2.0 */

DELAY();

LED = 0; /* Turn OFF the LED connected to P2.0 */

DELAY();

void DELAY(void)

unsigned int i,j;

for(i=0;i<10;i++)

for(j=0;j<10000;j++);

}
RESULT:
Exp No: Date:

2.
and LEDs

#include<reg52.h>

sbit LED_pin = P2^0; //Defining LED PIN

sbit switch_pin = P0^0; //Defining Switch PIN

void Delay(int); //Function prototype declaration

void main (void)

switch_pin = 1; // Making Switch PIN input

LED_pin=1; //LED off initially

while(1) //infinite loop

if(switch_pin == 0 ) //If switch pressed

LED_pin = 0; //LED ON

Delay(2000); //Delay

LED_pin = 1; //LED OFF

void Delay(int k)

int j;

int i;
for(i=0;i<k;i++)

for(j=0;j<100;j++)

RESULT:
Exp No: Date:

12. STEPPER MOTOR INTERFACE


ABSTRACT: C language program to do stepper motor interface
PROGRAM:
#INCLUDE<STDIO.H>
#INCLUDE<REG51.H>

CHAR XDATA PORT _AT_ 0XE803;


CHAR XDATA PORTA _AT_ 0XE800;
CHAR IDATA ACC _AT_ 0X30;

DELAY() //DELAY BETWEEN THE ROTATION OF THE STEPPER MOTOR


{
INT J;
FOR(J = 0;J < 800; J++)
{}
}
VOID MAIN()
{
PORT = 0X80; //CONFIGURE ALL THE PORTS OF 8255 AS OUTPUT PORT
WHILE(1)
{
ACC = 0X11;
PORTA = ACC;
DELAY();
ACC = 0X22;
PORTA = ACC;
DELAY();
ACC = 0X44;
PORTA = ACC;
DELAY();
ACC = 0X88
PORTA = ACC;
DELAY();
}
}.

RESULT:

You might also like