我在C中制作了一个冒泡排序程序,并检查了它的汇编列表文件。但我无法得到for循环的位置。你能让我知道for循环和if语句在哪里?
#include<stdio.h>
int main()
{
int arr[5]={2,4,5,6,1};
int i,j,tmp;
for(i=0;i<5;i++)
{
for(j=0;j<4;j++)
{
if(arr[j]>arr[j+1])
{
tmp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=tmp;
}
}
}
for(i=0;i<5;i++){
printf(" %d",arr[i]);
}
printf("\n");
return 0;
}
这是汇编列表文件。
; generated by ARM C Compiler, ADS1.2 [Build 848]
; commandline [-O1 -browseinfo "0xff
" -S -g+ -fk -J:cw:]
CODE32
AREA ||.text||, CODE, READONLY
main PROC
|L1.0|
STMFD sp!,{r4,lr}
SUB sp,sp,#0x18
MOV r2,#0x14
LDR r1,|L1.148|
ADD r0,sp,#4
BL __rt_memcpy_w
MOV r12,#0
|L1.28|
MOV r0,#0
|L1.32|
ADD r1,sp,#4
ADD r2,sp,#4
ADD r3,r2,r0,LSL #2
LDR r1,[r1,r0,LSL #2]
LDR r2,[r3,#4]
CMP r1,r2
BLE |L1.72|
ADD lr,sp,#4
STR r2,[lr,r0,LSL #2]
STR r1,[r3,#4]
|L1.72|
ADD r0,r0,#1
CMP r0,#4
BLT |L1.32|
ADD r12,r12,#1
CMP r12,#5
BLT |L1.28|
MOV r4,#0
|L1.100|
ADD r0,sp,#4
LDR r1,[r0,r4,LSL #2]
ADR r0,|L1.152|
BL _printf
ADD r4,r4,#1
CMP r4,#5
BLT |L1.100|
ADR r0,|L1.160|
BL _printf
MOV r0,#0
ADD sp,sp,#0x18
LDMFD sp!,{r4,pc}
|L1.148|
DCD ||.constdata$1||
|L1.152|
DCB " %d"
DCB "\0\0\0\0"
|L1.160|
DCB "\n\0\0\0"
ENDP
AREA ||.constdata||, DATA, READONLY, ALIGN=2
||.constdata$1||
DCD 0x00000002
DCD 0x00000004
DCD 0x00000005
DCD 0x00000006
DCD 0x00000001
EXPORT main
IMPORT _main
IMPORT __main
IMPORT _printf
IMPORT __rt_memcpy_w
IMPORT ||Lib$$Request$$armlib||, WEAK
KEEP
答案 0 :(得分:5)
你走了。如果您只是查找 LDR r1,[r1,r0,LSL #2] ; r1 = arr[j]
LDR r2,[r3,#4] ; r2 = arr[j+1]
CMP r1,r2 ; arr[j] <= arr[j+1]
BLE |L1.72| ; jump if yes
ADD lr,sp,#4 ; arr
STR r2,[lr,r0,LSL #2] ; arr[j] = arr[j+1]
STR r1,[r3,#4] ; arr[j+1] = arr[j]
|L1.72|
ADD r0,r0,#1 ; j++
CMP r0,#4 ; j < 4
BLT |L1.32| ; jump to inner loop if yes
ADD r12,r12,#1 ; i++
CMP r12,#5 ; i < 5
BLT |L1.28| ; jump to outer loop if yes
和常量,那么您应该能够找到它们:
<flow name="myprojectFlow">
<http:listener config-ref="HTTP_Listener_Configuration1" path="/" doc:name="HTTP"/>
<set-payload doc:name="Set Payload" value="Hi"/>
<request-reply doc:name="RR1">
<jms:outbound-endpoint queue="req_queue" doc:name="JMS" connector-ref="Active_MQ">
<jms:transaction action="ALWAYS_BEGIN"/>
</jms:outbound-endpoint>
<jms:inbound-endpoint queue="req_queue" doc:name="JMS" connector-ref="Active_MQ">
<jms:transaction action="ALWAYS_BEGIN"/>
</jms:inbound-endpoint>
</request-reply>
<logger message="---- payload ---#[payload]" level="INFO" doc:name="Logger"/>
<request-reply doc:name="RR2">
<jms:outbound-endpoint queue="req_queue1" doc:name="JMS" connector-ref="Active_MQ">
<jms:transaction action="ALWAYS_BEGIN"/>
</jms:outbound-endpoint>
<jms:inbound-endpoint queue="req_queue1" doc:name="JMS" connector-ref="Active_MQ">
<jms:transaction action="ALWAYS_BEGIN"/>
</jms:inbound-endpoint>
</request-reply>
<logger message="---- payload1 ---#[payload]" level="INFO" doc:name="Logger"/>