Created
June 23, 2017 01:54
-
-
Save C47D/980c0731a223a6da2da45208b04591e1 to your computer and use it in GitHub Desktop.
Iterate over an array using C++11 "approach"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// cpp_array.cpp | |
#include <array> | |
#include <iostream> | |
#include <stdint.h> | |
int main(void) | |
{ | |
const std::array<std::uint8_t, 10> array_cpp = | |
{ 0x01, 0x02, 0x03, 0x04, 0x05, | |
0x06, 0x07, 0x08, 0x09, 0x0A }; | |
// range-based for loop | |
for (const auto& s: array_cpp) { | |
std::cout << unsigned(s) << '\n'; | |
} | |
return 0; | |
} | |
/** | |
* Result: | |
* Toolchain: arm-none-eabi-g++ (GNU Tools for ARM Embedded Processors 6-2017-q2-update) 6.3.1 20170215 | |
* Compile: arm-none-eabi-g++ -S cpp_array.cpp -mthumb -mcpu=cortex-m4 -O3 -std=c++11 -fno-exceptions | |
*/ | |
.cpu cortex-m4 | |
.eabi_attribute 20, 1 | |
.eabi_attribute 21, 1 | |
.eabi_attribute 23, 3 | |
.eabi_attribute 24, 1 | |
.eabi_attribute 25, 1 | |
.eabi_attribute 26, 1 | |
.eabi_attribute 30, 2 | |
.eabi_attribute 34, 1 | |
.eabi_attribute 18, 4 | |
.file "cpp_array.cpp" | |
.section .text.startup,"ax",%progbits | |
.align 1 | |
.p2align 2,,3 | |
.global main | |
.syntax unified | |
.thumb | |
.thumb_func | |
.fpu softvfp | |
.type main, %function | |
main: | |
@ args = 0, pretend = 0, frame = 16 | |
@ frame_needed = 0, uses_anonymous_args = 0 | |
push {r4, r5, r6, r7, lr} | |
ldr r3, .L6 | |
ldr r7, .L6+4 | |
ldm r3, {r0, r1, r2} | |
sub sp, sp, #20 | |
add r3, sp, #4 | |
stmia r3!, {r0, r1} | |
add r4, sp, #4 | |
strh r2, [r3] @ movhi | |
add r6, sp, #14 | |
movs r5, #10 | |
.L2: | |
ldrb r1, [r4], #1 @ zero_extendqisi2 | |
mov r0, r7 | |
bl _ZNSo9_M_insertImEERSoT_ | |
movs r2, #1 | |
add r1, sp, #3 | |
strb r5, [sp, #3] | |
bl _ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_i | |
cmp r4, r6 | |
bne .L2 | |
movs r0, #0 | |
add sp, sp, #20 | |
@ sp needed | |
pop {r4, r5, r6, r7, pc} | |
.L7: | |
.align 2 | |
.L6: | |
.word .LANCHOR0 | |
.word _ZSt4cout | |
.size main, .-main | |
.align 1 | |
.p2align 2,,3 | |
.syntax unified | |
.thumb | |
.thumb_func | |
.fpu softvfp | |
.type _GLOBAL__sub_I_main, %function | |
_GLOBAL__sub_I_main: | |
@ args = 0, pretend = 0, frame = 0 | |
@ frame_needed = 0, uses_anonymous_args = 0 | |
push {r4, lr} | |
ldr r4, .L10 | |
mov r0, r4 | |
bl _ZNSt8ios_base4InitC1Ev | |
mov r0, r4 | |
ldr r2, .L10+4 | |
ldr r1, .L10+8 | |
pop {r4, lr} | |
b __aeabi_atexit | |
.L11: | |
.align 2 | |
.L10: | |
.word .LANCHOR1 | |
.word __dso_handle | |
.word _ZNSt8ios_base4InitD1Ev | |
.size _GLOBAL__sub_I_main, .-_GLOBAL__sub_I_main | |
.section .init_array,"aw",%init_array | |
.align 2 | |
.word _GLOBAL__sub_I_main(target1) | |
.section .rodata | |
.align 2 | |
.set .LANCHOR0,. + 0 | |
.LC0: | |
.byte 1 | |
.byte 2 | |
.byte 3 | |
.byte 4 | |
.byte 5 | |
.byte 6 | |
.byte 7 | |
.byte 8 | |
.byte 9 | |
.byte 10 | |
.bss | |
.align 2 | |
.set .LANCHOR1,. + 0 | |
.type _ZStL8__ioinit, %object | |
.size _ZStL8__ioinit, 1 | |
_ZStL8__ioinit: | |
.space 1 | |
.hidden __dso_handle | |
.ident "GCC: (GNU Tools for ARM Embedded Processors 6-2017-q2-update) 6.3.1 20170215 (release) [ARM/embedded-6-branch revision 245512]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment