0% found this document useful (0 votes)
30 views

8051 programming

Uploaded by

u2203162
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

8051 programming

Uploaded by

u2203162
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Q: Find out how many equal bytes between two memory blocks 15h to 25h and 30h

to 40h.

Mov r7, #0Ah ; initialize counter by 10d

Mov r0, #15h ; get initial location of block1

Mov r1, #30h ; get initial location of block2

Mov r6, #00h ; equal byte counter. Starts from zero

Nxt: Mov a, @r0 ; get content of block 1 in acc

Mov b, a ; move it to B

Mov a, @r1 ; get content of block 2 in acc

Cjne a, b, nomatch ; compare both if equal

Inc r6 ; increment the counter

Nomatch: inc r0 ; otherwise go for second number

Inc r1

djnz r7, nxt ; decrease r7. if zero then over otherwise move next

Q: Write a assembly language program to continuously scan port P0. If data is other

then FFh write a subroutine that will multiply it with 10d and send it to port P1

Again: Mov p0, #0ffh ; initialize port P0 as input port

Loop: Mov a, p0 ; get the data in acc

Cjne a, #0FFh, dat ; compare it with FFh

Sjmp loop ; if same keep looping

Dat: acall multi; if different call subroutine

Sjmp again ; again start polling

Multi

Mov b,#10d ; load 10d in register B

Mul ab ; multiply it with received data


Mov p1, a ; send the result to P1
Ret ;return to main program

Q: Write a 8051 assembly language program to transfer the block of data from 20h to

30h to external location 1020h to 1030h.

Mov r7, #0Ah ; initialize counter by 10d

Mov r0, #20h ; get initial source location

Mov dptr, #1020h ; get initial destination location

Nxt: Mov a, @r0 ; get first content in acc

Movx @dptr, a ; move it to external location

Inc r0 ; increment source location

Inc dptr ; increase destination location

Djnz r7, nxt ; decrease r7. if zero then over otherwise move next

Q: Write an 8051 assembly language program to divide the content of r0 by r1. Store

the result in r2 (answer) and r3 (reminder).

Mov a, r0 ; get the content of r0 and r1

Mov b, r1 ; in register A and B

Div ab ; divide A by B

Mov r2, a ; store result in r2

Mov r3, b ; and reminder in r3

Q: Write program to copy a block of 8 bytes of data to RAM locations starting at 50H from RAM

locations 30H.

MOV R0, #30H ; source pointer

MOV R1, #50H ; destination pointer

MOV R3, #8 ; counter


RETURN: MOV A, @R0 ; get a byte from source

MOV @Rl, A ; copy it to destination

INC R0 ; increment source pointer

INC R1 ; increment destination pointer

DJNZ R3, RETURN ; keep doing it for all eight bytes

Q: Write a program to determine the largest number stored from 2000h onwards (10 locations)

ORG 00H

MOV DPTR,#2000H;initialize pointer to memory where numbers are stored

MOV R0,#0AH ; initialize counter

MOV R3,#00H ;maximum=0

AGAIN: MOV A,@DPTR ;get the number from memory

CJNE A,R3,NE ;compare number with maximum number

AJMP SKIP ;if equal go to SKIP

NE: JC SKIP ;if not equal check for carry, if carry go to skip

MOV R3,A ;otherwise maximum=[[DPTR]]

SKIP: INC DPTR ; Increment memory pointer

DJNZ R0,AGAIN ; Decrement count, if count=0 stop otherwise go to AGAIN

END

Q: Add the contents of RAM locations 60H, 61H and 62H. Store the result in RAM locations 41H
(MSB) and 40H (LSB).

MOV 41H, #00H ; Clear the RAM location where MSB has to be stored.

MOV A, 60H ; Move first number to accumulator.

ADD A, 61H ; Add the second number.

MOV R0, A ; Store result in R0.

MOV A, 00H ; Clear accumulator.

ADDC A, 41H ; Add A + CY + Contents of 41.


; Now A = 00H; 41H contains 00H.

; Therefore we essentially get the status of

; CY flag into accumulator.

MOV 41H, A ; Move it to location 41H.

MOV A, R0 ; Get back result of first addition into accumulator.

ADD A, 62H ; Add third byte. Result (LSB) is in accumulator.

MOV 40H, A ; Move result (LSB) to location 40H

MOV A, 00H ; Clear accumulator.

ADDC A, 41H ; Add present carry with previous carry in 41H.

MOV 41H, A ; Move MSB to 4lH.

You might also like