1 Addition

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

//1ADDITION

ORG 0000H MOV A,#05H MOV B,#05H ADD A,B H: SJMP H END

//2 SUBTRACTION
ORG 0000H MOV A,#05H MOV B,#04H SUB A,B H: SJMP H END

//DIVISION
ORG 0000H MOV A,#05H MOV B,#05H MUL AB H: SJMP H END

//4 Write and assemble a program to add the following data and then use the
simulator to examine the CY flag. 92H, 23H, 66H, 87H, FSH
ORG 0000H MOV A, #92H MOV R0, #23H ADD A, R0 JNC L1 INC R3 L1: ADD A,
#66H JNC L2 INC R3 L2: ADD A, #87H JNC L3 INC R3 L3: ADD A, #0F5H JNC L4
INC R3 L4: SJMP L4 END

//5 Write and assemble a program to load values into each of registers R0 - R4
and then push each of these registers onto the stack. Single step the program
and examine the stack and the SP register after the execution of each
instruction.
ORG 000H MOV R0,#30H MOV R1,#40H MOV R2,#50H MOV R3,#60H MOV
R4,#70H PUSH 0 PUSH 1 PUSH 2 PUSH 3 PUSH 4 HERE: SJMP HERE END

//6 Write an 8051 assemble language program: (a) Set SP = 0D, (b) Put a
different value in each of RAM locations 0D, 0C, 0B, 0A, 09 and 08 (c) POP each
stack location into registers R0 - R4.
ORG 000H MOV SP,#0DH MOV 0DH,#10H MOV 0CH,#20H MOV 0BH,#30H MOV
0AH,#40H MOV 09H,#50H MOV 08H,#60H POP 0 POP 1 POP 2 POP 3 POP 4 POP
5 HERE: SJMP HERE END

//7 Write and assemble a program to load valuesinto each of registers R0 - R4


and then push each of these registers onto the stack and pop them back. Single
step the program, and examine the stack and the SP register after the execution
of each instruction.
ORG 0000H MOV R0, #10H MOV R1, #20H MOV R2, #30H MOV R3, #40H MOV
R4, #50H PUSH 0 PUSH 1 PUSH 2 PUSH 3 PUSH 4 POP 4 POP 3 POP 2 POP 1 POP
0 END
//8 Write a program to transfer a string of data from code space starting at
address 200H to RAM locations starting at 40H. The data is as shown below:
0200H: DB "VIT UNIVERSITY" Using the simulator, single step through the
program and examine the data transfer and registers.
ORG 0000H MOV DPTR, #0200H MOV R1, #0EH MOV R0, #40H LOOP: CLR A
MOVC A, @A+DPTR MOV @R0, A INC DPTR INC R0 DJNZ R1, LOOP HERE: SJMP
HERE ORG 0200H DB "VIT UNIVERSITY" END

//9 Write a program to add 10 bytes of data and store the result in registers R2
and R3. The bytes are stored in the ROM space starting at 200H. The data would
look as follows: MYDATA: DB 92, 34, 84, 129, ... Pick your own data. Notice that
you must first bring the data from ROM space into the CPU's RAM, and then add
them together. Use a simulator to single step the program and examine the data.
ORG 000H MOV DPTR, #200H MOV R0, #10H MOV R2, #00H MOV R3, #00H
LOOP: CLR A MOVC A, @A+DPTR ADD A, R2 JNC NEXT INC R3 NEXT: INC DPTR
MOV R2, A DJNZ R0, LOOP HERE: SJMP HERE ORG 200H DB 22H, 43H, 23H, 34H,
31H, 77H, 91H, 33H, 43H, 07H END

//10 Write and assemble a program to toggle all the bits of P0, P1, and P2
continuously by sending 55H and AAH to these ports. Put a time delay between
the "on" and "off" states. Then using the simulator, single step through the
program and examine the ports. Do not single-step through the time delay calL
CODE ORG 0000H HERE: MOV P0, #55H MOV P1, #55H MOV P2, #55H ACALL
DELAY MOV P0, #0AAH. MOV P1, #0AAH MOV P2, #0AAH ACALL DELAY SJMP
HERE DELAY: MOV R1, #04H BACK: MOV R2, #20H AGAIN: DJNZ R2, AGAIN DJNZ
R1, BACK RET END

//11 Get the Data from Port P1 and Send it to Port P2, Note: P1 as input Port and
P2 as Output Port
MOV A, #0FFh MOV P1, A HERE: MOV A, P1 MOV P2, A SJMP HERE END

//12 Write a program using timer 0 to generate a 500 Hz square wave frequency
on one of the pins of P1.0 Then examine the frequency using the KEIL IDE inbuilt
Logic Analyzer.
Frequency f = 500Hz
Total time period T = 2ms
Required delay = TON = TOFF = 1ms
[(FFFF - XXXX) + 1] * 1.085µs = 1ms
(65536 - X) * 1.085µs = 1ms
X = (64614)D
X = XXXX = FC66H
ORG 0000H MOV TMOD, #01H HERE: MOV TL0, #66H MOV TH0, #0FCH CPL P1.0
ACALL DELAY SJMP HERE DELAY: SETB TR0 AGAIN: JNB TF0, AGAIN CLR TR0 CLR
TF0 RET END

//13 Write a program using timer 1 to generate a 1 kHz square wave frequency
on one of the pins of P1. Then examine the frequency using the KEIL IDE inbuilt
Logic Analyzer.
Frequency f = 1 KHz
Total time period T = 1ms
Required delay = TON = TOFF = 0.5ms
[(FFFF - XXXX) + 1] * 1.085µs = 0.5ms
XXXX = FE33H
ORG 0000H MOV TMOD, #10H HERE: MOV TL1, #33H MOV TH1, #0FEH CPL P1.0
ACALL DELAY SJMP HERE DELAY: SETB TR1 AGAIN: JNB TF1, AGAIN CLR TR1 CLR
TF1 RET END

//14 Write a program using timer 1 to generate a 2 KHz square wave frequency
on one of the pins of P1.0.
ORG 0000H MOV TMOD, #20H HERE: MOV TH1, #19H BACK: SETB TR1 AGAIN:
JNB TF1, AGAIN CPL P1.0 CLR TF1 SJMP BACK END

//15 Assuming that clock pulses are fed into pin T1, write a program for counter 1
in mode 2 to count the pulses and display the state of the TL1 count on P2, which
connects to 8 LEDs.
MOV TMOD, #01100000B MOV TH1, #0 SETB P3.5 AGAIN: SETB TR1 BACK: MOV
A, TL1 MOV P2, A JNB TF1, BACK CLR TR1 CLR TF1 SJMP AGAIN END

//16 Write an 8051-assembly program to transfer data serially at baud rate 9600
with 8- bit data, one stop bit, and observe the transmi ed data in the serial
window of the simulator
ORG 0000H START: MOV DPTR, #MYDATA MOV TMOD, #20H MOV TH1, #-3 MOV
SCON, #50H SETB TR1 MOV R1, #14 AGAIN: CLR A MOVC A, @A+DPTR MOV
SBUF, A HERE: JNB TI, HERE CLR TI INC DPTR DJNZ R1, AGAIN SJMP START
MYDATA: DB 'VIT UNIVERSITY' END
//17 Generate a square wave signal from P1.2 which has 0.1ms off me and 0.1ms
on me use Timer 1 – mode 2 (Auto Reload mode)
ORG 0000H MOV TMOD, #20H HERE: MOV TH1, #0A4H CPL P1.2 LCALL DELAY
SJMP HERE DELAY: SETB TR1 AGAIN: JNB TF1, AGAIN CLR TF1 RET END

//18 Write an 8051 program to get data from port P0 and send it to port P1
continuously while an interrupt will do the following: Timer 0 will toggle the P2.1
bit every 100 microseconds.
ORG 0000H LJMP MAIN ORG 000BH CPL P2.1 RETI ORG 0030H MAIN: MOV
TMOD,#02H MOV P0,#0FFH MOV TH0,#0A4H MOV IE,#10000010B SETB TR0
BACK: MOV A,P0 MOV P1,A SJMP BACK END

//19 Write an 8051 program to get data from a single bit of P1.2 and send it to
P1.7 continuously while an interrupt will do the following: A serial interrupt
service routine will receive data from a PC and display it on P2 ports
ORG 0000H LJMP MAIN ORG 0023H LJMP DISP ORG 0050H MAIN: SETB P1.2 MOV
TMOD, #20H MOV TH1, #-3 MOV SCON, #50H MOV IE, #10010000B SETB TR1
BACK:MOV C, P1.2 MOV P1.7, C SJMP BACK DISP: MOV A, SBUF MOV P2, A CLR RI
RETI END

//20
Write an assembly-level program to display your roll number on LCD which is
interfaced with an 8051 microcontroller.
ORG 0000H MOV A, #38H ACALL COMMAND ACALL DELAY MOV A, #0EH ACALL
COMMAND ACALL DELAY MOV A, #01H ACALL COMMAND ACALL DELAY MOV A,
#82H ACALL COMMAND ACALL DELAY MOV DPTR, #string back: MOV A, #00H
MOVC A, @A+DPTR JZ AGAIN ACALL DATATRANSFER ACALL DELAY INC DPTR SJMP
back ACALLDELAY AGAIN: SJMP AGAIN COMMAND: MOV P2, A CLR P0.5 CLR P0.6
SETB P0.7 CLR P0.7 RET DELAY: MOV R3, #255 HERE: DJNZ R3, HERE RET
DATATRANSFER: MOV P2, A SETB P0.5 CLR P0.6 SETB P0.7 CLR P0.7 END

You might also like