Escolar Documentos
Profissional Documentos
Cultura Documentos
ANS:
2.TEN 8 BITS NUMBERS ARE STORED IN INTERNAL DATA MEMORY FROM LOCATION 50H.WRITE
ASSEMBLEY LEVEL PROGRAM TO INCREMENT THE DATA.
ANS:
ASSUME THAT TEN 8 BIT NUMBERS ARE STORED FROM THE INTERNAL LOCATION 50H,HENCE R0,R1
MUST BE USED AS POINTER.
PROGRAM:
ORG 0000H ;SET THE PROGRAM COUNTER 0000H
MOV R0,#50H ;LOAD POINTER ,R0=50H
MOV R3,#0AH ;LOAD THE COUNTER R3=0AH
LOOP1: INC @R0 ;INCREMENT CONTENTS OF INTERNAL DATA RAM POINTED BY R0
INC R0 ;INCREMENT POINTER
DJNZ R3,LOOP1 ;REPEAT UNTILL R3 IS ZERO
END
3. WRITE ALP TO MULTIPLY 16 BIT UNSIGNED NUMBERS.
ANS:
4.WRITE ALP TO COUNT THE NUMBER OF 1S AND 0S OF 8 BIT DATA STORED IN LOCATION 6000H
PROGRAM:
ORG 0000H ;SET PROGRAM 0000H
MOV DPTR,#6000H ;COPY ADDRESS 6000H TO DPTR
MOVC A,@A+DPTR ; COPY NUMBER TO A
MOV R0,#08 ;COPY 08 IN R0
MOV R2,#00 ;COPY 00 IN R2
MOV R3,#00 ;COY 00 IN R3
CLR C ;CLEAR CARRY FLAG
BACK: RLC A ;ROTATE THE CARRY FLAG OF A THROUGH CARRY FLAG
JC NEXT ;IF CF=1 BRANCH TO NEXT
INC R2 ;IF CF=0,INCREMENT R2
AJMP NEXT2
NEXT: INC R3 ;IF CF = 1, INCREMENT R3
NEXT2:DJNZ R0,BACK ;REPEAT UNTIL R0 IS ZERO
ORG 6000H
DB 34H
END
5. an 8-bit word is stored in location 1000h of external data memory. Write assembly level program to
justify code word is valid if three MSB are zero it contains two ones in the remaining 5 bits. If code word
is valid store FF else store 00 in 1001h.
Ans) program
INC DPTR
BACK: RRC A
JNC LOOP2
INC R3
MOV A,R3
CJNE A, #02H, LOOP1 ; IF SECOND CONDITION FAILS BRANCH TO LOOP1 AND STORE 00H
DEC R4
MOVX @DPTR, A
ORG 1000H
DB 14H
END
6.WRITE ASSEMBLY LEVEL PROGRAM TO FIND THE SMALLEST NUMBER OF AN ARRAY OF N 8 BIT
UNSIGNED NUMBERS ( N IS AN 8 BIT NUMBER) THE STARTING ADDRESS OF THE ARRAY IS AT 2000H AND
STORES THE RESULT IN 2500H
ANS) PROGRAM
MOV DPTR, #2000H ; STORE THE STARTING ADDRESS OF THE ARRAY IN DPTR
MOV A,R1
END
7. N 8 BIT NUMBERS ARE STORED IN EXTERNAL DATA MEMORY WRITE ASSEMBLY LEVEL PROGRAM TO
ARRANGE THEM IN ASCENDING ORDER.
ANS) PROGRAM
LOOPS: MOV DPTR, #2000H ; STORE THE STARTING ADDRESS OF THE ARRAY IN DPTR
MOV R5,R4
MOV A,R1
MOV A, TEMP
DEC DPL
MOVX @DPTR,A
INC DPL
END
8. N 8 BIT NUMBERS ARE STORED IN EXTERNAL DATA MEMORY WRITE ASSEMBLY LEVEL PROGRAM TO
ARRANGE THEM IN DESCENDING ORDER
ANS) PROGRAM
LOOPS: MOV R0, #41H ; STORE THE STARTING ADDRESS OF THE ARRAY IN R0
MOV R5,R4
INC R0 ; INCREMENT R0
MOV A,R1
MOV A, TEMP
DEC R0
MOV @R0,A
INC R0
END
9. Write Assembly level program to convert BCD number stored in location 6000H to binary and store
the result in 5100H.
ORG 000H ; set the program counter 0000H
MOV DPTR,#6000H ; store the address of the memory in DPTR
MOVC A,@A+DPTR ; copy the contents pointed by DPTR to A
ANL A,#0FH ; mark upper nibble of A
MOV R1,A ; copy contents of A in R1
MOVX A,@DPTR ; copy contents of memory pointed by DPTR to A
ANL A,#0F0H ; mask lower nibble of A
SWAP A ; exchange upper and lower nibble of A
MOV B,A
MOV A,#0AH
MUL AB ; multiply upper nibble with 10 (0AH)
ADD A,R1 ; add lower nibble of A with result
MOV DPTR,#5100H
MOVX @DPTR,A ; store result in 5100H
ORG 6000H
DB 12
END
10.Write Assembly level program to convert an ASCII number stored in location 7000H of external data
RAM to hex. Store the result in 5000H.
11.Write Assembly level program to convert hex number stored in location 7000H of external data RAM to
ASCII. store the result in 5000H.
ORG 0000H
MOV DPTR,#7000H
MOV A,#01D
MOVX @DPTR,A
INC DPTR
MOV A,#02D
MOVX @DPTR,A
MOV DPTR,#7000H
MOVX A,@DPTR
ANL A,#00001111B
MOV B,A
INC DPTR
MOVX A,@DPTR
SWAP A
ANL A,#11110000B
ORL A,B
MOV DPTR,#5000H
MOVX @DPTR,A
END
12.Write Assembly level program to convert an 8 bit BCD number stored in location 7000H of external
data RAM to packed BCD. Store the result in location 5000H.
13 13.Write Assembly level program to convert binary code stored in location 6000H to gray code. Store
the result in location 5000H.
15. Write Assembly level program to compute 1+3+. +N (say 15) and save the sum at 70H.
16. Write Assembly level program to compute 2+4+. +N (say 16) and save the sum at 70H.
ORG 0000H ;SET PROGRAM COUNTER 0000H
N EQU 15
MOV R0, #00 ;CLEAR R0
CLR A;CLEAR A
again :INC R0
INC R0 ;INCREMENT R0
ADD A,R0 ;ADD THE CONTENTS OF R0 WITH CONTENTS OF A
CJNE R0, #N, again ;LOOP UNTIL COUNTER,R0=N
MOV 70H,A ;SAVE THE RESULT IN LOCATION 70H
END
VIVA
2 Indicate which mode and which timer are selected for each of the following.
(a) MOV TMOD, #01H (b) MOV TMOD, #20H (c) MOV TMOD, #15H
(a)00000001=timer o mode 1;(b)00100000=timer 1 mode 2;(c)00010101=timer 1 mode 1 and timer 2 as
counter
3 Find the timers clock frequency and its period for various 8051-based system, with the crystal
frequency 11.0592 MHz when C/T bit of TMOD is 0.
5 Calculate the amount of time delay in the DELAY subroutine generated by the timer. Assume XTAL =
11.0592 MHz
The timer works with a clock frequency of 1/12 of the XTAL frequency; therefore, we have 11.0592 MHz / 12 =
921.6 kHz as the timer frequency. As a result, each clock has a period of T = 1 / 921.6 kHz = 1.085 (is. In other
words, Timer 0 counts up each 1.085 us resulting in delay = number of counts x 1.085 us.
The number of counts for the rollover is FFFFH FFF2H = ODH (13 decimal). However, we add one to 13
because of the extra clock needed when it rolls over from FFFF to 0 and raises the TF flag. This gives 14 x
1.085 us = 15.19 us for half the pulse. For the entire period T = 2 x 15.19 (as = 30.38 (is gives us the time
delay generated by the timer
6 Calculate the frequency of the square wave generated on pin P1.5.
7 The following program generates a square wave on P1.5 continuously using timer 1 for a time
delay. Find the frequency of the square wave if XTAL = 11.0592 MHz In your calculation, do not
include the overhead due to Instructions in the loop.
1.
(FFFF-B83E + 1) = 47C2H= 18370 in decimal and 18370 x 1.085 fis= 19.93145
ms.
12 Assuming that we are programming the timers for mode 2, find the value (in hex) loaded into TH for
each of the following cases
13 With XTAL = 11.0592 MHz, find the TH1 value needed to have the following baud rates. (a) 9600 (b)
2400 (c) 1200.
14 Explain bits of SMOD register.
15 Assume that XTAL = 11.0592 MHz for the following program, state (a) what this program does, (b)
compute the frequency used by timer 1 to set the baud rate, and (c) find the baud rate of the data
transfer.
16 Find the TH1 value (in both decimal and hex) to set the baud rate to each of the following.
(a) 9600 (b) 4800 if SMOD = 1 Assume that XTAL 11.0592 MHz.
Solution:
With XTAL = 11.0592 MHz and SMOD = 1, we have Tinier 1 frequency = 57,600 Hz.
29 With XTAL = 11.0592 MHz, find the TH1 value needed to have the following baud rates. (a) 9600 (b)
2400 (c) 1200.