将c语言转换为汇编语言
展开全部
//正确的C代码
int a[]={4,12,0,4};
int b[]={2,543,2,3};
main(){
int i,t;
for(i=0;i<4;i++){
if(a[i]>b[i]){
t=a[i];
a[i]=b[i];
b[i]=t;
}
}
}
翻译后得到的汇编代码:
; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.50727.1
TITLE \Desktop\main.c
.686P
.XMM
include listing.inc
.model flat
INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES
PUBLIC _a
PUBLIC _b
_DATA SEGMENT
_a DD 04H
DD 0cH
DD 00H
DD 04H
_b DD 02H
DD 021fH
DD 02H
DD 03H
_DATA ENDS
PUBLIC _main
; Function compile flags: /Odtp
_TEXT SEGMENT
_t$ = -8 ; size = 4
_i$ = -4 ; size = 4
_main PROC
; Line 3
push ebp
mov ebp, esp
sub esp, 8
; Line 5
mov DWORD PTR _i$[ebp], 0
jmp SHORT $LN4@main
$LN3@main:
mov eax, DWORD PTR _i$[ebp]
add eax, 1
mov DWORD PTR _i$[ebp], eax
$LN4@main:
cmp DWORD PTR _i$[ebp], 4
jge SHORT $LN5@main
; Line 6
mov ecx, DWORD PTR _i$[ebp]
mov edx, DWORD PTR _i$[ebp]
mov eax, DWORD PTR _a[ecx*4]
cmp eax, DWORD PTR _b[edx*4]
jle SHORT $LN1@main
; Line 7
mov ecx, DWORD PTR _i$[ebp]
mov edx, DWORD PTR _a[ecx*4]
mov DWORD PTR _t$[ebp], edx
; Line 8
mov eax, DWORD PTR _i$[ebp]
mov ecx, DWORD PTR _i$[ebp]
mov edx, DWORD PTR _b[ecx*4]
mov DWORD PTR _a[eax*4], edx
; Line 9
mov eax, DWORD PTR _i$[ebp]
mov ecx, DWORD PTR _t$[ebp]
mov DWORD PTR _b[eax*4], ecx
$LN1@main:
; Line 11
jmp SHORT $LN3@main
$LN5@main:
; Line 12
xor eax, eax
mov esp, ebp
pop ebp
ret 0
_main ENDP
_TEXT ENDS
END
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询