good, by the way i was tring this but it always crash.
for(ecx = 0 to 1)
{
ebx=@myArr;
mov eax,[ebx+ecx*4]
print(eax:string , '\r\n');
}
http://www.freewebs.com/ogremagic/index.htm
A community discussion post from the original code:zIRON forum.
good, by the way i was tring this but it always crash.
for(ecx = 0 to 1)
{
ebx=@myArr;
mov eax,[ebx+ecx*4]
print(eax:string , '\r\n');
}
http://www.freewebs.com/ogremagic/index.htm
eax can not be passed as a string to print, i have added a error for this in next release, you can use edx or other registers:
char* myArr[2];
myArr[0] = 'Test 1';
myArr[1] = 'Test 2';
for(ecx = 0 to 1) {
ebx = @myArr;
edx = [ebx+ecx*4];
print(edx:string, '\r\n');
}
but easiest and best way:
program WIN32CUI 'test';
#include 'ch.zir';
char* myArr[2];
myArr[0] = 'Test 1';
myArr[1] = 'Test 2';
ebx = @myArr;
for(ecx = 0 to 1) {
print([ebx+ecx*4], '\r\n');
}
wait_key();
ExitProcess(0);
ok , i was playing with printf function from msvcrt.dll and used it instead of print but it
crashed , i think it is a problem with cdecl.
program WIN32CUI 'test';
#include 'ch.zir';
imports('msvcrt.dll')
{
function printf(char* format[]): Int32; cdecl;
}
char* myArr[2];
//constant mem
myArr[0] = 'String 1';
myArr[1] = 'String 2';
edi=@myArr;
for(ecx = 0 to 1)
{
printf('%s ',[edi+ecx*4]);
}
delete myArr[0];
delete myArr[1];
wait_key();
ExitProcess(0);
http://www.freewebs.com/ogremagic/index.htm
hi emil, there is no problem with cdecl, i see your mistake:
all windows functions do not preserve ecx and edx, infact it is normal for all functions to trash eax-edx, so you have 2 options:
edi=@myArr;
for(ecx = 0 to 1)
{
push ecx
printf('%s ',[edi+ecx*4]);
pop ecx
}
or better:
ebx=@myArr;
for(edi = 0 to 1)
{
printf('%s ',[ebx+edi*4]);
}
oh , i see now.
but what exactly is the free register that can be used and what that used by windows function.
http://www.freewebs.com/ogremagic/index.htm
well the registers are:
eax, ecx, edx, ebx, esp, ebp, esi, edi
eax-edx are usually trashed in external function calls (internal depends if the function has been written to protect the register.
ebp is used for stack frame in functions, esp is the stack pointer, else ebx, esi and edi are good to go in most cases, of course ecx and edx are still usable in alot of cases, you just need to check if the external functions will trash the register or not.
ok , thanks for your help.
I am stuck here , i was implement strArr like this
char strArr[10240]; storage for hold all string array each one is 128 byte len
dword cnt;
dword disp;
..........
.........
//later
eax = Ziron_GetNextToken();
ebx = 0;
cnt = 0;
edi = @strArr;
while( eax != zirParenClose)
{
H_strcpy( [edi+ebx],Ziron_GetStringValue());
ebx += 128;
cnt++;
eax = Ziron_GetNextToken();
}
but it crashed.
so i think Ziron_GetStringValue() may change edi or ebx?
then i tried this
dword disp = 0;
while( eax != zirParenClose)
{
eax=Ziron_GetStringValue();
push eax
edi = @parArr;
edi += disp;
push edi
call H_strcpy
add disp,128
cnt++;
eax = Ziron_GetNextToken();
}
it did not crashed , do you have any suggestion or another approach?
thanks.
http://www.freewebs.com/ogremagic/index.htm
ok i found the error , here is the new code
eax = Ziron_GetNextToken();
esi = 0;
cnt = 0;
while( eax != zirParenClose)
{
edi = @parArr;
edi += esi;
H_strcpy( edi,Ziron_GetStringValue());
esi += 128;
cnt++;
eax = Ziron_GetNextToken();
}
there is another thing
when using this , it crashed
for(edi = 0 to cnt)
{
}
and when using this , it's okay
edi = cnt;
while(edi>0)
{
edi--;
}
http://www.freewebs.com/ogremagic/index.htm