我真的很困惑我的家庭作業。我們給C代碼,然後組裝下面列出。這是x86彙編。任何援助將不勝感激。我試圖根據我的理解來解決這個問題。裝配到C矩陣Assignment
C代碼:只內環
void transpose(Marray_t A) {
int i, j;
for (i = 0; i < M; i++)
for (j = 0; j < i; j++) {
int t = A[i][j];
A[i][j] = A[j][i];
A[j][i] = t;
}
}
彙編代碼:
1 .L3:
2 movl (%ebx), %eax //is this getting the mem location of %ebx and setting to %eax?
3 movl (%esi,%ecx,4), %edx //ecx * 4 + esi into edx
4 movl %eax, (%esi,%ecx,4) //
5 addl $1, %ecx //add 1 to ecx
6 movl %edx, (%ebx) //move edx to mem location of ebx???
7 addl $52, %ebx //I think this is M but I could be wrong
8 cmpl %edi, %ecx //compare edi & ecx
9 jl .L3
這裏是我來回答:
A.什麼是M值? ...我認爲這是52 ...?
B.什麼寄存器保存程序值我和j? ...我認爲edx和eax? C.編寫一個C代碼版本的轉置文件,利用該循環中發生的優化 。在代碼中使用參數M而不是數字 常量。
在嘗試(C):
void tranpose(Marray_t A) {
int i, j;
for(i = 0; i < M; i++) {
for(j = 0; j < i; j++) {
int *row = &A[i][0];
int *col = &A[0][j];
int value = (*row * 4) + *col;
}
}
}
也許你想回顧(並接受我的回答,如果合適的話) –
這就是我所困惑的,我不知道我們是否可以根據所給出的來確定M.我從課本中直接複製了這些,所以我不知道。 – user1758231