You are on page 1of 21

1.WRITE A ROGRAM TO COMPUTE 1+2+3+.

+N AND SAVE THE SUM AT 70H

ANS:

ORG 0000H ;SET PROGRAM COUNTER 0000H


N EQU 15
MOV R0,#00 ;CLEAR R0
CLR A ;CLEAR A
AGAIN : INC R0 ;INCREMENT R0
ADD A,R0 ;ADD THE CONTET OF R0 WID CONTENT OF A
CJNE R0,#N,AGAIN ;LOOP UNTIL COUNTER,R0=N
MOV 70H,A ;SAVE THE RESULT IN LOCATION 70H
END

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:

ORG 0000H ;SET PROGRAM COUNTER 0000H


MOV A,50H ;PLACE LSB OF MULTIPLIER IN A
MOV B,52H ;PLACE LSB OF MULTIPLICAND IN B
MUL AB ;COMPUTE PRODUCT
MOV 60H,A ;STORE LSB OF THE RESULT
MOV 61H,B ;STORE MSB OF THE RESULT
MOV A,51H ;PLACE MSB OF MULTIPLIER IN A
MOV B,53H ;PLACE MSB OF MULTIPLICAND IN B
MUL AB ;COMPUTE PRODUCT
MOV 62H,A ;STORE LSB OF THE RESULT
MOV 63H,B ;STORE MSB OF THE RESULT
MOV A,51H ;PLACE MSB OF MULTIPLIER IN A
MOV B,52H ;PLACE LSB OF MULTIPLICAND IN A
MUL AB ;COMPUTE PRODUCT
ADD A,61H ;ADD THE RESULT TO P+1
MOV 61H,A ;STORE LSB TO RESULT
MOV A,B
ADDC A,62H ;ADD THE RESULT TO P+2
MOV 62H,A
MOV A , 63H
ADDC A,#0H;
MOV 63H,A
MOV A,50H
MOV B,53H
MUL AB
ADD A,61H
MOV 61H,A
MOV A,B
ADDC A,62H ;ADD RESULT TO P+2
MOV 62H,A ;STORE RESULT IN P+2
MOV A,63H
ADDC A,#0H
MOV 63H,A
END

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

ORG 000H ; SET PROGRAM COUNTER 000H

MOV DPTR, #1000H ; COPY ADDRESS 1000H TO DPTR

MOVC A, @A+DPTR ; COPY NUMBER TO A

MOV R1,A ; COPY NUMBER TO R1

INC DPTR

MOV R2,#05 ; COPY 05 IN TO R2

MOV R3, #00 ; COPY 00 IN R3

MOV R4, #00 ; COPY 00 IN R4

CLR C ; CLEAR CARRY FLAG

ANL A,#0E0H ; MASK LOWER 5 BIT

CJNE A,#00,LOOP1 ; IF FIRST CONDITION FAILS BRANCH TO LOOP1

MOV A,R1 ; CHECK THE SECOND CONDITION

BACK: RRC A

JNC LOOP2

INC R3

LOOP2: DJNZ R2,BACK

MOV A,R3

CJNE A, #02H, LOOP1 ; IF SECOND CONDITION FAILS BRANCH TO LOOP1 AND STORE 00H

DEC R4

LOOP1: MOV A,R4 ; CODE WORD IS VALID TO STORE FF DECREMENT 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

ORG 000H ; SET PROGRAM COUNTER 00H

TEMP EQU 40H

N EQU 04H ; ARRAY COUNT

MOV R4, #N-1 ; LOAD N-1 TO R4

MOV DPTR, #2000H ; STORE THE STARTING ADDRESS OF THE ARRAY IN DPTR

MOVX A, @DPTR ; COPY FIRST NUMBER TO A

LOOP1: MOV R1,A ; COPY CONTENTS OF A TO R1

AGAIN: INC DPTR ; INCREMENT DPTR

MOVX A, @DPTR ; GET THE NEXT NUMBER TO A

MOV TEMP , A ; COPY HE NEXT NUMBER TO TEMP

MOV A,R1

CJNE A, TEMP, LOOP2 ; A NOT EQUAL TEMP THEN BRANCH TO LOOP 2

SJMP LOOP3 ; A EQUAL TO TEMP BRANCH TO LOOP 3

LOOP2: JC LOOP3 ; A< TEMP BRANCH TO LOOP3

MOV A, TEMP ; A > TEMPNCOPY CONTENTS OF TEMP TO A

LOOP3: DJNZ R4, LOOP1 ; REPEAT UNTIL R4 IS ZERO

END
7. N 8 BIT NUMBERS ARE STORED IN EXTERNAL DATA MEMORY WRITE ASSEMBLY LEVEL PROGRAM TO
ARRANGE THEM IN ASCENDING ORDER.

ANS) PROGRAM

ORG 000H ; SET PROGRAM COUNTER TO 000H

TEMP EQU 40H

N EQU 04H ; ARRAY COUNT

MOV R4, #N-1 ; LOAD N-1 TO R4

LOOPS: MOV DPTR, #2000H ; STORE THE STARTING ADDRESS OF THE ARRAY IN DPTR

MOV R5,R4

LOOP1: MOVX A, @DPTR ; COPY CONTENTS OF MEMORY POINTED BY DPTR TO A

MOV R1,A ; COPY CONTENTS OF A TO R1

INC DPTR ; INCREMENT DPTR

MOV A,@DPTR ; GET THE NEXT NUMBER TO A

MOV TEMP, A ; COPY THE NEXT NUMBER TO TEMP

MOV A,R1

CJNE A, TEMP , LOOP2 ; A NOT EQUAL TEMP THEN BRANCH TO LOOP 2

SJMP LOOP3 ; A EQUAL TO TEMP BRANCH TO LOOP 3

LOOP2: JC LOOP3 ; A< TEMP BRANCH TO LOOP3

MOV @DPTR, A ; A> TEMP EXCHANGE THE CONTENTS OF TWO LOCATIONS

MOV A, TEMP

DEC DPL

MOVX @DPTR,A

INC DPL

LOOP3: DJNZ R5, LOOP1 ; REPEAT UNTIL R5 IS ZERO

DJNZ R4, LOOPS ; REPEAT UNTIL R4 IS ZERO

END
8. N 8 BIT NUMBERS ARE STORED IN EXTERNAL DATA MEMORY WRITE ASSEMBLY LEVEL PROGRAM TO
ARRANGE THEM IN DESCENDING ORDER

ANS) PROGRAM

ORG 000H ; SET PROGRAM COUNTER TO 000H

TEMP EQU 40H

N EQU 04H ; ARRAY COUNT

MOV R4, #N-1 ; LOAD N-1 TO R4

LOOPS: MOV R0, #41H ; STORE THE STARTING ADDRESS OF THE ARRAY IN R0

MOV R5,R4

LOOP1: MOV A, @R0 ; COPY CONTENTS OF MEMORY POINTED BY R0 TO A

MOV R1,A ; COPY CONTENTS OF A TO R1

INC R0 ; INCREMENT R0

MOV A,@R0 ; GET THE NEXT NUMBER TO A

MOV TEMP, A ; COPY THE NEXT NUMBER TO TEMP

MOV A,R1

CJNE A, TEMP , LOOP2 ; A NOT EQUAL TEMP THEN BRANCH TO LOOP 2

SJMP LOOP3 ; A EQUAL TO TEMP BRANCH TO LOOP 3

LOOP2: JNC LOOP3 ; A> TEMP BRANCH TO LOOP3

MOV @R0, A ; A< TEMP EXCHANGE THE CONTENTS OF TWO LOCATIONS

MOV A, TEMP

DEC R0

MOV @R0,A

INC R0

LOOP3: DJNZ R5, LOOP1 ; REPEAT UNTIL R5 IS ZERO

DJNZ R4, LOOPS ; REPEAT UNTIL R4 IS ZERO

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.

ORG 000H ; set the program counter 0000H


MOV DPTR,#7000H ; store the address of the memory in DPTR
MOVC A,@A+DPTR ; copy the contents pointed by DPTR to A
CJNE A,#39H,NEXT1 ; (A) not equal 39H branch NEXT1
AJMP NEXT2 ; (A) = 39H branch NEXT2
NEXT1:JC NEXT2 ; (A) < 39H branch NEXT2
CLR C
SUBB A,#37H ; (A) > 39H sub 37H
AJMP NEXT5 ; branch to NEXT 5
NEXT2:CLR C
SUBB A,#30H ; (A) < 39H sub 30H
NEXT5:MOV DPTR,#5000H
MOVX @DPTR,A ; store the result in 5000H
ORG 7000H
DB 66
END

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.

ORG 000H ; set the program counter 000H


MOV DPTR,#7000H ; copy address 7000H to DPTR
MOVX A,@DPTR ; copy number to A
MOV DPTR, #5000H ; copy address 5000H to DPTR
MOV R2,A ; copy BCD data in R2
ANL A,#0FH ; mask the upper nibble
ORL A,#30H ; convert the lower nibble to ASCII
MOVX @DPTR,A ; store the result in 5000H
MOV A,R2 ; get the original data
ANL A,#0F0H ; mask the lower nibble
SWAP A
ORL A,#30H ; convert the lower nibble to ASCII
INC DPTR ; increment DPTR
MOVX @DPTR,A ; store the result in 5001H
END

13 13.Write Assembly level program to convert binary code stored in location 6000H to gray code. Store
the result in location 5000H.

ORG 000H ;SET PROGRAM COUNTER 0000H


MOV DPTR,#6000H ;COPY ADDRESS 6000H TO DPTR
MOVX A,@DPTR ;COPY NUMBER TO A
MOV DPTR,#5000H ;COPY ADDRESS 500H TO DPTR
MOV RO,A ;COPY DATA TO R0
CLR C ;CLEAR CARY FLAG
RRC A ;ROTATE CONTENTS OF A RIHT BY ONE POSITION
XRL A,R0 ;ER-OR CONTENTS OF A WITH R0
MOVX @DPTR,A ;STORE RESULT IN LOCATION 5000H
END
14.Two 8 bit numbers are stored in locations 1000H and 1001H of external data memory. Write
Assembly level program to find Greatest Common Divisor (GCD) of two numbers and store the result in
location 2000H.

ORG 000H;SET PROGRAM COUNTER 0000H


TEMP EQU 70H
TEMP1 EQU 71H
MOV DPTR,#1000H ;COPY ADDRESS 1000H TO DPTR
MOVX A,@DPTR ;COPY FIRST NUMBER TO A
MOV TEMP,A ;COPY FIRST NUMBER TO TEMP
INC DPTR
MOVX A,@DPTR ;COPY SECOND NUMBER TO A
LOOPS:CJNE A,TEMP,LOOP1 ;(A) NOT EQUALS TO (TEMP) BARNCH TO LOOP 1
AJMP LOOP2;(A) EQUALS TO (TEMP) BRANCH TO LOOP 2
LOOP1: JNC LOO3;(A) > (TEMP) BRANCH TO LOOP 3
MOV TEMP1,A;(A) < (TEMP) EXCHANGE (A) WITH (TEMP)
MOV A,TEMP
MOV TEMP,TEMP1
LOOP3:MOV B,TEMP
DIV AB ;DIVIDE (A) BY (TEMP)
MOV A,B ;MOV REMAINDER TO A
CJNE A,#00,LOOPS ;(A) NOT EQUAL TO 00 BRANCH TO LLOPS
LOOP2:MOV A,TEMP
MOV DPTR,#2000H
MOVX @DPTR,A ;STORE THE RESULT IN 2000H
END

15. Write Assembly level program to compute 1+3+. +N (say 15) and save the sum at 70H.

ORG 0000H ;SET PROGRAM COUNTER 0000H


N EQU 15
MOV R0, #01 ;CLEAR R0
MOV B,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
ADD A,B
MOV 70H,A ;SAVE THE RESULT IN LOCATION 70H
END

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

1 Draw TMOD CWF BIT functions.

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.

F= (1/12 machine cycles ) * XTAL = (1/12) * 11.0592e6 HZ = .92160 MHz

Period = T= 1/F = 1/.92160 MHZ = 1.085 micro Sec

4 Explain operations of Timer mode 1 and characteristics with diagram.

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.

2. Since TH TL = B83EH = 47166 (in decimal) we have 65536 47166 = 18370.


This means that the timer counts from B83EH to FFFFH.. This plus rolling over to
0 goes through a total of 18370 clock cycles, where each clock is 1.085 \ls in dura
tion. Therefore, we have 18370 x 1.085 (is = 19.93145 ms as the width of the pulse.

9 Write the characteristics and operations of Timer mode 2.


Mode 2- It is an 8 bit timer that allows only values of 00 to FFH to be loaded into the timers register TH.
After TH is loaded with 8 bit value, the 8051 gives a copy of it to TL. Then the timer must be started. It is
done by the instruction SETB TR0 for timer 0 and SETB TR1 for timer1. This is like mode 1. After
timer is started, it starts to count up by incrementing the TL register. It counts up until it reaches its limit
of FFH. When it rolls over from FFH to 00. It sets high the TF (timer flag). If we are using timer 0, TF0
goes high; if using TF1 then TF1 is raised. When Tl register rolls from FFH to 00 and TF is set to 1, TL is
reloaded automatically with the original value kept by the TH register. To repeat the process, we must
simply clear TF and let it go without any need by the programmer to reload the original value. This makes
mode 2 auto reload, in contrast in mode 1 in which programmer has to reload TH and TL. .

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.

1. 57,600 / 9600 = 6; therefore, TH1 = -6 or TH1 = FAH.

2. 57,600 / 4800 = 12; therefore, TH1 = -12 or TH1 = F4H.

17 Draw the interrupt vector table.


22 Draw Barrel shifter in ARM processor
21 Draw the pin diagram of 8051 microcontroller.

.23 Draw ARM stage 5, 6, 7 pipelining sequence.


24 Draw 8085 architecture.

25 Draw the architecture of 8086 microprocessor.


26 Draw ADC and sensor interfacing with 8051 microcontroller.

29 With XTAL = 11.0592 MHz, find the TH1 value needed to have the following baud rates. (a) 9600 (b)
2400 (c) 1200.