所以,有一个过去的考试问题,我没有清楚地了解。
“下面的ARM例程执行什么功能?” 功能是
int exam1(int array[], int size)
stmfd sp!, {v1-v6, lr}
mov a3,#0
elop: ldr a4, [a1], #4
movs a4,a4
addmi a3,a3,#1
subs a2,a2,#1
bne elop
mov a1,a3
ldmfd sp!,{v1-v6,pc}
编辑: 关于它如何编辑内存中的寄存器/读取,我不会根据每个命令做什么。
答案 0 :(得分:1)
让我们看看我是否能记住我的ARM汇编程序:
int exam1(int array[], int size)
stmfd sp!, {v1-v6, lr} ; store registers v1-v6 plus link register on the stack
mov a3,#0 ; zero register a3 - prospective count of negative numbers
elop: ; loop label
ldr a4, [a1], #4 ; load register a4 from the memory addr pointed to by a1 (first param)
; and increment a1 by 4 bytes
movs a4,a4 ; move a4 to itself, but setting flags, so negative flag set
; if the loaded value was negative
addmi a3,a3,#1 ; if the negative flag was set, increment a3
subs a2,a2,#1 ; subtract one from a2 (number of entries to process), setting flags
bne elop ; if a3 did not reach zero, loop
mov a1,a3 ; move the result (number of negative numbers) into a1
ldmfd sp!,{v1-v6,pc} ; restore v1-v6, and restore saved link register as pc, returning
如果您不了解助记符或符号或个别说明的含义,最好在参考指南中查找它们。