Good morning,
May not be correct board, but as near as I could identify.
I have made several games for the grandkids using Arduino and teaching them how to do simpler tasks.
Being quick of brain and wanting to know everything, the question came up "What is the compiled like, that which is sent to Arduino. My question is : Is it possible to print out these 'instructions' codes?. I may not be able to explain them but at least they can be seen and appreciated.
Many thanks
RA.
Click Sketch -> Export compiled Binary in the IDE to save your sketch. In the same folder there will be a file named "xxx.ino.standard.hex", containing hex numbers like this:
:100000000C9453000C947B000C947B000C947B00AC
:100010000C947B000C947B000C947B000C947B0074
:100020000C947B000C947B000C947B000C947B0064
:100030000C947B000C947B000C947B000C947B0054
:100040000C94A1010C947B000C9411020C94EB0114
:100050000C947B000C947B000C947B000C947B0034
:100060000C947B000C947B0000000000250028000D
:100070002B0000000000240027002A0004040404D0
:100080000404040402020202020203030303030342
:10009000010204081020408001020408102001021F
:1000A00004081020F90211241FBECFEFD8E0DEBFF4
:1000B000CDBF11E0A0E0B1E0E6E6F6E002C00590B9
:1000C0000D92A636B107D9F722E0A6E6B1E001C04D
:1000D0001D92AC30B207E1F710E0C3E5D0E004C0F8
:1000E0002197FE010E942603C235D107C9F70E945D
etc...
I'm still searching for a tool to translate this to assembler opcodes...
(edit): "C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-objdump.exe" should do it. I haven't tested it. See also:
Thank you very much Erik,
Even at 6 years old the oldest can make led's blink and turn digital on and off for relays and print to 20 x 4 led display.
If I can help get even one interested into computer practicalities that will make a 76 year old happy.
All the best
RA.
(partial) AVR assembler code produced by the compiler (using -S option)
.file "Tst.ino.cpp"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
.text
.section .text._ZN14HardwareSerial5beginEm,"axG",@progbits,_ZN14HardwareSerial5beginEm,comdat
.weak _ZN14HardwareSerial5beginEm
.type _ZN14HardwareSerial5beginEm, @function
_ZN14HardwareSerial5beginEm:
push r28
push r29
rcall .
rcall .
rcall .
in r28,__SP_L__
in r29,__SP_H__
/* prologue: function */
/* frame size = 6 */
/* stack size = 8 */
.L__stack_usage = 8
std Y+2,r25
std Y+1,r24
std Y+3,r20
std Y+4,r21
std Y+5,r22
std Y+6,r23
ldd r24,Y+3
ldd r25,Y+4
ldd r26,Y+5
ldd r27,Y+6
ldd r30,Y+1
ldd r31,Y+2
ldi r18,lo8(6)
movw r20,r24
movw r22,r26
movw r24,r30
call _ZN14HardwareSerial5beginEmh
nop
/* epilogue start */
adiw r28,6
in __tmp_reg__,__SREG__
cli
out __SP_H__,r29
out __SREG__,__tmp_reg__
out __SP_L__,r28
pop r29
pop r28
ret
.size _ZN14HardwareSerial5beginEm, .-_ZN14HardwareSerial5beginEm
.section .rodata
.type _ZL2SS, @object
.size _ZL2SS, 1
_ZL2SS:
.byte 10
.type _ZL4MOSI, @object
.size _ZL4MOSI, 1
_ZL4MOSI:
.byte 11
.type _ZL4MISO, @object
.size _ZL4MISO, 1
_ZL4MISO:
.byte 12
.type _ZL3SCK, @object
.size _ZL3SCK, 1
_ZL3SCK:
.byte 13
.type _ZL3SDA, @object
.size _ZL3SDA, 1
_ZL3SDA:
.byte 18
.type _ZL3SCL, @object
.size _ZL3SCL, 1
_ZL3SCL:
.byte 19
.type _ZL2A0, @object
.size _ZL2A0, 1
_ZL2A0:
.byte 14
.type _ZL2A1, @object
.size _ZL2A1, 1
_ZL2A1:
.byte 15
.type _ZL2A2, @object
.size _ZL2A2, 1
_ZL2A2:
.byte 16
.type _ZL2A3, @object
.size _ZL2A3, 1
_ZL2A3:
.byte 17
.type _ZL2A4, @object
.size _ZL2A4, 1
_ZL2A4:
.byte 18
.type _ZL2A5, @object
.size _ZL2A5, 1
_ZL2A5:
.byte 19
.type _ZL2A6, @object
.size _ZL2A6, 1
_ZL2A6:
.byte 20
.type _ZL2A7, @object
.size _ZL2A7, 1
_ZL2A7:
.byte 21
.global butPins
.data
.type butPins, @object
.size butPins, 3
butPins:
.byte 15
.byte 16
.byte 17
.global butSt
.section .bss
.type butSt, @object
.size butSt, 3
butSt:
.zero 3
.global butDbnc
.type butDbnc, @object
.size butDbnc, 12
butDbnc:
.zero 12
.global ledPins
.data
.type ledPins, @object
.size ledPins, 4
ledPins:
.byte 10
.byte 11
.byte 12
.byte 13
.global patLed_1
.type patLed_1, @object
.size patLed_1, 6
patLed_1:
.byte 10
.byte 10
.byte 10
.byte 10
.byte 10
.byte 10
.global patDly_1
.type patDly_1, @object
.size patDly_1, 24
patDly_1:
.byte -6
.byte 0
.byte 0
.byte 0
.byte -6
.byte 0
.byte 0
.byte 0
.byte -6
.byte 0
.byte 0
.byte 0
.byte -6
.byte 0
.byte 0
.byte 0
.byte -6
.byte 0
.byte 0
.byte 0
.byte -6
.byte 0
.byte 0
.byte 0
.global patSt_1
.type patSt_1, @object
.size patSt_1, 6
patSt_1:
.byte 0
.byte 1
.byte 0
.byte 1
.byte 0
.byte 1
.global idx
.section .bss
.type idx, @object
.size idx, 2
idx:
.zero 2
.global s
.type s, @object
.size s, 80
s:
.zero 80
.global msec
.type msec, @object
.size msec, 4
msec:
.zero 4
.text
.global setup
.type setup, @function
setup:
push r28
push r29
rcall .
rcall .
in r28,__SP_L__
in r29,__SP_H__
/* prologue: function */
/* frame size = 4 */
/* stack size = 6 */
.L__stack_usage = 6
ldi r20,lo8(-128)
ldi r21,lo8(37)
ldi r22,0
ldi r23,0
ldi r24,lo8(Serial)
ldi r25,hi8(Serial)
call _ZN14HardwareSerial5beginEm
std Y+2,__zero_reg__
std Y+1,__zero_reg__
.L4:
ldd r24,Y+1
ldd r25,Y+2
sbiw r24,3
brsh .L3
ldd r24,Y+1
ldd r25,Y+2
subi r24,lo8(-(butPins))
sbci r25,hi8(-(butPins))
movw r30,r24
ld r24,Z
ldi r22,lo8(2)
call pinMode
ldd r24,Y+1
ldd r25,Y+2
subi r24,lo8(-(butPins))
sbci r25,hi8(-(butPins))
movw r30,r24
ld r24,Z
call digitalRead
mov r18,r24
ldd r24,Y+1
ldd r25,Y+2
subi r24,lo8(-(butSt))
sbci r25,hi8(-(butSt))
movw r30,r24
st Z,r18
ldd r24,Y+1
ldd r25,Y+2
adiw r24,1
std Y+2,r25
std Y+1,r24
rjmp .L4
.L3:
std Y+4,__zero_reg__
std Y+3,__zero_reg__
.L6:
ldd r24,Y+3
ldd r25,Y+4
sbiw r24,4
brsh .L7
ldd r24,Y+3
ldd r25,Y+4
subi r24,lo8(-(ledPins))
sbci r25,hi8(-(ledPins))
movw r30,r24
ld r24,Z
ldi r22,lo8(1)
call digitalWrite
ldd r24,Y+3
ldd r25,Y+4
subi r24,lo8(-(ledPins))
sbci r25,hi8(-(ledPins))
movw r30,r24
ld r24,Z
ldi r22,lo8(1)
call pinMode
ldd r24,Y+3
ldd r25,Y+4
adiw r24,1
std Y+4,r25
std Y+3,r24
rjmp .L6
.L7:
nop
/* epilogue start */
pop __tmp_reg__
pop __tmp_reg__
pop __tmp_reg__
pop __tmp_reg__
pop r29
pop r28
ret
.size setup, .-setup
.local _ZZ7patternPhPmS_PiiE7msecLst
.comm _ZZ7patternPhPmS_PiiE7msecLst,4,1
.section .rodata
.LC0:
.string "%s: begin idx %d, msec %ld"
.text
.global _Z7patternPhPmS_Pii
.type _Z7patternPhPmS_Pii, @function
_Z7patternPhPmS_Pii:
push r16
push r17
push r28
push r29
in r28,__SP_L__
in r29,__SP_H__
sbiw r28,10
in __tmp_reg__,__SREG__
cli
out __SP_H__,r29
out __SREG__,__tmp_reg__
out __SP_L__,r28
/* prologue: function */
/* frame size = 10 */
/* stack size = 14 */
.L__stack_usage = 14
std Y+2,r25
std Y+1,r24
std Y+4,r23
std Y+3,r22
std Y+6,r21
std Y+5,r20
std Y+8,r19
std Y+7,r18
std Y+10,r17
std Y+9,r16
ldd r24,Y+7
ldd r25,Y+8
movw r30,r24
ld r24,Z
ldd r25,Z+1
ldd r18,Y+9
ldd r19,Y+10
cp r24,r18
cpc r25,r19
brlt .+2
rjmp .L12
ldd r24,Y+7
ldd r25,Y+8
movw r30,r24
ld r24,Z
ldd r25,Z+1
or r24,r25
brne .L11
lds r24,_ZZ7patternPhPmS_PiiE7msecLst
lds r25,_ZZ7patternPhPmS_PiiE7msecLst+1
lds r26,_ZZ7patternPhPmS_PiiE7msecLst+2
lds r27,_ZZ7patternPhPmS_PiiE7msecLst+3
or r24,r25
or r24,r26
or r24,r27
brne .L11
lds r24,msec
lds r25,msec+1
lds r26,msec+2
lds r27,msec+3
sts _ZZ7patternPhPmS_PiiE7msecLst,r24
sts _ZZ7patternPhPmS_PiiE7msecLst+1,r25
sts _ZZ7patternPhPmS_PiiE7msecLst+2,r26
sts _ZZ7patternPhPmS_PiiE7msecLst+3,r27
ldd r24,Y+7
ldd r25,Y+8
movw r30,r24
ld r24,Z
ldd r25,Z+1
movw r18,r24
ldd r24,Y+5
ldd r25,Y+6
add r24,r18
adc r25,r19
movw r30,r24
ld r20,Z
ldd r24,Y+7
ldd r25,Y+8
movw r30,r24
ld r24,Z
ldd r25,Z+1
movw r18,r24
ldd r24,Y+1
ldd r25,Y+2
add r24,r18
adc r25,r19
movw r30,r24
ld r24,Z
mov r22,r20
call digitalWrite
rjmp .L8
If you click on compile the IDE starts arduino-builder which runs the toolchain with respect to the options set in the preferences file.
If you show "verbose output" you'll notice that there is a call to avr-size at the end of the compilation which returns the space requirements of your sketch.
I have renamed avr-size.exe on windows and replaced it by a batch script which automatically generates the .asm code from the .elf file and then invokes the original avr-size command to create the regular IDE output.
This way I always have the assembler output at hand without any extra hassle if I want to see what the compiler created from the source code.
@echo OFF
SET SIZEcmd="%USERPROFILE%\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\bin\avr-size_orig.exe"
SET DUMPcmd="C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-objdump.exe"
SET DUMPopts=-S -h -l
SET ELFfile=%~f2
SET TEMPdir=%~dp2
%DUMPcmd% %DUMPopts% %ELFfile% > "%ELFfile%".asm
%SIZEcmd% %*
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.