Sunteți pe pagina 1din 12

DIGITAL ASSIGNMENT-1 (LAB)

Name: Atri Acharya


Registration number: 17BEE0070
Programme Name & Branch: B.Tech.(EEE)
Slot: L53+L54
Course Code: EEE4001
Course Title: Microprocessor and Microcontroller

CODE 1: Write the 8051 assembly language program to sort the following set of marks scored by

ten students in Microprocessor and Microcontroller course in descending order.

RAM Address (Hex) 40 41 42 43 44 45 46 47 48 49

Marks (in decimal) 67 78 34 94 56 85 47 32 12 08

(From CAT 1 paper)

org 0h

mov 40h, #0

mov 41h, #1

mov 42h, #2

mov 43h, #3

mov 44h, #4

mov 45h, #5

mov 46h, #6

mov 47h, #7

mov 48h, #8

mov 49h, #9
mov r2, #9

back: mov r0, #40h

mov r1, #9h

mov a, @r0

back1: inc r0

mov b, @r0

cjne a,b,target1

target1: jnc target2

mov @r0,a

dec r0

mov @r0,b

inc r0

sjmp target3

target2: mov a,b

target3: djnz r1, back1

djnz r2, back

end
CODE 2: Write a program with three subroutines to (a) transfer the following data from on-chip
ROM to RAM locations starting at 30H, (b) add them and save the result in 70H, and (c) find the
average of the data and store it in R7. Notice that the data is stored in a code space of on-chip
ROM.(from CAT1 paper)

org 0H
lcall romtoram

lcall addition

lcall average

here: sjmp here

romtoram:

mov DPTR, #mydata

mov r2, #9

mov r0, #30H

clr a

inc dptr

inc r0

djnz r2, back

ret

addition:

mov r0, #30H

mov r2, #9

mov A, #0

back1: add a, @r0

inc r0

djnz r2, back1

mov 70H, a

ret

average:

mov a, 70H

mov b, #9

div ab

mov r7, a

ret

org 250H

mydata: DB 3,6,9,7,6,4,2,8

end
(a)

(b)
(c)

CODE 3: Assume that register A has packed BCD. Write a program to convert packed BCD to two
ASCII numbers and place them in R2 and R6. (from class notes and ppt)

MOV A, #29H

MOV R2, A

ANL A, #0FH

ORL A, #30H

MOV R6, A

MOV A, R2

ANL A, #0F0H

RR A

RR A

RR A
RR A

ORL A, #30H

MOV R2, A
CODE 4: Write 8051 assembly language program to find the total number of high bits in a data
item stored in 45H. Finally store the result in R7. (from CAT1 paper)

org 0H

clr c

mov r0, #8

mov r7, #0

mov a, 45h

back: rrc a

jnc next

inc r7

next: djnz r0, back

end
CODE 5: Ten hex numbers are stored in RAM locations 50H onwards. Write a program to find the
biggest number in the set. The biggest number should finally be saved in 60H.(From class notes)

MOV R0, #50H

MOV R1, #10


MOV B, 0

BACK: MOV A, @R0

CJNE A, B, LOOP

LOOP: JC LOOP1

MOV B, A

INC R0

DJNZ R1, BACK

SJMP NEXT

LOOP1: INC R0

DJNZ R1, BACK

NEXT: MOV A,B

MOV 60H, A

END
CODE 6: Write a program to transfer value 41H serially (one bit at a time) via pin P2.1. Put two
highs at the start and end of the data. Send the byte LSB first.

MOV A, #41H

SETB P2.1

SETB P2.1

MOV R5, #8

HERE: RRC A

MOV P2.1,C

DJNZ R5, HERE

SETB P2.1

SETB P2.1

S-ar putea să vă placă și