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

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [macros/] [9x8/] [push16.py] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 sinclairrf
# Copyright 2014, Sinclair R.F., Inc.
2
 
3
def push16(ad):
4
  """
5
  User-defined macro to push a 16 bit value onto the data stack so that the LSB
6
  is deepest in the data stack and the MSB is at the top of the data stack.\n
7
  Usage:
8
    .push16(v)
9
  where
10
    v           is a 16-bit value, a constant, or an evaluated expression\n
11
  The effect is to push v%0x100 and int(v/2**8)%0x100 onto the data stack.\n
12 4 sinclairrf
  ( - u_LSB u_MSB )
13 3 sinclairrf
  """
14
 
15
  # Add the macro to the list of recognized macros.
16
  ad.AddMacro('.push16', 2, [ ['','singlevalue','symbol'] ]);
17
 
18
  # Define the macro functionality.
19
  def emitFunction(ad,fp,argument):
20
    argument = argument[0];
21 4 sinclairrf
    v = ad.Emit_IntegerValue(argument);
22
    if not (-2**15 <= v < 2**16):
23
      raise asmDef.AsmException('Argument "%s" should be a 16-bit integer at %s' % (argument['value'],argument['loc'],));
24
    printString = argument['value'] if type(argument['value']) == str else '0x%04X' % (v % 2**16);
25
    ad.EmitPush(fp,v%0x100,'');
26
    v >>= 8;
27
    ad.EmitPush(fp,v%0x100,'.push16(%s)' % printString);
28
 
29 3 sinclairrf
  ad.EmitFunction['.push16'] = emitFunction;

powered by: WebSVN 2.1.0

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