Assembly Programs VNH
-
Upload
hafizrahimmit -
Category
Documents
-
view
1 -
download
0
description
Transcript of Assembly Programs VNH
-
1MICROCONTROLLER IV SEMESTERASSEMBLY PROGRAMS
-
2//1a)WAP to move a block of data within the internal RAM
Org 0hstart1: mov r0,#40h ;r0 pointed to internal RAM 40h
mov r1,#30h ;r1 pointing to internal RAM 030hmov r2,#5 ;r2 loaded with no. of elements in the array
Start:mov a,@r0 ;data transfermov @r1,ainc r0inc r1djnz r2,start ;decrement r2,if not equal to 0,continue with data
;transfer process.Sjmp Start1end
//1b)WAP to move a block of data external RAM to internal RAM//program for block data transfer from external RAM to internal RAM//enter the elements from location 0500h(ext.RAM)
Org 0hstart1: mov dptr,#0500h //data pointer ppointed to external memory
//0500hmov r1,#30h //r1 pointing to internal RAM 030hmov r2,#5 //r2 loaded with no. of elements in the array
Start:movx A,@dptrmov @r1,a
-
3inc dptrinc r1djnz r2,startSjmp Start1end
////2)WAP to exchange data between internal RAM locations
org 0000hmov r0,#30h ;r0 pointing to 030h(int. RAM)mov r1,#40h ;r1 pointing to 040h(int. RAM)mov r2,#0ah ;r2 loaded with no. of elements to be exchanged
start: mov a,@r0 ;data @r0 is stored in temporary reg r3mov r3,amov a,@r1 ;data @r1 is moved to @r0mov @r0,amov a,r3 ;data from r3 is moved to @r1mov @r1,ainc r0 ;increment data pointersinc r1djnz r2,start ;decrement counter r2,repeat the process if r2 is not zeronop
here: sjmp hereend
//3) WAP to sort an array stored in the internal RAM//program for sorting the elements in ascending order in a given array in the internalRAM
org 0000h
-
4num equ 040hback1: mov r0,#50h ;store n elements(say n=5) from 50h
mov a,r0 ;r0 and r1 are used as pointersmov r1,amov r3,#04h ;load (n-1) to r3 (no. of passes)mov a,r3mov r2,a ;load r3 to r2(no. of comparison in each pass)
back: mov a,@r0 ;compare no. pointed to by r0 with no. pointed to by r1
inc r1mov num,@r1
cjne a,num,loopsjmp next
loop: jc next ;if num at r0
-
5end
//5)WAP to add two 16 bit numbers// program to add two 16 bit numbers//result available in 40h,41h and 42h(40 lsb;41 msb;42 carry)
org 0hstart: mov r0,#20h ;r0 pointing to lsb of src1
mov r1,#30h ;r1 pointing to lsb of src2mov a,@r0 ;add lsb of src1 and src2add a,@r1mov 40h,a ;result stored at 40hinc r0 ;r0 pointing to msb of src1inc r1 ;r0 pointing to msb of src2mov a,@r0addc a,@r1 ;add msb of src1 and src2 with carrymov 41h,a ;result stored at 41hmov a,#0haddc a,#0hmov 42h,a ;carry stored at 42hsjmp startend
6)WAP to subtract two 16 bit numbers// program to subtract two 16 bit numbers//result available in 40h and 41h(40 lsb;41 msb)
org 0hhere: clr c ;clear carry bit
mov r0,#20h ;r0 pointing to lsb of src1mov r1,#30h ;r1 pointing to lsb of src2mov a,@r0 ;sub lsb of src2 from lsb of src1subb a,@r1mov 40h,a ;result stored at 40hinc r0 ;r0 pointing to msb of src1inc r1 ;r0 pointing to msb of src2mov a,@r0subb a,@r1 ;sub msbs with borrowmov 41h,a ;result stored at 41hsjmp hereend
7)pgm for 16 bit multiplication8)pgm for 16 bit division
-
6//9)WAP to find the square of the number in the range 0h to ffh//WAP to find the square of the number in data RAM 20h and store the square in 30h and//31h
org 0hmov r0,#20Hmov a,@r0 ;num in 20h is loaded into acc and b regmov 0f0h,amul abmov 030h,a ;lower order product in 30hmov 031h,0f0h ;higher order product in 31h
here: sjmp hereend
// Program to convert BCD to ASCII// The equivalent ASCII code will be found in Registers R2 and R6
ORG 00HMOV A,#29H // Register A contains BCD valueMOV R2,AANL A,#0FHORL A,#30HMOV R6,AMOV A,R2ANL A,#0f0HRR ARR ARR ARR AORL A,#30HMOV R2,A
END
// PROGRAM USING TIMER 0 TO GENERATE TIME DELAY// IT CREATES A SQUARE WAVE OF 50% DUTY CYCLE ON P3.0 BIT
ORG 00H
-
7MOV TMOD,#01HHERE: MOV TL0,#0F2H
MOV TH0,#0FFHCPL P3.0ACALL DELAYSJMP HERE
DELAY: SETB TR0
AGAIN: JNB TF0,AGAIN
CLR TR0CLR TF0RET
END
// PROGRAM TO CONVERT HEX VALUE TO DECIMAL VALUE //
ORG 00HSJMP 30HORG 30H
MOV A,#0Fh // HEX VALUEMOV B,#0AHDIV ABMOV R0,B // RO,R1,R2 SHOWS THE EQUIVALENT
DECIMAL VALUEMOV B,#0AHDIV ABMOV R1,BMOV R2,A
end
-
8//10)WAP to find the cube of the number in the range 0h to fh//WAP to find the cube of the number in data RAM 20h and store the result in 30h
org 0hmov r0,#20Hmov a,@r0 ;num in 20h is loaded into acc and b regmov 0f0h,amul ab ;find the square of the no.mov 0f0h,@r0mul ab ;multiply square of the no. by the no.to get the cube.mov 030h,a ;lower order product in 30hmov 031h,0f0h ;higher order product in 31h
here: sjmp hereend
//12)WAP to convert BCD to ASCIIorg 0h
start: mov r0,#20h ;r0 pointing to src location,loaded with a BCD no.mov a,@r0 ;no. moved to accumulator and added 30h to get equivalent
;ASCIIadd a,#30hmov 40h,a ;result stored at 40hsjmp startend
//13)WAP to convert given decimal no. to equivalent ASCIIorg 0h
start: mov r0,#30h ;r0 pointing to src locn.mov a,@r0 ;acc. loaded with decimal no.
;process of seperating the lower nibble and higher nibble of decimal no.
anl a,#0fh ;mask higher nibblemov r1,a ;lower nibble stored at r1mov a,@r0anl a,#0f0h ;mask lower nibbleswap a ;exchange higher and lower nibble positionsmov r2,a ;higher nibble stored in r2
;process of converting decimal to ASCII
mov a,r1
-
9add a,#30hmov 40h,a ;40h has ASCII value for lower nibble of decimal no.mov a,r2add a,#30hmov 41h,a ;41h has ASCII value for higher nibble of decimal no.sjmp startend
//14)WAP to convert given hex no. to equivalent decimal no.
//Hex number has to be store at location x:5fffh and result to be stored in//next consecutive locations
org 0hstart:
mov dptr,#5fffhmovx a,@dptrmov 0f0h,#064h ;Load B reg with 100d or 64hdiv ab ;Hundredsinc dptrmovx @dptr,a ;store in external rammov a,0f0h ;remainder from b reg to accmov 0f0h,#0ah ; Load B reg with 10d or 0ahdiv ab;inc dptr;movx @dptr,a ;store tens in external raminc dptrmov a,0f0hmovx @dptr,a ;store units in ext ram
here: sjmp hereend
-
10
//15)WAP to convert given dec no. to equivalent hexadecimal no.org 0h
start: mov r0,#30hmov a,@r0;process of seperating the lower nibble and higher nibble of decimal no.
anl a,#0fh ;mask higher nibblemov r1,a ;lower nibble stored at r1mov a,@r0
swap a ;exchange higher and lower nibble positionanl a,#0fh ;mask lower nibble
mov r2,a ;higher nibble stored in r2;process of conversion;dec no.=higher nibble*10d (or 0ah)+lower nibble*1
mov a,r1 ;lower nibble to accmov 0f0h,#01h ;reg b=01mul abmov r3,a ;product in r3
mov a,r2 ;higher nibble to accmov 0f0h,#0ah ;reg b=10dmul ab ;product in acc.
add a,r3 ;compute hex no.
mov 40h,a ;result at 40hsjmp startend