MC Lab - EXP3

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

Microcontroller Lab

Expt No. 3
1.

VI Sem. B.Tech. Biomedical Engineering

Memory Array Handling and Code Conversion

Find the sum of ten 2-digit BCD numbers available in memory locations XX40 to
XX49. Store the result in R0, R1 and in memory locations XX50h and XX51H.

ORG 0000H
AJMP START
START:

UP:

DOWN:

HERE:

2.

MOV R1, #00H ; CY reg.


MOV R3, #10
; Length of the array
MOV R0, #00H ; Sum reg.
MOV DPTR, #XX40H; Starting memory location
MOVX A, @DPTR ; Decimal addition
ADD A, R0
DA A
MOV R0, A
JNC DOWN
MOV A,#00H
; accumulate carry decimally
ADDC A, R1
DA A
MOV R1, A
INC DPTR
DJNZ R3, UP
MOV A, R0
MOV DPTR, #XX50H ; copy the result into memory
MOVX @DPTR, A
INC DPTR
MOV A, R1
MOVX @DPTR, A
SJMP HERE
; stop execution
END

Find the largest number of a memory array. Array begins at memory location 40H,
the length of the array is in memory location 30H. Store the result in memory location
XX60H.
ORG 0000H
AJMP START

START:

UP:

MOV R0, #30H


MOV A, @R0
MOV R7, A
DEC R7
MOV R1, #40H
MOV A, @R1
INC R1
CLR C
MOV B,A
SUBB A, @R1

;length of array
; n-1 comparisions

; compare A with content of next memory location


1

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

Microcontroller Lab

DOWN1:
DOWN:

HERE:

3.

JNC DOWN1
MOV A, @R1
SJMP DOWN
MOV A,B
DJNZ R7, UP
MOV DPTR, #0060H
MOVX @DPTR, A
SJMP HERE
END

VI Sem. B.Tech. Biomedical Engineering

; if a smaller copy larger data into A

; go to next memory location


; store the largest number
; terminate program

Transfer the contents of memory locations 50H to 59H in the same sequence to a
memory array which begins at 70H.
ORG 0000H
AJMP START

START:

UP:

HERE:

1.

MOV R2, #0AH


; length of the array
MOV R0, #50H ; stating address of source array
MOV R1, #70H ; starting address of destination array
MOV A, @R0
; transfer the elements of array
MOV @R1, A
INC R0
INC R1
DJNZ R2, UP
; repeat the transfer for rest of the elements
SJMP HERE
; terminate the program execution
END

Arrange elements of memory array in ascending order.


ORG 0000H
AJMP START

START:

MOV A, #nn
DEC A
MOV 30H,A
NXT_PSS: MOV R7, 30H
MOV R6, 30H
MOV R0, #50H
NXT_CMP: MOV A, @R0
MOV R3, A
INC R0
MOV 0F0H, @R0
CLR C
SUBB A,B
JC DOWN
MOV A, R3
MOV @R0,A
DEC R0
MOV @R0,0F0H

; no. of elements
; pass and comparision counter
;
; Starting location of internal data memory

; compare with next element for less than

; if next elemnt is smaller than


; prev. element then exchange elemnts

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

Microcontroller Lab

DOWN:
HERE:

2.

VI Sem. B.Tech. Biomedical Engineering

INC R0
DJNZ R6, NXT_CMP ;continue with remaining elements
DJNZ 30H, NXT_PSS
SJMP HERE
; stop executing
END

Convert an 8-bit hexadecimal number into decimal.


ORG 0000H
AJMP START

START:

HERE:

3.

MOV A, #0ABH
MOV 0F0H, #10
DIV AB
MOV R7, 0F0H
MOV B, #10
DIV AB
MOV R6, 0F0H
MOV R5, A
SJMP HERE
END

; hexadecimal no. to be converted

; divide the number by 10

; unpacked decimal number in R7, R6 and R5

Convert a 2-digit BCD number available in memory location XX50 into hexadecimal
and store the hexadecimal number in next memory location.
ORG 0000h
AJMP START

START:

HERE:

MOV DPTR, #XX50H


MOVX A, @DPTR
ANL A, #0FH
MOV R0, A
MOVX A, @DPTR
ANL A, #0F0H
CLR C
RRC A
RRC A
RRC A
RRC A
RLC A
MOV 0F0H, A
RLC A
RLC A
ADD A, B
ADD A, R0
INC DPTR
MOVX @DPTR, A
SJMP HERE
END

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

Microcontroller Lab

4.

VI Sem. B.Tech. Biomedical Engineering

Convert a single digit data available in memory location XX50h into ASCII code and
store the ASCII code in the next location.
ORG 0000H
AJMP START

START:

DOWN:

HERE:

MOV DPTR, #XX50H


MOVX A, @DPTR
CLR C
MOV B,A
SUBB A, #0AH
MOV A,B
JC DOWN
ADD A, #07H
ADD A, #30H
INC DPTR
MOVX @DPTR, A
SJMP HERE
END

EXERCISES
1. Find the sum of ten 16 bit hexadecimal numbers available in memory starting from
location XX10h. store the result in XX50h onwards.
2. Find the number of occurrences of data 2Ah in a memory array. The last element of
the array is 3Ah. The array begins at XX30h. Store the result in memory location
XX80h.
3. Transfer ten elements of an array starting at location XX40h in external data memory to
a location XX45 in the same memory.
4. Convert a 2-digit hexadecimal number into BCD number.
PRACTICE PROGRAMS
1. Find the sum of odd and even numbers available in a memory array and store the result
in memory locations.
2. Convert a 2-digit BCD number into ASCII code.
3. Convert binary number into Gray code.
4. Convert Gray code into binary number.
5. Reverse the elements of an array.
6. Read a single digit hexadecimal number from the memory location and generate 7segment code for the number read and send the code to port1. Assume common anode
seven segment display.

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

You might also like