Norcroft ARM C 1.50A Aug 7 1987 |v$codeseg| 000000 ea000000 B |__main| /* ! ! The hand-generated code below should be producable by PSR's compiler if it: ! A) delays stores as late as possible ! ! B) remembers registers over procedure calls ! ! C) has a general algorithm for drop-through conditionally executed ! instructions, i.e. if there are no instructions between a conditional ! branch and its destination which set the condition codes, and the ! sequence is less that a certain length, then all the instructions ! within the sequence can be made conditional. ! ! D) does as above, but also allows instructions within the sequence ! whose subsequent execution depends on the same condition, e.g. ! ! %if a=b %and c=d %then a=b ! ! CmpS R0,R1 NAIVE STYLE ! Bne elsepart ! Cmps R2,R3 ! Bne elsepart ! Mov R0,R2 ! ! CmpS R0,R1 RULE (C) ABOVE ! Bne elsepart ! CmpS R2,R3 ! MovEQ R0,R2 ! ! CmpS R0,R1 RULE (D) SPECIAL CASE ! CmpSEQ R2,R3 ! MovEQ R0,R2 ! ! E) alters conditions to generate similar condition codes on ! condition AND condition AND condition to generate more cases ! to which rule (D) can be applied. ! ! F) adjusts constants in < or <= cases to favour above, i.e. turning ! CMP R,#const & BLE ... into CMP R,#const-1 & BLT ... etc. ! ! G) changes Newline back from the current implicit printsymbol(10) - ! there is no run-time overhead in moving the MOV R0,#10 over to ! the procedure body instead of having it in every call where it ! takes up space - after all, Peter's code-moving stuff ought to ! get %permroutine newline;printsymbol(10);%end correct - it will ! place the Mov R0,#10 before the body of %permroutine printsymbol ! and generate a suitable entry point for it... ! Personally, I would recommend stacking/restoring R0 as well ! as it might keep another variable in a register for a bit longer... ! ! I've only suggested optimisations which fit into the style of PSR's ! compilers... ! */ extern int readnum(void); extern void write(int num, int pl); extern void newline(void); void main(void) { 000004 6e69616d DCB &6d,&61,&69,&6e ; 'main' 000008 00000000 DCB &00,&00,&00,&00 ; '\0\0\0\0' 00000c ff000008 DCD &ff000008 main , line 59, Warning: extern 'main' needs to be 'int' function int a,i,b; 000010 e1a0b00c MOV ip, sp 000014 e92cccf0 STMFD sp!, {v1,v2,v3,v4,fp,ip,lk,pc} 000018 e24ba004 SUB fp, ip, #4 ; 00000004 00001c e15c000d CMPS sp, sl 000020 3b000000 BLCC |x$stack_overflow| a = readnum(); 000024 e3a04000 MOV v1, #0 ; 00000000 000028 eb000000 BL readnum i = readnum(); 00002c e1a07000 MOV v4, a1 000030 eb000000 BL readnum b = readnum(); 000034 e1a05000 MOV v2, a1 000038 eb000000 BL readnum 00003c e1a06000 MOV v3, a1 if ((a <= i) && (i <= b)) { 000040 e1570005 CMPS v4, v2 000044 ca000001 BGT main+&40 ; 00000001 000048 e1550006 CMPS v2, v3 i = 22; 00004c d3a05016 MOVLE v2, #22 ; 00000016 }; if ((22 <= i) && (i <= b)) { 000050 e3550016 CMPS v2, #22 ; 00000016 000054 ba000001 BLT main+&50 ; 00000001 000058 e1550006 CMPS v2, v3 i = 44; 00005c d3a0502c MOVLE v2, #44 ; 0000002C }; if ((a <= i) && (i <= 77)) { 000060 e1570005 CMPS v4, v2 000064 ca000001 BGT main+&60 ; 00000001 000068 e355004d CMPS v2, #77 ; 0000004D i = 99; 00006c d3a05063 MOVLE v2, #99 ; 00000063 }; if ((11 <= i) && (i <= 100)) { 000070 e355000b CMPS v2, #11 ; 0000000B 000074 ba000001 BLT main+&70 ; 00000001 000078 e3550064 CMPS v2, #100 ; 00000064 i = 1; 00007c d3a05001 MOVLE v2, #1 ; 00000001 }; write(a,0); 000080 e1a00007 MOV a1, v4 000084 e1a01004 MOV a2, v1 000088 eb000000 BL write newline(); 00008c eb000000 BL newline write(i,0); 000090 e1a00005 MOV a1, v2 000094 e1a01004 MOV a2, v1 000098 eb000000 BL write newline(); 00009c eb000000 BL newline write(b,0); 0000a0 e1a00006 MOV a1, v3 0000a4 e1a01004 MOV a2, v1 0000a8 eb000000 BL write 0000ac e91a54f0 LDMEA fp, {v1,v2,v3,v4,fp,sp,lk} newline(); 0000b0 ea000000 B newline }; , line 89, Error: declaration with no effect AREA |C$$data| |v$dataseg| EXPORT main IMPORT newline IMPORT write IMPORT readnum IMPORT |x$stack_overflow| IMPORT |__main| END : 1 warning, 1 error, 0 serious errors.