Вы находитесь на странице: 1из 3

Microcontroller Lab

VI Sem. B.Tech. Biomedical Engineering

Expt No. 2

Arithmetic and Logical operations

1. Write a program to find sum of 5bytes available in RAM locations 40h to 45h. Store the
result in Reg A (low byte) and R7 (high byte).
ORG 0000H
AJMP START
START:

MOV R0, #50h ; load pointer


MOV R2, #06h ; load counter
CLR A
; initial sum = 0
REPEAT: ADD A, @R0
; add the byte pointed by R0
JNC NEXT
; if Cy = 0 dont accumulate
INC R7
; accumulate Cy if any
NEXT:
INC R0
; increment pointer
DJNZ R2, REPEAT ; repeat until R2 is zero
END
; end of the program

2. Write program to add two 16-bit numbers 2E5Fh and A3B4h. Store the sum in R7 and R6.
ORG 0000h
AJMP START
START:

CLR C
; clear the carry
MOV A, # 5Fh ; load the low byte of 1st data into A
ADD A, #0B4h ; add the low byte of 2nd data
MOV R6, A
; save the low byte of sum in R6
MOV A, #2Eh
; load the high byte of 1st data in A
ADDC A, #0A3h ; add the high byte of 2nd data with carry
MOV R7, A
; save the result in R7
HERE:
SJMP HERE
; infinite loop to stop execution
END
3. Write program to perform multiplication of two numbers. Two 8- bit numbers are available
in memory location 1000h and 1001h. Copy the product into 1002h and 1003h.
ORG 0000H
AJMP START
START:

MOV DPTR, # 1001H


MOVX A, @DPTR
MOV 0F0H, A
MOV DPTR, #1000H
MOVX A, @DPTR
MUL AB
MOV DPTR, #1002H
MOVX @DPTR, A
INC DPTR
MOV A, B

; data in 1000h & 1001h data memory location.

; perform multiplication
; copy product to data memory 1002h & 1003h

1
Department of Biomedical Engineering, Manipal Institute of Technology, Manipal 576 104

Microcontroller Lab

VI Sem. B.Tech. Biomedical Engineering

MOVX @DPTR, A
END
4. Perform division of two numbers. The numbers are available in 2000h and 2001h data
memory. After division operation, store the result in 200Ah and 200Bh.

START:

HERE:

MOV DPTR, #2001h


MOVX A, @DPTR
MOV B, A
MOV DPTR, #2000h
MOVX A, @DPTR
DIV AB
MOV DPTR, #200Ah
MOVX @DPTR, A
INC DPTR
MOV A, 0F0h
MOVX @DPTR, A
SJMP HERE

; keep data in 2000h and 2001h


; divisor in B
; dividend in A
; perform division operation
; store quotient

; store remainder
; infinite loop

5. Perform the logical AND operation of two 8-bit data available in R0 and R1 and output the
result to port2.
START:

HERE:

MOV R1, #23h


MOV R0,#0 AAh
MOV A, R0
ANL A, R1
MOV P2, A
SJMP HERE

; Store the data in R1 and R0


; copy one data into A
; A= A AND R1
; copy A into P2

Similarly perform OR and XOR operation.


6. Perform NOT operation on a data and output the result to port1.
START:
UP:
DLY:

MOV R0, #0FFh


MOV A, #55h
MOV P1, A
NOP
DJNZ R0, DLY
CPL A
SJMP UP

; Delay count
; data to be complemented
; send thedata to port1
; insert delay
; complement the data and send it port1

EXERCISES
1. Find the difference of two 2-digit BCD numbers available in R1 and R2 and store the
result in location 2000h.
2. Add two 32-bit numbers available in memory locations starting from 3050h and store
the result from memory location 3080h.
3. Multiply two 16-bit hex numbers and store the product.

2
Department of Biomedical Engineering, Manipal Institute of Technology, Manipal 576 104

Microcontroller Lab

VI Sem. B.Tech. Biomedical Engineering

PRACTICE PROGRAMS
1. Find the difference of two 16 bit numbers available in memory location XX50h and
XX52h and store the result in XX5Ah.
2. Add two 4-digit BCD numbers available in memory external data memory and store the
result in internal RAM location 00h.
3. Multiply two 2-digit BCD numbers.
4. Divide two 2-digit BCD numbers available in memory locations and store the quotient
and remainder.
5. Perform multiplication by shift and add method.

3
Department of Biomedical Engineering, Manipal Institute of Technology, Manipal 576 104

Вам также может понравиться