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

Plugin: EMIT source

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

Colin admin
Posts
928
Threads
49
Location
Bulgaria

Plugin: EMIT source

The sample plugin that is supplied with Ziron.

Version 0.5

program WIN32DLL 'EMIT PLUGIN';

#include 'zirplug/framework.zir';

//////////////////////////////

const strLoaded = 'Emit plugin has loaded!';

//////////////////////////////


//
// event_Emit()
// return false to allow the assembler to process this keyword internally.
// return true to tell the assembler this keyword has been processed.
//
function event_Emit() {
	uses edi;
	
	char codeBuf[4];

	eax = Ziron_ExpectNextToken(zirDATA_TYPE);
	if (eax == -1) {
		Ziron_FatalError('Expected data type');
		return true;
	}
	edi = Ziron_GetTypeSize();
	
	
	repeat {
		eax = Ziron_GetNextToken();
			
		case (eax) {
			state zirHEXADECIMAL:
			state zirNUMBER:
				codeBuf = Ziron_GetIntValue();
									
				Ziron_EmitCode(@codeBuf, edi);
				break;
			
			default:
				Ziron_FatalError('Unexpected token type');
				return true;
		}
		
		eax = Ziron_GetNextToken();
		
		if (eax == zirSEMI_COLON) {
			break;
		} elseif (eax != zirCOMMA) {
			Ziron_FatalError('Unexpected token type');
			break;
		}
	};
	return true;
}


function InitPlugin(pointer pGetF) {
	Ziron_LoadAll(pGetF); //use framework utility function to load all

	//register our keyword
	Ziron_RegisterKeyword('emit', @event_Emit);
	
	return strLoaded;
}

entry function DLLMain(DWord iDLL; DWord iReason; Pointer iResult) {
  if (iReason == DLL_PROCESS_ATTACH) {
    return true;
  }

  return false;
}

exports InitPlugin;

Save this code in a file such as "emit.zir", it can then be assembled with Ziron 1.1.24.9, finally, put the output dll into the plugins directory.

The extension this plugin brings is the emit keyword, which is used as so:

//a nop opcode
emit byte 0x90;

//push eax; pop eax
emit byte 0x50, 0x58;

//emit the number 5000 into the assembled code as a dword
emit dword 5000;

I will gradually upgrade this plugin as I extend the plugin system.

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

an upgrade before release of new Ziron :)

program WIN32DLL 'EMIT PLUGIN';

#include 'zirplug/framework.zir';

//////////////////////////////

const strLoaded = 'Emit plugin has loaded!';

//////////////////////////////


//
// event_Emit()
// return false to allow the assembler to process this keyword internally.
// return true to tell the assembler this keyword has been processed.
//
function event_Emit() {
	uses edi;
	
	char codeBuf[10];

	eax = Ziron_ExpectNextToken(zirDATA_TYPE);
	if (eax == -1) {
		Ziron_FatalError('Expected data type');
		return true;
	}
	edi = Ziron_GetTypeSize();
	
	if (edi < 1 and edi > 10) {
		Ziron_FatalError('Data type is invalid');
		return true;
	}	
	
	repeat {
		eax = Ziron_GetNextToken();
			
		case (eax) {
			state zirHEXADECIMAL:
			state zirNUMBER:
				codeBuf = Ziron_GetIntValue();
									
				Ziron_EmitCode(@codeBuf, edi);
				break;
				
			state zirFLOAT:
				codeBuf = Ziron_GetRealValue(edi);
				
				Ziron_EmitCode(@codeBuf, edi);
				break;				
			
			default:
				Ziron_FatalError('Unexpected token type');
				return true;
		}
		
		eax = Ziron_GetNextToken();
		
		if (eax == zirSEMI_COLON) {
			break;
		} elseif (eax != zirCOMMA) {
			Ziron_FatalError('Unexpected token type');
			break;
		}
	};
	return true;
}


function InitPlugin(pointer pGetF) {
	Ziron_LoadAll(pGetF); //use framework utility function to load all

	//register our keyword
	Ziron_RegisterKeyword('emit', @event_Emit);
	
	return strLoaded;
}

entry function DLLMain(DWord iDLL; DWord iReason; Pointer iResult) {
  if (iReason == DLL_PROCESS_ATTACH) {
    return true;
  }

  return false;
}

exports InitPlugin;

will allow real output.

emit extended 3.53;
Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

well done Mr OverHertz.

i have playing with the new Emit_plugin , but the next code did not as expected

/*
     Simple plugin Test program
     
      it test the Emit plugin
      
*/
program WIN32CUI 'EmitTest';

#include 'console.zir';
#include 'ch.zir';

Eax = 100;

Emit byte 0x50;  // push Eax
 
Eax = 200;

Emit byte 0x59; // pop Eax

print('Eax = ', Eax:int , '\r\n');

wait_key(nil);

ExitProcess(0);

it prints 200 !!!!!!!! , any help please?

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

Colin admin
Posts
928
Threads
49
Location
Bulgaria

hi

0x59 is pop ecx you need 0x58

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok , fix it and worked as expected.

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

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

i see that Ziron has sume functions to get the token value such as Ziron_GetIntValue ,Ziron_GetRealValue. so is there a function to get a string value?

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

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

also when i mentioned a string , i was meaning that the string does not have to enclose

by "" or '' ,it may be some char.

for example , i want to extend the mov instruction just like this

  mov 10 into Eax; 

so we can access to into string and convert the whole line to be like this

  mov Eax,10;

and return false to allow the assembler to reprocess it.

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

Colin admin
Posts
928
Threads
49
Location
Bulgaria

i will add identifiers next, but this system does not allow changing the line, it is intended for advanced usage, returning false is for another reason, i will make more samples to show how it is used