Sunteți pe pagina 1din 28

EXPERIMENT-5

AIM: Write an Assembly language program to toggle bits of port 1 continuously with a
250ms delay.
CODE:
ORG 0000H
MOV A,#0FFH
AGAIN1: MOV P1,A
ACALL DELAY
CPL A
MOV P1,A
SJMP AGAIN1

DELAY:MOV R4,#50
ITERATION: MOV R2,#19
HERE:MOV R3,#255
AGAIN:DJNZ R3,AGAIN
DJNZ R2,HERE
DJNZ R4,ITERATION
RET

END




OUTPUT






EXPERIMENT-6
AIM: Write an Assembly language program to display count form 00 to FFH on port 1 and
port 2.
CODE: ORG 0000H
MOV R3,#256
MOV R2,#00H
HERE:MOV A,R2
MOV P1,A
MOV P2,A
INC R2
MOV R4,#255
ITERATION: MOV R5,#19
HERE1:MOV R6,#255
AGAIN:DJNZ R6,AGAIN
DJNZ R5,HERE1
DJNZ R4,ITERATION
DJNZ R3,HERE
END







OUTPUT



EXPERIMENT-8
AIM: Write an Assembly language program to send your name to serial port. Assuming a
switch is connected to P1.0, monitor status and make the decision as follows:
SW=0: send first name
SW=1: send last name
Assume baud rate of 9600, 8bit data, 1stop bit

CODE:
SWITCH BIT P1.0
ORG 0000H
SETB P1.0
AGAIN:JB P1.0,LASTNAME
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON,#50H
SETB TR1
FIRSTNAME:
MOV SBUF,#'K'
MOV P2,#'K'
HERE1:JNB TI,HERE1
CLR TI
MOV SBUF,#'A'
MOV P2,#'A'
HERE2:JNB TI,HERE2
CLR TI

MOV SBUF,#'R'
MOV P2,#'R'
HERE3:JNB TI,HERE3
CLR TI
MOV SBUF,#'A'
MOV P2,#'A'
HERE4:JNB TI,HERE4
CLR TI
MOV SBUF,#'N'
MOV P2,#'N'
HERE5:JNB TI,HERE5
CLR TI
SJMP AGAIN

LASTNAME:
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON,#50H
SETB TR1
MOV SBUF,#'K'
MOV P2,#'K'
HERE6:JNB TI,HERE6
CLR TI


MOV SBUF,#'E'
MOV P2,#'E'
HERE7:JNB TI,HERE7
CLR TI
MOV SBUF,#'H'
MOV P2,#'H'
HERE8:JNB TI,HERE8
CLR TI
MOV SBUF,#'A'
MOV P2,#'A'
HERE9:JNB TI,HERE9
CLR TI
MOV SBUF,#'R'
MOV P2,#'R'
HERE10:JNB TI,HERE10
CLR TI
LJMP AGAIN

END





OUTPUT





EXPERIMENT-1
AIM: Write an Assembly language program for addition, subtraction, multiplication and
division of two 16 bit-numbers:
CODE:
ORG 0000H
MOV R4,#15H
MOV R5,#26H
MOV R6,#17H
MOV R7,#18H
//ADDITION
MOV A,R4
ADD A,R6
MOV R0,A
MOV A,R5
ADDC A,R7
MOV R1,A
//SUBTRACTION
MOV A,R4
SUBB A,R6
MOV R2,A
MOV A,R5
SUBB A,R7
MOV R3,A


//MULTIPLICATION OF 1526 AND 1718

//Multiply R5 by R7
MOV A,R5 //Move the R5 into the Accumulator
MOV B,R7 //Move R7 into B
MUL AB //Multiply the two values
MOV R2,B //Move B (the high-byte) into R2
MOV R3,A //Move A (the low-byte) into R3

//Multiply R5 by R6
MOV A,R5 // Move R5 back into the Accumulator
MOV B,R6 //Move R6 into B
MUL AB // Multiply the two values
ADD A,R2 //Add the low-byte into the value already in R2
MOV R2,A // Move the resulting value back into R2
MOV A,B //Move the high-byte into the accumulator
ADDC A,#00h //Add zero (plus the carry, if any)
MOV R1,A // Move the resulting answer into R1
MOV A,#00h //Load the accumulator with zero
ADDC A,#00h //Add zero (plus the carry, if any)
MOV R0,A //Move the resulting answer to R0.

//Multiply R4 by R7
MOV A,R4 // Move R4 into the Accumulator
MOV B,R7 //Move R7 into B
MUL AB // Multiply the two values
ADD A,R2 // Add the low-byte into the value already in R2
MOV R2,A //Move the resulting value back into R2
MOV A,B // Move the high-byte into the accumulator
ADDC A,R1 //Add the current value of R1 (plus any carry)
MOV R1,A // Move the resulting answer into R1.
MOV A,#00h //Load the accumulator with zero
ADDC A,R0 //Add the current value of R0 (plus any carry)
MOV R0,A // Move the resulting answer to R1.

//Multiply R4 by R6
MOV A,R4 //Move R4 back into the Accumulator
MOV B,R6 // Move R6 into B
MUL AB //Multiply the two values
ADD A,R1 //Add the low-byte into the value already in R1
MOV R1,A //Move the resulting value back into R1
MOV A,B //Move the high-byte into the accumulator
ADDC A,R0 //Add it to the value already in R0 (plus any carry)
MOV R0,A //Move the resulting answer back to R0

MOV A,R4 //DIVISION
MOV B,#17
DIV AB
MOV R1, A

OUTPUT




EXPERIMENT-7
AIM: Write an Assembly language program to generate square wave of 1KHz on pin 0.1
using Timer in mode 1 and mode 2.
ORG 0000H //MODE 1
RPT: MOV TMOD, #01H
MOV TL0,#34H
MOV TH0,#0FEH
CPL P0.1
SETB TR0
BACK: JNB TF0, BACK
CLR TR0
CLR TF0
SJMP RPT
END
ORG 0000H //MODE 2
CODE: MOV TMOD, #02H
REPT: CPL P0.1
MOV R0, #05
AGAIN: MOV TH0, #48H
SETB TR0
BACK: JNB TF0, BACK
CLR TR0
CLR TF0
DJNZ R0, AGAIN
SJMP REPT
END
OUTPUT




EXPERIMENT-4
AIM: Write an Assembly language program to convert packed BCD to two ASCII
characters.
CODE:
ORG 0000H
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
END






OUTPUT











EXPERIMENT-9
AIM: Write An Assembly Program That Gets 8 Bit Data From P0 And Send It To P2
While Simultaneously Creating Square Wave Of 400usec Period On P1.7.Use Timer 0 To
Create Square Wave.
CODE:
ORG 0000H
LJMP MAIN //by-pass interrupt vector table
//--ISR for timer 0 to generate square wave
ORG 000BH //Timer 0 interrupt vector table
CPL P1.7 //toggle P2.1 pin
RETI //return from ISR
//--The main program for initialization
ORG 0030H //after vector table space
MAIN: MOV TMOD,#02H //Timer 0, mode 2
MOV P0,#0FFH //make P0 an input port
MOV TH0,#48H //TH0=48H
MOV IE,#82H //IE=10000010 //(bin) enable Timer 0
SETB TR0 //Start Timer 0
BACK: MOV A,P0 //get data from P0
MOV P2,A //issue it to P1
SJMP BACK //keep doing it loop unless interrupted by
TF0
END

OUTPUT













EXPERIMENT-3
AIM: Write an Assembly language program to display AMITY COLLEGE on the LCD
display.
CODE:
ORG 0H
MOV DPTR,#MYCOM
C1: CLR A
MOVC A,@A+DPTR
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
INC DPTR
JZ SEND_DAT
SJMP C1
SEND_DAT:
MOV DPTR,#MYDATA
D1: CLR A
MOVC A,@A+DPTR
ACALL DATAWRT ;call command subroutine
ACALL DELAY ;give LCD some time
INC DPTR
JZ AGAIN
SJMP D1
AGAIN: SJMP AGAIN
COMNWRT: ;send command to LCD
MOV P1,A ;copy reg A to port 1
CLR P2.0 ;RS=0 for command
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-L pulse
RET
DATAWRT: ;write data to LCD
MOV P1,A ;copy reg A to port 1
SETB P2.0 ;RS=1 for data
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-L pulse
RET
DELAY:MOV R5,#255
ITERATION:MOV R3,#255 ;50 or higher for fast CPUs
HERE2: MOV R4,#255 ;R4 = 255
HERE: DJNZ R4,HERE ;stay until R4 becomes 0
DJNZ R3,HERE2
DJNZ R5,ITERATION
RET
ORG 300H
MYCOM:DB 38H,0EH,01,06,84H,0 ;COMMANDS AND NULL
MYDATA:DB "AMITY COLLEGE",0 ;DATA AND NULL
END
OUTPUT








EXPERIMENT-2
AIM: Write an Assembly language program to sort 10 numbers in ascending order stored
at some memory location.
CODE:
MAIN:MOV DPTR,#4200H
MOVX A,@DPTR
DEC A
MOV R0,A
MOV R1,A
INC DPTR
NEXT:MOVX A,@DPTR
MOV R2,A
INC DPTR
MOVX A,@DPTR
CLR C
SUBB A,R2
JNC NOSWAP
MOVX A,@DPTR
SWAPING:XCH A,R2
MOVX @DPTR,A
DEC DPL
MOV A,R2
MOV P1,A
MOVX @DPTR,A
INC DPTR
NOSWAP:DJNZ R0,NEXT
DJNZ R1,MAIN
END






















OUTPUT













EXPERIMENT-10
AIM: Write an Assembly language program to convert Hexadecimal into decimal.

CODE:
ORG 0000H
MOV A,#9C //read data from P1
MOV B,#10 ;B=0A hex
DIV AB ;divide by 10
MOV R7,B ;save lower digit
MOV B,#10
DIV AB ;divide by 10 once more
MOV R6,B ;save the next digit
MOV R5,A ;save the last digit
END












OUTPUT












INDEX
S.NO
NAME OF EXPERIMENT DATE TEACHERS
SIGN
1 Write an Assembly language program for
addition, subtraction, multiplication and division
of two 16 bit-numbers.

2
Write an Assembly language program to sort 10
numbers in ascending order stored at some
memory location.

3
Write an Assembly language program to display
AMITY COLLEGE on the LCD display.

4
Write An Assembly Language Program To
Convert Packed BCD Into Two ACSII Numbers.

5
Write an Assembly language program to toggle
bits of port 1 continuously with a 250msec delay

6
Write an Assembly language program to count
from 00H to FFH on port 1 and port 2.

7
Write an Assembly language program to generate
a square wave of IKHz on P0.1 using Timer
mode 1 and 2.

8
Write an Assembly language program to send
your name to serial port. Assuming a switch is
connected to P1.0, monitor status and make the
decision as follows:
SW=0: send first name
SW=1: send last name
Assume baud rate of 9600, 8bit data, 1stop bit


9
Write An Assembly Program That Gets 8 Bit Data
From P0 And Send It To P2 While
Simultaneously Creating Square Wave Of
400usec Period On P1.7. Use Timer 0 To Create
Square Wave.

10
Write an Assembly language program to convert
Hexadecimal to decimal number.

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