Register | Login
Forum Index > Plugins > Plugin: EMIT source
Author Message
Pages: 1 2 3 4
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[211] Plugin: EMIT source - posted: 2011-10-30 12:40:31
The sample plugin that is supplied with Ziron.

Version 0.5

Code:
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:

Code:
//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.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[212] - posted: 2011-10-30 15:00:24
an upgrade before release of new Ziron smile

Code:
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.

Code:
emit extended 3.53;


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[214] - posted: 2011-10-30 17:56:10

well done Mr OverHertz.

i have playing with the new Emit_plugin , but the next code did not as expected
Code:
/*
     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
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[215] - posted: 2011-10-30 18:48:01
hi

0x59 is pop ecx you need 0x58

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[216] - posted: 2011-10-30 19:08:43

ok , fix it and worked as expected.



http://www.freewebs.com/ogremagic/index.htm
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[217] - posted: 2011-10-30 19:21:02

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
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[218] - posted: 2011-10-30 20:14:43

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
Code:
  mov 10 into Eax; 


so we can access to into string and convert the whole line to be like this
Code:
  mov Eax,10;


and return false to allow the assembler to reprocess it.

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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[219] - posted: 2011-10-30 20:18:42
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

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1 2 3 4
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 7 user(s) online. 0 member(s) and 7 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd