program test_idea;
#include( "stdlib.hhf" );
static
begin test_idea;
mov(6, ecx);
malloc(ecx);
mov(30, ecx);
mov(ecx, [eax + 5]);
mem.free(eax);
end test_idea;
不知道为什么这不起作用。我正在使用 hla 和汇编。
环境
笔记
n * 4
字节,其中n
是数组中元素的数量。b + i * 4
whereb = ArrayBaseAddr; i = DesiredIndex;
例子
program array_access;
#include( "stdlib.hhf" );
static
ArrySize: int32 := 10;
BaseAddr: pointer to int32;
begin array_access;
// Store the array size in EAX
mov(ArrySize, EAX);
// Multiple array size by 4
shl(2, EAX);
// Allocate storage
malloc(EAX);
// save the BaseAddr of the new array
mov(EAX, BaseAddr);
// Store BaseAddr in EBX
mov(BaseAddr, EBX);
// Loop through the Array
for(mov(0, ESI); ESI < ArrySize; inc(ESI)) do
// Store the index as the value for the element at the index
mov(ESI, [EBX + ESI*4 ]);
endfor;
// Print the sixth element
mov(6, ESI);
mov([EBX + ESI*4], EAX);
stdout.puti32(EAX);
stdout.put(nl);
// Change the sixth element to 73
mov(73, EDX);
mov(EDX, [EBX + ESI*4]);
// Print the sixth element
mov([EBX + ESI*4], EAX);
stdout.puti32(EAX);
stdout.put(nl);
end array_access;