Anda di halaman 1dari 3

1.

Counting 1s in a 32 bit ARM register:

#includbe<LPC17xx.h>
int main() MOVS r2,#0x0F
{ MOVS r3,#0x00
unsigned int a,b,c,i; MOVS r0,#0x00
a=15; B LOOP1
b=0; LOOP2 LSR r1,r2,r0
for(i=0;i<32;i++) TST r1,#0x01
{ BEQ LOOP3
c = a >> i; ADDS r3,r3,#1
if( c & 0x01 ) LOOP3 ADDS r0,r0,#1
b=b+1; LOOP1 CMP r0,#0x20
} BCC LOOP2
while(1); LOOP4 B LOOP4
}

2. Binary Sequence
000000001
000000010
000000100
..
...
100000000
000000000

a=1;
for(i=0;i<32;i++)
a=a<<1;

0x000001A4 MOVS r1,#0x01


0x000001AA B 0x000001B0
0x000001AC LSLS r1,r1,#1
0x000001AE ADDS r0,r0,#1
0x000001B0 CMP r0,#0x20
0x000001B2 BCC 0x000001AC

3. If statement

if(a>b)
{
Body of the condition statement
}
a=a>>12;

CMP r0,r1
BLS LOOP1
;; Body of the condition statement
LOOP1 LSRS r0,r0,#12

a<b BCS LOOP1


a==b BNE LOOP1
a!=b BEQ LOOP1
a>=b BCC LOOP1
a<=b BHI LOOP1
4. If else statement

if(a>b)
{ Body of the true condition statement
}
else
{ Body of the false condition statement
}
a=a*50;

CMP r0,r1
BHI loop1
;;;Body of the true condition statement
----------------------------------------
B loop2
loop1 ;;;Body of the false condition statement
----------------------------------------
loop2 MOV r3,#0x32
MULS r0,r3,r0

5. If else statement with two conditions

if((a<=b)&&(a>=c))
{ Body of the true condition statement
}
else
{ Body of the false condition statement
}
a=a*50;

CMP r0,r1
BHI loop1
CMP r0,r2
BCC loop1
;;;Body of the true condition statement
----------------------------------------------
B loop2
loop1 ;;;Body of the false condition statement
----------------------------------------
loop2 MOV r3,#0x32
MULS r0,r3,r0

if((a<=b)||(a>=c))
{ Body of the true condition statement
}
else
{ Body of the false condition statement
}
a=a*50;

CMP r0,r1
BLS loop3
CMP r0,r2
BCC loop1
loop3 ;;;Body of the true condition statement
----------------------------------------------
B loop2
loop1 ;;;Body of the false condition statement
----------------------------------------
loop2 MOV r3,#0x32
MULS r0,r3,r0

6. For loop

for(c=0;c<30;c++)
{
Body of the loop
}
a=a*50;

MOVS r1,#0x00
B loop1
loop2 ;;;;; body of the loop
ADDS r1,r1,#1
loop1 CMP r1,#0x1E
BCC loop2
MOV r3,#0x32
MULS r0,r3,r0

7. While loop

int a=30;
while(a>0)
{
a=a-1;
}

0x000001A4 MOVS r1,#0x1E


0x000001A6 B 0x000001AA
0x000001A8 SUBS r1,r1,#1 ;; body of the loop
0x000001AA CMP r1,#0x00 ;; condition check
0x000001AC BGT 0x000001A8

8. Do while loop

int a=30;
do
{
a=a-1;
}while(a>0);

0x000001A4 MOVS r1,#0x1E


0x000001A8 SUBS r1,r1,#1
0x000001AA CMP r1,#0x00
0x000001AC BGT 0x000001A8

Anda mungkin juga menyukai