Created
June 23, 2017 01:53
-
-
Save C47D/bb66c0524c53372c0c51aa5ef2d5335c to your computer and use it in GitHub Desktop.
Iterate over an array using C "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
/// c_array.c | |
#include <stdint.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
int main(void) | |
{ | |
const uint8_t array_c[10] = | |
{ 0x01, 0x02, 0x03, 0x04, 0x05, | |
0x06, 0x07, 0x08, 0x09, 0x0A }; | |
for ( uint8_t i = 0; | |
i < ( sizeof(array_c) / sizeof(array_c[0])); | |
i++ ) { | |
printf("0x%x\r\n", array_c[i]); | |
} | |
return 0; | |
} | |
/** | |
* Result: | |
* Toolchain: arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors 6-2017-q2-update) 6.3.1 20170215 (release) | |
* Compile: arm-none-eabi-gcc -S c_array.c -mthumb -mcpu=cortex-m4 -O3 -std=c11 | |
*/ | |
.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 "c_array.c" | |
.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, lr} | |
ldr r3, .L6 | |
ldr r6, .L6+4 | |
ldm r3, {r0, r1, r2} | |
sub sp, sp, #16 | |
add r3, sp, #4 | |
stmia r3!, {r0, r1} | |
add r4, sp, #4 | |
strh r2, [r3] @ movhi | |
add r5, sp, #14 | |
.L2: | |
ldrb r1, [r4], #1 @ zero_extendqisi2 | |
mov r0, r6 | |
bl printf | |
cmp r4, r5 | |
bne .L2 | |
movs r0, #0 | |
add sp, sp, #16 | |
@ sp needed | |
pop {r4, r5, r6, pc} | |
.L7: | |
.align 2 | |
.L6: | |
.word .LANCHOR0 | |
.word .LC1 | |
.size main, .-main | |
.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 | |
.section .rodata.str1.4,"aMS",%progbits,1 | |
.align 2 | |
.LC1: | |
.ascii "0x%x\015\012\000" | |
.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