Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Thu May 04, 2006 8:42 am |
|
|
Compare the assembled code for the following.
Code: | for (x=0;x<5;x++)
{ x=y;
}
x=0;
x=1;
x=2;
x=3;
x=4;
for (x=0;x<10;x++)
{ x=y;
}
x=0;
x=1;
x=2;
x=3;
x=4;
x=5;
x=6;
x=7;
x=8;
x=9;
|
Code: | .................... Int8 x,y;
....................
.................... for (x=0;x<5;x++)
0680: CLRF 4B
0682: MOVF 4B,W
0684: SUBLW 04
0686: BNC 0690
.................... { x=y;
0688: MOVFF 4C,4B
.................... }
068C: INCF 4B,F
068E: BRA 0682
....................
.................... x=0;
0690: CLRF 4B
.................... x=1;
0692: MOVLW 01
0694: MOVWF 4B
.................... x=2;
0696: MOVLW 02
0698: MOVWF 4B
.................... x=3;
069A: MOVLW 03
069C: MOVWF 4B
.................... x=4;
069E: MOVLW 04
06A0: MOVWF 4B
....................
.................... for (x=0;x<10;x++)
06A2: CLRF 4B
06A4: MOVF 4B,W
06A6: SUBLW 09
06A8: BNC 06B2
.................... { x=y;
06AA: MOVFF 4C,4B
.................... }
06AE: INCF 4B,F
06B0: BRA 06A4
....................
.................... x=0;
06B2: CLRF 4B
.................... x=1;
06B4: MOVLW 01
06B6: MOVWF 4B
.................... x=2;
06B8: MOVLW 02
06BA: MOVWF 4B
.................... x=3;
06BC: MOVLW 03
06BE: MOVWF 4B
.................... x=4;
06C0: MOVLW 04
06C2: MOVWF 4B
.................... x=5;
06C4: MOVLW 05
06C6: MOVWF 4B
.................... x=6;
06C8: MOVLW 06
06CA: MOVWF 4B
.................... x=7;
06CC: MOVLW 07
06CE: MOVWF 4B
.................... x=8;
06D0: MOVLW 08
06D2: MOVWF 4B
.................... x=9;
06D4: MOVLW 09
06D6: MOVWF 4B
|
If you start looking at the assembled code from the C code you write you will get a feel for the way to make code run fast ,use less space or easy to read. It is a big advantage to know how the C you write will assemble. |
|