All Programs

download All Programs

If you can't read please download the document

description

good one

Transcript of All Programs

1. move a block of 8 dat words from 0010 to 0030 mov.w #0010h, r5; point r5 to 0010 mov.w #0030h, r6; point r6 to 0030 mov #08, r7 ; couter for number of wordsup: mov.w @r5, 0(r6); mov data from @r5 to @r6 incd.w r5; point to next memory location incd.w r6; point to next memory location dec.w r7; decrement counter jnz up; jump up

2. move a block of 8 dat bytes from 0010 to 0030 mov.w #0010h, r5 ; point r5 to 0010 mov.w #0030h, r6 ; point r6 to 0030 mov #08, r7 ; couter for number of bytesup: mov.b @r5, 0(r6) ; mov data from @r5 to @r6 incd.w r5 ; point to next memory location incd.w r6 ; point to next memory location dec.w r7 ; decrement counter jnz up ; jump up

3.ALP to multiply a number by 2,4,8... mov.w #0Ah, r5 ; take the number to be multiplied by 2 4 ..in r5 mov.w #3h, r6 ; counter for 2 4 ... r6 = r6*r5= 0A*3 = 1Ehup: rla r5 ; multiply by 2 dec.w r6 ; dec the counter jnz up ; repeat until the counter is zero

4.Exchange 2 block of 5 words at 0020 and 0030 mov.w #0020h, r5 ; point r5 to 0020 mov.w #0030h, r6 ; point r6 to 0030 mov.w #05h, r7 ; counter for number of wordsup: mov @r5, r8 ; Take @r5 content to temp register mov @r6, 0(r5) ; mov @r6 content into @r5 mov r8, 0(r6) ; mov temp reg content into @r6 incd.w r5 ; point r5 to next memory location incd.w r6 ; point r6 to next memory location dec r7 ; decrement the counter jnz up ; repeat until the counter is zero

5.ALP to find largest number in an array of 10 elements at 0040 mov.w #0040h, r5 ; point r5 to given memory location mov.w @r5, r6 ; r6 will be used to hold largest num mov.w #0Ah, r7 ; counter for number of wordsup: incd.w r5 ; Take @r5 content to temp register cmp.w @r5, r6 ; mov @r6 content into @r5 jhs DOWN ; do nothing if r6 > @r5 mov @r5, r6 ; take higher num in r6DOWN: dec r7 ; decrement the counter jnz up ; repeat until the counter is zero

6.ALP to arrange numbers in ascending order mov.w #0Ah, r7 ; counter for number of wordsup1: mov.w #0040h, r5 ; point r5 to given memory location mov.w #09h, r8 ; counter for inner loop up2: cmp.w @r5, 2(r5) ; compare r5 and (r5+2) jhs DOWN ; jump down mov @r5, r6 ; move @r5 to temp mov 2(r5), 0(r5) ; move (r5+2) to @r5 mov r6, 2(r5) ; move temp to (r5+2)DOWN: incd.w r5 ; r5 points to next word memory location dec r8 ; decrement the inner counter jnz up2 ; repeat until the counter is zero dec r7 ; decrement the outer counter jnz up1 ; jump to up1

7. ALP to determine cube of a 16 bit number; r8 is used hold the MS word and r6 holds the LS word of the result; for a given number=00AA the result is r8=4A r6=F768 mov.w #0000h, r8 ; for MS word result mov.w #00AAh, r5 ; take given number in r5 mov.w #02h, r9 ; counter for outer loopup1: mov.w #00AAh, r7 ; counter for inner loop mov.w #0000h, r6 ; clear r6 up2: add.w r5, r6 ; add r5 to r6 jnc DOWN ; jump on no carry to DOWN inc.w r8 ; increment MS wordDOWN: dec.w r7 ; decrement the inner counter jnz up2 ; repeat until the counter is zero mov.w r6, r5 ; take the sum in r5 dec.w r9 ; decrement the outer counter jnz up1 ; repeat until the counter is zero

8a. multiply 2 16-bit numbers; r5 and r6 hold the 2 16- bit numbers and result will be in r8 and r6; example=> r5 = 0xaaaa and r6=55h, result is 38AA72 r8=38 and r6=AA72 mov.w #0000h, r8 ; for MS word result mov.w #0xAAAA, r5 ; take given number in r5 mov.w #55h, r7 ; take another number in r7, counter for inner loop mov.w #0000h, r6 ; clear r6 up: add.w r5, r6 ; add r5 to r6 jnc DOWN ; jump DOWN inc.w r8 ; increment MS WordDOWN: dec.w r7 ; decrement the inner counter jnz up ; repeat until the counter is zero

8b.Division of 2 16-bit numbers; r5=478d and r6=44d ; r8=r5/r6=487/44 = 11 mov.w #487d, r5 ; take given dividend number in r5 which is x for x/y mov.w #44d , r6 ; divider i.e y for x/y operation mov.w #0001h, r8 ; initialize result mov.w #0000h, r7 ; clear r7 cmp.w r5, r6 ; check if r5 > r6 jhs DOWN ; jump to DOWN up: subc.w r6, r5 ; subtract r6 from r6 inc.w r7 ; increment the counter cmp r6, r5 ; check if r5 > r6 jhs up ; jump up if r5 > r6 mov r7, r8 ; move result to r8DOWN

9a. ALP to set individual bits in a given word @0030 and stote result into 0032; @r5 has given number ; r6 has info on which bit is to be set;example @r5 = 0A and 5th bit is to be set, then result @r7 = 1A mov.w #0030h, r5 ; point r5 to 0x0030 mov.w #0032h, r7 ; point r7 to 0x0032 mov.w #0Ah, 0(r5) ; take given number in @r5 mov.w #05h, r6 ; give 1 for 0th bit 2 for 1st bit, 3 for 2rd bit... mov.w #01h,r8 ; bit set patternup: dec r6 ; decrement the counter jz down ; jump down rla r8 ; rotate r8 left jmp up ; jump updown: bis.w r8, 0(r5) ; set required bit in @r5 mov.w @r5, 0(r7) ; mov result to 0032

9b. ALP to set or clear individual bits in a given word @0030 and store result into 0032; @r5 has given number ; r6 has info on which bit is to be cleared; example @r5 = 0A and 4th bit is to be cleared, then result @r7 = 02

mov.w #0030h, r5 ; point r5 to 0x0030 mov.w #0032h, r7 ; point r7 to 0x0032 mov.w #0Ah, 0(r5) ; take given number in @r5 mov.w #04h, r6 ; give 1 for 0th bit 2 for 1st bit, 3 for 2rd bit... mov.w #01h,r8 ; bit clear patternup: dec r6 ; decrement the counter jz down ; jump down rla r8 ; rotate r8 left jmp up ; jump updown: bic.w r8, 0(r5) ; clear required bit in @r5 mov.w @r5, 0(r7) ; mov result to 0032

10a. ALP to compule A + BC; r5 = 0Ah, r6 = 05h, r7=0Ah ;result => r7 | (r6 & r5) =0Ah mov.w #0Ah, r5 ; take C in r5 mov.w #05h, r6 ; take B in r6 mov.w #0Ah, r7 ; take A in r7 and.w r5,r6 ; perform BC bis.w r7, r6 ; perform A + BC

10b. ALP to compute ~AC + ~ AB; r5 = 0Ah, r6 = 05h, r7=0Ah ; result => ~(r7 &r6) | ~(r7 & r5) =FFFFh mov.w #0Ah, r5 ; take C in r5 mov.w #05h, r6 ; take B in r6 mov.w #0Ah, r7 ; take A in r7 and.w r7,r5 ; perform AC inv.w r5 ; perform ~AC and.w r7,r6 ; perform AB inv.w r6 ; perform ~AB bis.w r5, r6 ; perform ~AB+~AC