【发布时间】:2016-03-09 23:20:26
【问题描述】:
鉴于此 c 代码:
char** names=(char**)malloc(count*sizeof(char*));
我想把它转换成 NASM 汇编代码。这是我尝试过的,但代码崩溃了:
mov eax, dword count
mov ebx, [eax*4] ;; i did times 4 because we clear stack by 4 bits or bytes?
push ebx
call _malloc
mov names, eax
add esp, 4
sizeof(char*)是什么意思?代码寻址的是哪个 char 指针?
【问题讨论】:
-
mov ebx, [eax*4]应该是lea ebx, [eax*4]或只是shl eax, 2; push eax。 -
它不再崩溃了。但是 sizeof(char*) 是多少。我感觉不是 4。
-
@Jester 你应该把它作为答案发布!
-
sizeof(char *)正在确定系统上指针的大小。如果您有 64 位系统,则可能是 8。
标签: c arrays pointers assembly nasm