Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / General Discussion

goto statment

A community discussion post from the original code:zIRON forum.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

goto statment

Hi Mr Colin.

as you know , with asm language you can make some tricks to preform something.

so i used goto to put some data after it , then when trying to use this data , we get NULL.

for Example:

imports('msvcrt.dll') 
{
  function printf(char* format[]): Int32; cdecl;
}

goto @end

char* str1 = 'this well not seen by ziron';
  ............
  ............

@end:

ebx=@str1;
printf('%s',[Ebx]);
 

this will print null , but this of course work

imports('msvcrt.dll') 
{
  function printf(char* format[]): Int32; cdecl;
}



char* str1 = 'this well not seen by ziron';
goto @end
    ........
    ........
@end:

ebx=@str1;
printf('%s',[Ebx]);

so why ziron did not execute what after goto.

http://www.freewebs.com/ogremagic/index.htm

Replies

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

to be more specific ,i want to allow this

goto @end

@myStr:
Emit byte  'E','m','i','l',0,10,13;  // of course i will put useful data here    

@end:

ebx=@myStr;
printf('%s',[Ebx]);

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

with your first example you were confusing pointers and also mov operation

e.g.

char* str1 = 'this well not seen by ziron';

this is a mov op

and this:

printf('%s',[Ebx]);

here you are not passing a pointer by the value of the pointer

working example:

program WIN32CUI 'Test';

#include 'ch.zir';

imports('msvcrt.dll') 
{
  function printf(char* format[]): Int32; cdecl;
}

goto @end

const str = 'this is a test';

@end:

ebx = @str;
printf('%s\r\n', ebx);

wait_key();

ExitProcess(0);

as for emitting text between jumps, this is also possible:

program WIN32CUI 'Test';

#include 'ch.zir';

imports('msvcrt.dll') 
{
  function printf(char* format[]): Int32; cdecl;
}

goto @end
	@str: emit byte "t","e","s","t",0;
@end:

ebx = @str;
printf('%s\r\n', ebx);

wait_key();

ExitProcess(0);

emit plugin could be extended to support emit string '....';

or optionally a whole new plugin could be developed for handling strings emitted inside of code :)

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok , thanks for explanation.

http://www.freewebs.com/ogremagic/index.htm

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

good news , this also working well.

program WIN32CUI 'Test';

#include 'ch.zir';

imports('msvcrt.dll') 
{
  function printf(char* format[]): Int32; cdecl;
}

ebx = @str;
printf('%s\r\n', ebx);

wait_key();

ExitProcess(0);

// we put data here for erasing goto statment.
 @str: 
    emit byte "t","e","s","t",0;

so the big trick here , can we use a label as a variable ?

eg. something like that

   al = str[2];
 

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

at current, not directly, but i need to work more on this.. else

eax = @lbl;
al = [eax+1];
Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok , but how to put the address of another labels to make array of pointer.

for Example

@Str2:
     emit byte "t","e","s","t","2",13,10,0;
     
@Str3:
     emit byte "t","e","s","t","3",13,10,0;
     
@Str4:
     emit byte "t","e","s","t","4",13,10,0;     
     
@addr:
     emit dword @Str2,@Str3,@Str4,0;        // how can we make that
     

http://www.freewebs.com/ogremagic/index.htm