我需要這個C代碼翻譯成彙編語言代碼轉換C代碼到大會
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int answer, i;
int right, wrong;
right = 0;
wrong = 0;
for(i =1; i < 11; i = i+1){
printf("What is %d + %d? ", i,i);
scanf("%d", &answer);
if(answer == i + 1) {
printf("right! ");
right++;
}
else {
printf("Sorry, you're wrong. ");
printf("The answer is %d. ", i + 1);
wrong++;
}
}
printf("You got %d right and %d wrong. ", right, wrong);
return 0;
}
我真的只需要知道如何將一個變量與字符串彙編語言如上面的C代碼相結合。我想我可以處理所有其他事情。有人能告訴我嗎?我會不得不使用某種參考[]。
注意我使用MASM和工作了硤歐文的彙編語言的x86處理器第6版書
更新繼承人我試圖將代碼從回答者的答案我的一個寫到MASM不斷收到錯誤。就像我說我使用硤歐文的彙編語言,所以我必須包括庫鏈接之前,先添加Irvine32.inc
這是錯誤>>>> programb.obj:錯誤LNK2019:無法解析外部符號_scanf在函數_main引用@ 0
INCLUDE Irvine32.inc
能有人幫助我GE牛逼這一權利
.data
string1 db "What is %d + %d? ", 0
string2 db "%d", 0
string3 db "right! ", 0
string4 db "Sorry, you're wrong. The answer is %d", 10, 0
string5 db "You got %d right and %d wrong.", 10, 0
answer dd 0
right dd 0
wrong dd 0
.code
main PROC
mov ebx, 1
L1:
cmp ebx, 11
je L2
push 1
push ebx
mov edx,OFFSET string1
call WriteString
add esp, 12
push answer
mov edx,OFFSET string2
call scanf
add esp, 8
inc ebx
cmp answer, ebx
jne L3
push ebx
mov edx,OFFSET string3
call WriteString
add esp, 8
inc right
jmp L1
L3:
push ebx
mov edx,OFFSET string4
call WriteString
add esp, 8
inc wrong
jmp L1
L2:
push wrong
push right
mov EDX,OFFSET string5
call WriteString
add esp, 12
exit
main ENDP
END main
programb.obj : error LNK2019: unresolved external symbol _scanf referenced in function [email protected]
我對彙編語言代碼對不起....我不知道怎樣格式化它,所以它可以更容易閱讀....
所以你問如何從裝配調用printf,或正在問如何做整數字符串轉換,然後在彙編中的字符串連接?這是兩件完全不同的事情。 – 2010-11-05 12:33:53
基本上字符串連接 – jwill22 2010-11-05 20:28:58