OpenCores
URL https://opencores.org/ocsvn/ssbcc/ssbcc/trunk

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [macros/] [9x8/] [push16.py] - Diff between revs 3 and 4

Show entire file | Details | Blame | View Log

Rev 3 Rev 4
Line 7... Line 7...
  Usage:
  Usage:
    .push16(v)
    .push16(v)
  where
  where
    v           is a 16-bit value, a constant, or an evaluated expression\n
    v           is a 16-bit value, a constant, or an evaluated expression\n
  The effect is to push v%0x100 and int(v/2**8)%0x100 onto the data stack.\n
  The effect is to push v%0x100 and int(v/2**8)%0x100 onto the data stack.\n
  ( - u_LSB u u u_MSB )
  ( - u_LSB u_MSB )
  """
  """
 
 
  # Add the macro to the list of recognized macros.
  # Add the macro to the list of recognized macros.
  ad.AddMacro('.push16', 2, [ ['','singlevalue','symbol'] ]);
  ad.AddMacro('.push16', 2, [ ['','singlevalue','symbol'] ]);
 
 
  # Define the macro functionality.
  # Define the macro functionality.
  def emitFunction(ad,fp,argument):
  def emitFunction(ad,fp,argument):
    argument = argument[0];
    argument = argument[0];
    if argument['type'] == 'value':
    v = ad.Emit_IntegerValue(argument);
      v = argument['value'];
    if not (-2**15 <= v < 2**16):
    elif argument['type'] == 'symbol':
      raise asmDef.AsmException('Argument "%s" should be a 16-bit integer at %s' % (argument['value'],argument['loc'],));
      name = argument['value'];
    printString = argument['value'] if type(argument['value']) == str else '0x%04X' % (v % 2**16);
      if not ad.IsSymbol(name):
    ad.EmitPush(fp,v%0x100,'');
        raise asmDef.AsmException('Symbol "%s" not recognized at %s' % (argument['value'],argument['loc'],));
    v >>= 8;
      ix = ad.symbols['list'].index(name);
    ad.EmitPush(fp,v%0x100,'.push16(%s)' % printString);
      v = ad.symbols['body'][ix];
 
      if len(v) != 1:
 
        raise asmDef.AsmException('Argument can only be one value at %s' % argument['loc']);
 
      v = v[0];
 
    else:
 
      raise asmDef.AsmException('Argument "%s" of type "%s" not recognized at %s' % (argument['value'],argument['type'],argument['loc'],));
 
    if type(v) != int:
 
      raise Exception('Program Bug -- value should be an "int"');
 
    ad.EmitPush(fp,v%0x100,''); v >>= 8;
 
    printValue = argument['value'] if type(argument['value']) == str else '0x%08X' % argument['value'];
 
    ad.EmitPush(fp,v%0x100,'.push16(%s)' % printValue);
 
  ad.EmitFunction['.push16'] = emitFunction;
  ad.EmitFunction['.push16'] = emitFunction;
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.