You are on page 1of 10

MICROCONTROLLER IV SEMESTER

ASSEMBLY PROGRAMS

//1a)WAP to move a block of data within the internal RAM Org 0h mov r0,#40h mov r1,#30h mov r2,#5 mov a,@r0 mov @r1,a inc r0 inc r1 djnz r2,start Sjmp Start1 end

start1:

;r0 pointed to internal RAM 40h ;r1 pointing to internal RAM 030h ;r2 loaded with no. of elements in the array ;data transfer

Start:

;decrement r2,if not equal to 0,continue with data ;transfer process.

//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 0h start1: mov dptr,#0500h //data pointer ppointed to external memory //0500h mov r1,#30h //r1 pointing to internal RAM 030h mov r2,#5 //r2 loaded with no. of elements in the array Start: movx A,@dptr mov @r1,a

inc dptr inc r1 djnz r2,start Sjmp Start1 end

////2)WAP to exchange data between internal RAM locations org 0000h mov r0,#30h mov r1,#40h mov r2,#0ah mov a,@r0 mov r3,a mov a,@r1 mov @r0,a mov a,r3 mov @r1,a inc r0 inc r1 djnz r2,start nop sjmp here end

start:

;r0 pointing to 030h(int. RAM) ;r1 pointing to 040h(int. RAM) ;r2 loaded with no. of elements to be exchanged ;data @r0 is stored in temporary reg r3 ;data @r1 is moved to @r0 ;data from r3 is moved to @r1 ;increment data pointers ;decrement counter r2,repeat the process if r2 is not zero

here:

//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 internal RAM org 0000h

num equ 040h back1: mov r0,#50h mov a,r0 mov r1,a mov r3,#04h mov a,r3 mov r2,a back: mov a,@r0 inc r1 mov num,@r1

;store n elements(say n=5) from 50h ;r0 and r1 are used as pointers ;load (n-1) to r3 (no. of passes) ;load r3 to r2(no. of comparison in each pass) ;compare no. pointed to by r0 with no. pointed to by r1

cjne a,num,loop sjmp next loop: jc next ;if num at r0<no. at r1 continue with comparison process //jnc next for descending order mov r4,a ;else exchange the two numbers mov a,@r1 mov @r0,a mov a,r4 mov @r1,a next: inc r0 djnz r2,back ;decrement no. of comparison djnz r3,back1 ;decrement no. of passes end

//4)WAP to find the largest element in ar array stored in the internal RAM. //program for finding the largest element in a given array in the internal RAM org 0000h lar equ 040h start1: mov r0,#50h mov r2,#4h mov lar,@r0 inc r0 mov a,@r0 cjne a,lar,big sjmp next jc next mov lar,@r0 djnz r2,start sjmp here ;array location is 50h pointed to by r0 ;no. of elements in the array ;no. pointed to by r0 loaded to lar ;no. pointed to by r0+1 loaded to acc. ;compare the two no.s ;jump to next if a<lar ;else acc loaded to lar ;decrement count

;location lar stores the largest element in the array

start:

big: next: here:

end

//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 0h start: mov r0,#20h ;r0 pointing to lsb of src1 mov r1,#30h ;r1 pointing to lsb of src2 mov a,@r0 ;add lsb of src1 and src2 add a,@r1 mov 40h,a ;result stored at 40h inc r0 ;r0 pointing to msb of src1 inc r1 ;r0 pointing to msb of src2 mov a,@r0 addc a,@r1 ;add msb of src1 and src2 with carry mov 41h,a ;result stored at 41h mov a,#0h addc a,#0h mov 42h,a ;carry stored at 42h sjmp start end

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 0h here: clr c ;clear carry bit mov r0,#20h ;r0 pointing to lsb of src1 mov r1,#30h ;r1 pointing to lsb of src2 mov a,@r0 ;sub lsb of src2 from lsb of src1 subb a,@r1 mov 40h,a ;result stored at 40h inc r0 ;r0 pointing to msb of src1 inc r1 ;r0 pointing to msb of src2 mov a,@r0 subb a,@r1 ;sub msbs with borrow mov 41h,a ;result stored at 41h sjmp here end 7)pgm for 16 bit multiplication 8)pgm for 16 bit division

//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 0h mov r0,#20H mov a,@r0 ;num in 20h is loaded into acc and b reg mov 0f0h,a mul ab mov 030h,a ;lower order product in 30h mov 031h,0f0h ;higher order product in 31h here: sjmp here end

// Program to convert BCD to ASCII // The equivalent ASCII code will be found in Registers R2 and R6

ORG 00H 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

// Register A contains BCD value

// PROGRAM USING TIMER 0 TO GENERATE TIME DELAY // IT CREATES A SQUARE WAVE OF 50% DUTY CYCLE ON P3.0 BIT ORG 00H

HERE:

MOV TMOD,#01H MOV TL0,#0F2H MOV TH0,#0FFH CPL P3.0 ACALL DELAY SJMP HERE SETB TR0 JNB TF0,AGAIN CLR TR0 CLR TF0 RET END

DELAY: AGAIN:

// PROGRAM TO CONVERT HEX VALUE TO DECIMAL VALUE //

ORG 00H SJMP 30H ORG 30H MOV A,#0Fh MOV B,#0AH DIV AB MOV R0,B DECIMAL VALUE MOV B,#0AH DIV AB MOV R1,B MOV R2,A end // HEX VALUE

// RO,R1,R2 SHOWS THE EQUIVALENT

//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 0h mov r0,#20H mov a,@r0 ;num in 20h is loaded into acc and b reg mov 0f0h,a mul ab ;find the square of the no. mov 0f0h,@r0 mul ab ;multiply square of the no. by the no.to get the cube. mov 030h,a ;lower order product in 30h mov 031h,0f0h ;higher order product in 31h here: sjmp here end

//12)WAP to convert BCD to ASCII org 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 ;ASCII add a,#30h mov 40h,a ;result stored at 40h sjmp start end

//13)WAP to convert given decimal no. to equivalent ASCII org 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 mov r1,a mov a,@r0 anl a,#0f0h swap a mov r2,a ;mask higher nibble ;lower nibble stored at r1 ;mask lower nibble ;exchange higher and lower nibble positions ;higher nibble stored in r2

;process of converting decimal to ASCII mov a,r1

add a,#30h mov 40h,a mov a,r2 add a,#30h mov 41h,a sjmp start end

;40h has ASCII value for lower nibble of decimal no.

;41h has ASCII value for higher nibble of decimal no.

//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 0h start: mov dptr,#5fffh movx a,@dptr mov 0f0h,#064h ;Load B reg with 100d or 64h div ab ;Hundreds inc dptr movx @dptr,a ;store in external ram mov a,0f0h ;remainder from b reg to acc mov 0f0h,#0ah ; Load B reg with 10d or 0ah div ab; inc dptr; movx @dptr,a ;store tens in external ram inc dptr mov a,0f0h movx @dptr,a ;store units in ext ram here: sjmp here end

//15)WAP to convert given dec no. to equivalent hexadecimal no. org 0h start: mov r0,#30h mov a,@r0 ;process of seperating the lower nibble and higher nibble of decimal no. anl a,#0fh mov r1,a mov a,@r0 swap a anl a,#0fh ;mask higher nibble ;lower nibble stored at r1 ;exchange higher and lower nibble position ;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 mov 0f0h,#01h mul ab mov r3,a mov a,r2 mov 0f0h,#0ah mul ab add a,r3 mov 40h,a sjmp start end ;lower nibble to acc ;reg b=01 ;product in r3 ;higher nibble to acc ;reg b=10d ;product in acc. ;compute hex no. ;result at 40h

10

You might also like