Ich versuche Array A zu Array B zu kopieren. Hier ist meine cpp-Datei.Nasm 64, Segmentierungsfehler
#include <stdio.h>
using namespace std;
void copy(int * to, int * from, unsigned int n); //_Z6copyPiS_j
int main(){
int * a = new int [4];
int * b = new int [4];
for (int i=0;i<4;++i)
{
a[i] = i+1;
}
kopiuj(b,a,4);
for (int i=0;i<4;++i)
{
printf("%d - ", b[i]);
}
delete(a);
delete(b);
return 0;
}
und hier ist meine asm-Datei mit Kopierfunktion Implementierung
BITS 64
section .text
global _Z6kopiujPiS_j
_Z6kopiujPiS_j:
push rbp
mov rbp, rsp
cld
mov edi, dword [rbp+8] ; destination
mov esi, dword [rbp+12] ; source
mov ecx, dword [rbp+16] ; size
rep movsd; repeat ecx times
mov rsp, rbp
pop rbp
ret
hier ist, wie ich es kompilieren. Leider hat es 64-Bit sein. (Ausübungspflicht)
// nasm -felf64 82.asm -o 82.o
// g++ -m64 -o 82m.o -c 82m.cpp
// g++ -m64 82m.o 82.o -o 82
und bei rep movsd
ich Segmentation Fault. Was mache ich falsch?
64bit == Zeiger sind 8 Bytes: Warum ebp + 8/12/16 ... sind das 4 getrennt? Und welche Aufrufkonvention übergibt die ersten 3 Argumente über den Stack? – ABuckau