Professional Documents
Culture Documents
09 P3, P4 Cumulative Sum
09 P3, P4 Cumulative Sum
MICROCONTROLLER
&
EMBEDDED
SYSTEMS
LECTURE NOTES - 09
SUBMITTED BY :
Shivam Gulati -15476
Rishabh Gupta – 15477
OVERVIEW OF ADD INSTRUCTION
(To understand Rn, Direct, @Ri, #Data)
ADD A,Rn
A = A + value of (Rn)
A= 03H + R2 = 05H
Result: 03H+05H=08H
A=08H R2 = 05H
ADD A,direct
A= 0AH
ADD A,@Ri
Add the value present in memory where memory address is present in either R0 or R1 with Accumulator
content.
-- 64H
Ex. ADD A,@R0
07H 63H
A= 03H R0 = 62H 06H 62H
-- 61H
@R0
-------------------------------------------------------------------------------------------------------------
ACALL: ACALL unconditionally calls a subroutine at the indicated code address. ACALL pushes the
address of the instruction that follows ACALL onto the stack, least-significant-byte first, most-significant-
byte second. The Program Counter is then updated so that program execution continues at the
indicated address.
The new value for the Program Counter is calculated by replacing the least-significant-byte of the
Program Counter with the second byte of the ACALL instruction, and replacing bits 0-2 of the most-
significant-byte of the Program Counter with 3 bits that indicate the page. Bits 3-7 of the most-
significant-byte of the Program Counter remain unchaged.
Since only 11 bits of the Program Counter are affected by ACALL, calls may only be made to routines
located within the same 2k block as the first byte that follows ACALL.
AJMP: AJMP unconditionally jumps to the indicated code address. The new value for the Program
Counter is calculated by replacing the least-significant-byte of the Program Counter with the second byte
of the AJMP instruction, and replacing bits 0-2 of the most-significant-byte of the Program Counter with
3 bits that indicate the page of the byte following the AJMP instruction. Bits 3-7 of the most-significant-
byte of the Program Counter remain unchaged.
Since only 11 bits of the Program Counter are affected by AJMP, jumps may only be made to code
located within the same 2k block as the first byte that follows AJMP.
EXAMPLE: If the label THERE represents an instruction at address 0F46H and the instruction AJMP
THERE is in memory at locations 0900H and 0901H, the assembler will encode the instruction as
-- --
0100 0110 2nd byte (A7 - A0)
--
The underlined bits are the low-order 11 bits of the destination address,
0F46H = 00001 111 0100 0110 B. The upper five bits in the program counter will not change when this
instruction executes.
Note that both the AJMP instruction and the destination are within the 2K page bounded by 0800H and
0FFFH, and therefore have the upper five address bits in common.
By default all the ports i.e, port 0, port 1, port 2, port 3 of the 8051 microcontroller are output ports.
To make entire pins of ports as input pins write ‘1’ to all the pins like this:
MOV P0, #0FFH (to make all bits of port 0 as input port).
To make individual pin of that port as input pin set individually the bits/pin.
SETB P0.1 (to make 1st bit of port 0 as input pin).
PROGRAM 1)
To continuously read number from Port 0 and cumulatively add it.
Index PORT 2
Put the cumulative sum at port 1 and index (how many no’s added together) at port 2.
CODE:-
The use of this program is in Checksum. A checksum is a small-sized datum derived from a block
of digital data for the purpose of detecting errors which may have been introduced during
its transmission or storage. It is usually applied to an installation file after it is received from the
download server. By themselves, checksums are often used to verify data integrity but are not relied
upon to verify data authenticity.
PROGRAM 2)
continuously read number from Port 0 and cumulatively add only those values which are divisible by
3.
Put the cumulative sum at port 1 and index (how many no’s added together) at port 2.
CODE:-