この 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 を使用しており、Kip Irvine のアセンブリ言語 x86 プロセッサの第 6 版ブックを使用しています。
回答者の回答の1つからMASMに書き込もうとしたコードを更新します。エラーが発生し続けます。前に言ったように、私は Kip Irvine のアセンブリ言語を使用しているので、ライブラリ リンクを含める必要があります INCLUDE Irvine32.inc
これはエラー>>>> programb.obj です: エラー LNK2019: 未解決の外部シンボル _scanf が関数 _main@0 で参照されています
含む Irvine32.inc
誰かがこれを正しくするのを手伝ってくれますか
.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 _main@0
アセンブリ言語のコードで申し訳ありません....読みやすいようにフォーマットする方法がわかりません....