Write assembly language program to multiply 25 by
10 using repeated addition
MOV R0, #25H;
MOV R1, #10H;
MOV A, #00H;
UP: ADD A, R0;
DJNZ R1, UP
MOV R5, A
Transfer the contents of the register A,R0,and R1,respectively of bank0 to the register B, R0
and R1 of bank1 using stack operation.
MOV R6, #25H [R6]=25H //CONTENT OF R6 IS 25H
MOV R1, #12H [R1]=12H //CONTENT OF R1 IS 12H
MOV R4, #0F3H [R4]=F3H //CONTENT OF R4 IS F3H
PUSH 6 [SP]=08 [08]=[06]=25H //CONTENT OF 08 IS 25H
PUSH 1 [SP]=09 [09]=[01]=12H //CONTENT OF 09 IS 12H
PUSH 4 [SP]=0A [0A]=[04]=F3H //CONTENT OF 0A IS F3H
POP 6 [06]=[0A]=F3H [SP]=09 //CONTENT OF 06 IS F3H
POP 1 [01]=[09]=12H [SP]=08 //CONTENT OF 01 IS 12H
POP 4 [04]=[08]=25H [SP]=07 //CONTENT OF 04 IS 25H
Write an assembly language program to exchange
the lower nibble of data present in external memory
6000H and 6001H.
Exchange digit. Exchange the lower order nibble of
Accumulator (A0-A3) with lower order nibble of the
internal RAM location which is indirectly addressed by
the register.
Mov dptr, #6000h
Movx a, @dptr
Mov b,a
Inc dptr
Movx a, @dptr
XCHD A,B
Movx @ dptr,a
DEC DPL
Mov a,b
Movx @dptr, a
end
Write an assembly language program to toggle the bits of port P1
START: MOV A, #55H ; A = 55H
MOV P1, A ; send register A to port 1
ACALL DELAY ; call DELAY
MOV A, #AAH ; A = AAH
MOV P1, A ; send register A to port 1
ACALL DELAY ; call DELAY
SJMP START ; repeat again from START
In order to make Port 0 as input, the port must be programmed by writing 1 to all the bits.
Example 2.2.2:
Configure port 0 as input port by writing 1s to it and then receive data from the port 0 and
send to P1.
Solution:
MOV A, #FFH ; A = FFH
MOV P0, A ; make port 0 as input
START:
MOV A, P0 ; get data from port 0
MOV P1, A ; send register A to port 1
SJMP START ; repeat again from START
A student has to take 6 courses in semester. The
marks of student out of 25 are stored in RAM
location of 50h. Write a program to find average
marks and stored in R6.
ORG 0000H
MOV R1, #0A ;R1 stores the count of total 6
bit numbers
MOV B, #0A ;B is used as divisor for average
MOV R0, #50H ;R0 acts as pointer to the data
MOV A, #00H ;Clear A
BACK : ADD A, @R0 ; Add the data to A
register
INC R0 ; Increment the pointer
DJNZ R1,BACK ; repeat addition until R1=0
DIV AB ; divide sum to get average ;quotient is
in A and remainder in B
MOV R6,A ;Ignore remainder and store
average result in 60h
HERE: SJMP HERE ; wait
END
Write a program to complement the value of AAH,
800 times
Write a program to generate square wave of 5o% duty cycle on bit-5 of port-1
Assuming XTAL = 11.0592 MHz, write a program to generate a square wave of 50
Hz frequency on pin P2.3.
Solution:
Look at the following steps.
1. T — 1 / 50 Hz = 20 ms, the period of the square wave.
2. 1/2 of it for the high and low portions of the pulse = 10 ms
1. 10 ms / 1.085 us = 9216 and 65536 – 9216 = 56320 in decimal,
and in hex it is
DCOOH.
3. TL = 00 and TH = DC (hex)