> Sitting here in Knoxville, and I find myself
pondering the question of
> which MSP430 compiler was used to generate a particular piece of object
> code that sits before me. As this is a common question for me, I'd
like
> to automate the process.
>
> To that end, I'd be ever so grateful if a few of you would send me a
> compiled binary of the following C program from your favorite compiler.
> This will give me examples of the integer calling convention and a
> switch(){}.
>
> http://pastebin.com/f3643b46 Samples should be
sent in the ihex format, with compiler version
> information, to t...@utk.edu . Target any
> chip you like, and make any
> changes necessary to get this to compile. Extra credit if I've not
> heard of the compiler you use.
>
> Personal observations of the differences in compiler output are also
> welcome.
>
> Cheers,
> --Travis
>
> short foo(short a, short b, short c){
> return a+c;
> }
>
> short bar(short a){
> switch(a){
> case 0:
> return abs(5);
> case 1:
> break;
> case 2:
> case 3:
> return 256;
> }
> return 32;
> }
>
> void main(){
> short a;
> foo(1,2,3);
> bar(a);
> while(1);
> }
Hi Travis!
Ok, here comes the IAR compiler, I just compiled this with the
--discard_unused_publics flag, and ended up with:
main:
MOV.W #0x5, R12
CALL #abs
??main_0:
JMP ??main_0
Clearly, this is not optimal since we all know that "abs" does not have
side effects. So I took the liberty of adding the line "#include
" and ended up with the following:
main:
??main_0:
JMP ??main_0
OK, ok -- using the --discard_unused_publics option is a bit like
cheating, I know, so here comes the real result:
3 short foo(short a, short b, short c){
\ foo:
4 return a+c;
\ 000000 0C5E ADD.W R14, R12
\ 000002 3041 RET
5 }
6
\ In segment CODE, align 2
20 void main(){
\ main:
21 short a;
22 foo(1,2,3);
23 bar(a);
^
Warning[Pe549]: variable "a" is used before its value is set
\ 000000 3C400500 MOV.W #0x5, R12
\ 000004 B012.... CALL #abs
24 while(1);
\ ??main_0:
\ 000008 FF3F JMP ??main_0
25 }
Please note that the call to "bar" from main has been optimized away, so
the linker would not include "foo" and "bar" in case no other part of
your application used them.
Again, you could get rid of the calls to "abs" by including the right
header file...
-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.
AQ430 C 2008/06/30:
; Archelon URCC C 3.27 2008/06/30
; MSP430 CIF 2008/01/07
; Compiled "travis.c" Sat Jul 26 00:00:47 2008
;
; short foo(short a, short b, short c){
.pseg travis_code
.global _foo
_foo:
; ENTRY
; a at argloc 0 (0x0) in reg size 2
; c at argloc 0 (0x0) in reg size 2
; return a+c;
add r14,r12
; EXIT
ret
; }
; ****** Warning: Symbol ``b'' (function foo) was defined, but not
used
; short bar(short a){
.iseg travis_data_const
.align 0x2
.align 0x2
bar_LL4:
.data bar_L3
.data bar_L4
.data bar_L5
.data bar_L6
.pseg travis_code
.global _bar
_bar:
; ENTRY
; a at argloc 0 (0x0) in reg size 2
; switch(a){
jmp bar_L2
; case 0:
bar_L3:
; return abs(5);
mov #0x5,r12
call #_abs
jmp bar_LL2
; case 1:
bar_L4:
; break;
jmp bar_L1
; case 2:
bar_L5:
; case 3:
bar_L6:
; return 256;
mov #0x100,r12
jmp bar_LL2
bar_L2:
; swcode: switch has 4 cases - min 0 max 3
mov #0x3,r13
cmp r12,r13
jnc bar_LL3
rla r12
br bar_LL4(r12)
bar_LL3:
bar_L1:
; }
; return 32;
mov #0x20,r12
bar_LL2:
; EXIT
ret
; }
; void main(){
.global _main
_main:
; ENTRY
; a in reg size 2
; short a;
; foo(1,2,3);
mov #0x3,r14
mov #0x2,r13
mov #0x1,r12
call #_foo
; bar(a);
; }
; ****** Warning: Uninitialized variable "a" in main()
mov r4,r12
call #_bar
; while(1);
main_L1:
jmp main_L1
; EXIT
; .temp0 at stkloc 0 (0x0) size 2
ret
.extern _abs
Reply by Matthias Weingart●July 25, 20082008-07-25
> Howdy Y'all,
>
> Sitting here in Knoxville, and I find myself pondering the question of
> which MSP430 compiler was used to generate a particular piece of object
> code that sits before me. As this is a common question for me, I'd
like
> to automate the process.
>
> To that end, I'd be ever so grateful if a few of you would send me a
> compiled binary of the following C program from your favorite compiler.
> This will give me examples of the integer calling convention and a
> switch(){}.
>
> http://pastebin.com/f3643b46
>
> Samples should be sent in the ihex format, with compiler version
> information, to t...@utk.edu. Target any chip you like, and make any
> changes necessary to get this to compile. Extra credit if I've not
> heard of the compiler you use.
>
> Personal observations of the differences in compiler output are also
> welcome.
>
> Cheers,
> --Travis
> short foo(short a, short b, short c){
> return a+c;
> }
>
> short bar(short a){
> switch(a){
> case 0:
> return abs(5);
> case 1:
> break;
> case 2:
> case 3:
> return 256;
> }
> return 32;
> }
>
> void main(){
> short a;
> foo(1,2,3);
> bar(a);
> while(1);
> }
>
Reply by old_cow_yellow●July 24, 20082008-07-24
I am pretending to be a c-compiler ;-)
My compiled object code consists of a single instruction:
JMP $
--- In m..., Travis Goodspeed wrote: >
> Howdy Y'all,
>
> Sitting here in Knoxville, and I find myself pondering the question of
> which MSP430 compiler was used to generate a particular piece of object
> code that sits before me. As this is a common question for me, I'd
like
> to automate the process.
>
> To that end, I'd be ever so grateful if a few of you would send me a
> compiled binary of the following C program from your favorite compiler.
> This will give me examples of the integer calling convention and a
> switch(){}.
>
> http://pastebin.com/f3643b46
>
> Samples should be sent in the ihex format, with compiler version
> information, to travis@... Target any chip you like, and make any
> changes necessary to get this to compile. Extra credit if I've not
> heard of the compiler you use.
>
> Personal observations of the differences in compiler output are also
> welcome.
>
> Cheers,
> --Travis
> short foo(short a, short b, short c){
> return a+c;
> }
>
> short bar(short a){
> switch(a){
> case 0:
> return abs(5);
> case 1:
> break;
> case 2:
> case 3:
> return 256;
> }
> return 32;
> }
>
> void main(){
> short a;
> foo(1,2,3);
> bar(a);
> while(1);
> }
>
Reply by Travis Goodspeed●July 24, 20082008-07-24
Howdy Y'all,
Sitting here in Knoxville, and I find myself pondering the question of
which MSP430 compiler was used to generate a particular piece of object
code that sits before me. As this is a common question for me, I'd like
to automate the process.
To that end, I'd be ever so grateful if a few of you would send me a
compiled binary of the following C program from your favorite compiler.
This will give me examples of the integer calling convention and a
switch(){}.
Samples should be sent in the ihex format, with compiler version
information, to t...@utk.edu. Target any chip you like, and make any
changes necessary to get this to compile. Extra credit if I've not
heard of the compiler you use.
Personal observations of the differences in compiler output are also
welcome.
Cheers,
--Travis
short foo(short a, short b, short c){
return a+c;
}
short bar(short a){
switch(a){
case 0:
return abs(5);
case 1:
break;
case 2:
case 3:
return 256;
}
return 32;
}
void main(){
short a;
foo(1,2,3);
bar(a);
while(1);
}