Professional Documents
Culture Documents
Microprocessors and Microcontrollers LAB: Aditya Engineering College (A)
Microprocessors and Microcontrollers LAB: Aditya Engineering College (A)
Regulations : AR 17
Course Code : 171EC6L07
Semester : VI Sem
Name :
Roll No :
Section :
MARKS AND
S. NO NAME OF THE EXPERIMENT DATE SIGNATURE
6 AVERAGE OF N-NUMBERS
s
AVERAGE MARKS
Roll Number
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:
MERITS OF MASM:
Path setting
Suppose it display path as Z:\>
Then type MOUNT C C:\ MASM then drive c is mounted as local directory C:\MASM\
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:
INPUT I port
QUIT Q
REGISTER R [register]
UNASSEMBLE U [range]
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:
MANUAL CALCULATIONS:
RESULT:
FLOW CHART:
START
Initialize DS
Initialize Data1,
Data2
CX COUNT
BX COUNT-1
AL Data1 [BX]
Data memory AL
BX BX-1
CX CX-1
NO
CX=
YES
CX COUNT
BX COUNT-1
AL Data1 [BX]
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
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.
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:
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:
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:
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:
RESULT: