I want to get an insight into the code that is generated by the compiler. Since I am quite new to ARM assembly code I have some questions. I compile the following (nosense) test-program on the Teensy40:
The code generated is:
I have the following questions: What is the purpose of the code generated by the many .short directives? Why does the source-code appear two times in the assembly listing? Is the code generated two times? If so, why?
Code:
volatile int a,b,c ;
volatile int kStop ;
void setup() {
Serial.begin(9600);
delay(1000) ;
Serial.print("Hello teensy40armDisasm0\n");
kStop=0 ;
while(1){
a=a+0x1234 ;
b=a+0x5678 ;
xstop() ;
}
Serial.print("end setup....\n");
}
void xstop(){
Serial.printf("a=%08XH b=%08XH\n",a,b) ;
kStop++ ;
if(kStop>3){
while(1){} ;
}
}
void loop(){
}
The code generated is:
Code:
void setup() {
b4: b508 push {r3, lr}
Serial.begin(9600);
delay(1000) ;
b6: f44f 707a mov.w r0, #1000 ; 0x3e8
ba: 4c0c ldr r4, [pc, #48] ; (ec <setup+0x38>)
bc: f000 f838 bl 130 <delay>
virtual int read() { return usb_serial_getchar(); }
virtual int peek() { return usb_serial_peekchar(); }
virtual void flush() { usb_serial_flush_output(); } // TODO: actually wait for data to leave USB...
virtual void clear(void) { usb_serial_flush_input(); }
virtual size_t write(uint8_t c) { return usb_serial_putchar(c); }
virtual size_t write(const uint8_t *buffer, size_t size) { return usb_serial_write(buffer, size); }
c0: 480b2119 .word 0x480b2119
c4: f000 ffbe bl 1044 <usb_serial_write>
c8: 4b0b4d0a .word 0x4b0b4d0a
Serial.print("Hello teensy40armDisasm0\n");
kStop=0 ;
cc: 2200 movs r2, #0
ce: 601a .short 0x601a
while(1){
a=a+0x1234 ;
d0: 6821 ldr r1, [r4, #0]
d2: f241 .short 0xf241
d4: 2234 movs r2, #52 ; 0x34
b=a+0x5678 ;
d6: f245 .short 0xf245
d8: 6378 str r0, [r7, #52] ; 0x34
Serial.begin(9600);
delay(1000) ;
Serial.print("Hello teensy40armDisasm0\n");
kStop=0 ;
while(1){
a=a+0x1234 ;
da: 440a .short 0x440a
dc: 6022 str r2, [r4, #0]
b=a+0x5678 ;
de: 6822 .short 0x6822
e0: 4413 add r3, r2
e2: 602b .short 0x602b
xstop() ;
e4: f7ff ffca bl 7c <xstop()>
e8: bf00e7f2 .word 0xbf00e7f2
ec: 0ddc lsrs r4, r3, #23
ee: 2000 .short 0x2000
f0: 0014 movs r4, r2
f2: 2000 movs r0, #0
f4: 20000de0 .word 0x20000de0
f8: 0de4 lsrs r4, r4, #23
fa: 2000 movs r0, #0
000000fc <loop>:
if(kStop>3){
while(1){} ;
}
}
void loop(){
fc: bf004770 .word 0xbf004770
I have the following questions: What is the purpose of the code generated by the many .short directives? Why does the source-code appear two times in the assembly listing? Is the code generated two times? If so, why?