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

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [macros/] [9x8/] [push32.py] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 sinclairrf
# Copyright 2014, Sinclair R.F., Inc.
2
 
3
def push32(ad):
4
  """
5
  User-defined macro to push a 32 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.
7
  Usage:
8
    .push32(v)
9
  where
10
    v           is a 32-bit value, a constant, or an evaluated expression\n
11
  The effect is to push v%0x100, int(v/2**8)%0x100, int(v/2**16)%0x100, and
12
  int(v/2**24)%0x100 onto the data stack.\n
13
  ( - u_LSB u u u_MSB )
14
  """
15
 
16
  # Add the macro to the list of recognized macros.
17
  ad.AddMacro('.push32', 4, [ ['','singlevalue','symbol'] ]);
18
 
19
  # Define the macro functionality.
20
  def emitFunction(ad,fp,argument):
21
    argument = argument[0];
22
    if argument['type'] == 'value':
23
      v = argument['value'];
24
    elif argument['type'] == 'symbol':
25
      name = argument['value'];
26
      if not ad.IsSymbol(name):
27
        raise asmDef.AsmException('Symbol "%s" not recognized at %s' % (argument['value'],argument['loc'],));
28
      ix = ad.symbols['list'].index(name);
29
      v = ad.symbols['body'][ix];
30
      if len(v) != 1:
31
        raise asmDef.AsmException('Argument can only be one value at %s' % argument['loc']);
32
      v = v[0];
33
    else:
34
      raise asmDef.AsmException('Argument "%s" of type "%s" not recognized at %s' % (argument['value'],argument['type'],argument['loc'],));
35
    if type(v) != int:
36
      raise Exception('Program Bug -- value should be an "int"');
37
    ad.EmitPush(fp,v%0x100,''); v >>= 8;
38
    ad.EmitPush(fp,v%0x100,''); v >>= 8;
39
    ad.EmitPush(fp,v%0x100,''); v >>= 8;
40
    printValue = argument['value'] if type(argument['value']) == str else '0x%08X' % argument['value'];
41
    ad.EmitPush(fp,v%0x100,'.push32(%s)' % printValue);
42
  ad.EmitFunction['.push32'] = emitFunction;

powered by: WebSVN 2.1.0

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