int *arr=new int[10];(executable NetRun link)
for (int i=0;i<10;i++)
arr[i]=(i*10);
return arr[7];
int i;(executable NetRun link)
int *arr=malloc(10*sizeof(int));
for (i=0;i<10;i++)
arr[i]=(i*10);
return arr[7];
C/C++ |
Assembly |
int *p; |
; Not needed--no types! (Woo hoo!) Er, now be careful, kids... |
p=malloc(40); |
push 40; Function arguments go on the stack in 32-bit x86 extern malloc call malloc add esp,4; Undo "push" ; Malloc's return value, a pointer, comes back in eax |
p++; |
add eax,4; Subtle: advance 1 int, by advancing 4 bytes |
int i=*p; |
mov ecx, [eax]; Treat eax as a pointer, and copy out the value it points to |