#include <stdint.h> uint32_t A[]={1,2,3,4,5,6}; int main() { shiftArray(A,6); while(1); } void shiftArray(uint32_t *ary, uint32_t size) { uint32_t value1,value2; value2 = 0; while(size != 0) { value1 = *ary; *ary = value2; value2 = value1; ary++; size--; } }
时间: 2024-02-25 13:57:30 浏览: 77
stdint.h和inttypes.h
5星 · 资源好评率100%
Sure, here is the equivalent assembly code for the given C program, written for the TM4C123:
```
.syntax unified
.cpu cortex-m4
.data
A: .word 1, 2, 3, 4, 5, 6 @ Data array A
.text
.global main
.type main, %function
main:
@ Push registers to the stack
push {r4-r11, lr}
@ Call shiftArray function with A and 6 as arguments
ldr r0, =A
mov r1, #6
bl shiftArray
loop:
b loop @ Infinite loop
@ Pop registers from the stack and return
pop {r4-r11, pc}
.type shiftArray, %function
shiftArray:
@ Push registers to the stack
push {r4-r11, lr}
@ Initialize value2 to 0 and loop until size is 0
mov r4, #0
loop:
cmp r1, #0
beq end_loop
@ Load value1 from the current element of ary
ldr r5, [r0]
@ Store value2 to the current element of ary
str r4, [r0]
@ Update value2 to value1 and increment ary and decrement size
mov r4, r5
add r0, r0, #4
sub r1, r1, #1
b loop
end_loop:
@ Pop registers from the stack and return
pop {r4-r11, pc}
```
Note that this is just one possible implementation, and there may be other ways to write the same program in assembly language.
阅读全文