Register | Login
Forum Index > Requests and Feedback > emit keyword
Author Message
Pages: 1 2
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[136] emit keyword - posted: 2011-10-25 23:23:46

hi OverHertz.

i just want Ziron to has way to emit a value inside the output code .eg
Code:
 eax = 10;
 emit byte 0x100; // we insert hex value of any instruction directly in out code
 emit word 0x200;  
 ecx = [eax + 3]


this will be useful in many cases.

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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[137] - posted: 2011-10-26 01:43:18
This is possible with the blob keyword

blob size_bytes,out

e.g.
Code:
blob 1,0x90; //single nop
blob 4,0x90909090; //4 nops


a slightly more complex usage from includes/opcodes.zir

Code:
inline op procedure _or(reg1, reg2) { 
  $expect sizeof $reg1 as sizeof $reg2: 'Operands must be equal size';

  $if sizeof $reg1 == 32:
    blob 1,0x0B 1,0xC0 + (($reg1*8)+$reg2); 
  $elseif sizeof $reg1 == 16:
    blob 1,0x66 1,0x0B 1,0xC0+(($reg1*8)+$reg2);
  $else
    blob 1,0x0A 1,0xC0+(($reg1*8)+$reg2);
  $end
}


it would be possible to write an Emit macro to implement the keyword smile

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
[138] - posted: 2011-10-26 18:36:38
very nice.

does macro system allow incompleted parameters ?
just like printf ic c&c++ ,

inline op mymacro(par1,par2,...)

and if so , is there a way to get those parameters as array

also can we test if any parameter is null ?

also we need a way to know the type of the parameter , is it register ,memory location , abslout value...

all that will be useful.

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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[143] - posted: 2011-10-26 19:26:52
i sugest for now you check the includes/console.zir file, this has a reasonable sample with the print macro.

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
[203] - posted: 2011-10-29 20:54:48
thought i'd post regarding this request - since actually it is useful i have implemented it as written, but better still instead of hardcoded i have used this feature to help me improve the plugin system and written this opcode using the plugin system smile

Code:
program WIN32DLL 'EMIT PLUGIN';

#include 'ziron32.zir';

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

enum ZirToken: DWord {
  zirSEMI_COLON, zirCOMMA, zirDATA_TYPE, zirREGISTER, zirNUMBER, zirHEXADECIMAL
}

enum ZirFWID: DWord {
  //settings
  idCPU_MODE = 10,  

  //functions
  idFATAL_ERROR = 1000,
  idSHOW_MESSAGE = 1001,
  
  //special functions
  idREGISTER_KEYWORD = 2000,
  
  idEXPECT_NEXT_TOKEN = 5000,
  idGET_NEXT_TOKEN = 5001,
  idIS_DATA_FLOAT = 5002,
  idGET_INTVALUE = 5003,
  idGET_DATA_SIZE = 5004,
  idEMIT_CODE = 5005
}

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

const strLoaded = 'Emit plugin has loaded!';

//////////////////////////////
function* Ziron_Get(ZirFWID funcID): DWord; stdcall;

////
procedure* Ziron_FatalError(char* str); stdcall;
procedure* Ziron_ShowMessage(char* str); stdcall;

//
function* Ziron_ExpectNextToken(ZirToken tt): DWord; stdcall;
function* Ziron_GetNextToken(): DWord; stdcall;
function* Ziron_GetIntValue(): Int32; stdcall;
function* Ziron_GetDataSize(DWord id): DWord; stdcall;

function* Ziron_RegisterKeyword(char* name; pointer callback): DWord; stdcall;
procedure* Ziron_EmitCode(char* buffer; DWord len); stdcall;
////


function event_Emit() { //always stdcall; return false to allow the assembler to use the default processor for this keyword
  uses edi;
  
  char codeBuf[4];

  eax = Ziron_ExpectNextToken(zirDATA_TYPE);
  if (eax == -1) {
    Ziron_FatalError('Expected data type');
    return true;
  }
  edi = Ziron_GetDataSize(eax);
  
  
  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_Get = pGetF;
  
  //get the functions this plugin will require - see plugin_interface.txt
  Ziron_FatalError = Ziron_Get(idFATAL_ERROR);
  Ziron_ShowMessage = Ziron_Get(idSHOW_MESSAGE);
  
  Ziron_RegisterKeyword = Ziron_Get(idREGISTER_KEYWORD);
  Ziron_ExpectNextToken = Ziron_Get(idEXPECT_NEXT_TOKEN);
  Ziron_GetNextToken = Ziron_Get(idGET_NEXT_TOKEN);
  Ziron_GetIntValue = Ziron_Get(idGET_INTVALUE);
  Ziron_GetDataSize = Ziron_Get(idGET_DATA_SIZE);
  Ziron_EmitCode = Ziron_Get(idEMIT_CODE);

  //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;


once compiled, put into the plugin directory it allows a new opcode to be used directly in your code:

Code:
//lets do a push eax; pop eax
emit byte 0x50, 0x58;


This feature request was the perfect sample plugin to be supplied with Ziron smile

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
[205] - posted: 2011-10-29 22:46:16

so nice , when you will release that , want to start playing with it.smile

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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[206] - posted: 2011-10-29 23:05:46
maybe tomorrow afternoon smile

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
[209] - posted: 2011-10-29 23:18:22

well ,

i think it will be better if you add a plugin section in the forum , so that we can collect a post of Plugin source in one place.

http://www.freewebs.com/ogremagic/index.htm
Pages: 1 2
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 10 user(s) online. 0 member(s) and 10 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