0
誰でも私を助けてくれますか?私はC++とASMでn個の要素を合計しなければなりません。すべてがC++で動作しますが、ASMでは動作しません。問題を解決する方法を誰かが知っていますか?それはC++の合計を計算し、時間と合計を表示しますが、ASMには0が表示されますが、C++では0が表示されることがあります。私はTurboC++を使用 は、ここでは私のコードです:C++とasmエラー
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#include <time.h>
void main()
{
clrscr();
int n = 30000;
double s=0;
int a[30000];
cout << "Array has " << n << " elements 3 times summed";
for (int i=0; i<n; i++)
{
a[i]=rand() % 10 + 1;
}
clock_t begin = clock();
for(i=0; i<n; i++)
{
s+=a[i];
}
for(i=0; i<n; i++)
{
s+=a[i];
}
for(i=0; i<n; i++)
{
s+=a[i];
}
clock_t end = clock();
cout << "\nExecution time for the sum in C++ is: " << ((double)(end-begin)/CLOCKS_PER_SEC);
int tmp;
clock_t start = clock();
for (int j=0;j<3;j++){
for (i=0;i<n;i++)
asm {
mov ax,13
add ax,2
}
}
clock_t stop = clock();
cout << "\nExecution time for the sum in ASM is: " << ((double)(stop-start)/CLOCKS_PER_SEC);
cout<<"\nSum: "<< s;
getch();
}
アセンブリコードがGCC(https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html)と一致しないため、Visual Studioを使用していると仮定します。どのようなエラーメッセージが表示されますか? –
私はそれを得ることはできません。あなたの合計を 'asm'の部分でどのように計算して' s'に表示したいのですか?あなたはちょうどそこに 'ax'で13 + 2を計算し続けます。 –
** time **に0が表示されている場合は、コンパイラが「何もしない」と言っているだけの長い方法であることがわかりました。コンパイルの結果を分析して、本当にあなたの 'mov ax、13;どこかに2を加える。 –