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

Subversion Repositories ssbcc

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

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 4 sinclairrf
from asmDef import AsmException
4
 
5 3 sinclairrf
def fetchvector(ad):
6
  """
7
  Built-in macro to move multiple bytes from memory to the data stack.  The byte
8
  at the specified memory address is stored at the top of the data stack with
9
  subsequent bytes store below it.\n
10
  Usage:
11
    .fetchvector(variable,N)
12
  where
13
    variable    is the name of a variable
14
    N           is the constant number of bytes to transfer\n
15
  The effect is to push the values u_LSB=variable[N-1], ..., u_msb=variable[0]
16
  onto the data stack.\n
17
  ( - u_LSB ... u_MSB )
18
  """
19
 
20
  def length(ad,argument):
21 4 sinclairrf
    N = ad.Emit_IntegerValue(argument[1]);
22
    if not (N > 0):
23
      raise asmDef.AsmException('Vector length must be positive at %s' % argument[1]['loc']);
24
    return N+1;
25 3 sinclairrf
 
26
  # Add the macro to the list of recognized macros.
27
  ad.AddMacro('.fetchvector', length, [
28
                                        ['','symbol'],
29
                                        ['','singlevalue','symbol']
30
                                      ]);
31
 
32
  # Define the macro functionality.
33
  def emitFunction(ad,fp,argument):
34
    variableName = argument[0]['value'];
35
    (addr,ixBank,bankName) = ad.Emit_GetAddrAndBank(variableName);
36 4 sinclairrf
    N = ad.Emit_IntegerValue(argument[1]);
37
    offsetString = '%s-1' % argument[1]['value'] if type(argument[0]['value']) == str else '%d-1' % N;
38
    ad.EmitPush(fp,addr+N-1,'%s+%s' % (variableName,offsetString));
39 3 sinclairrf
    for dummy in range(N-1):
40
      ad.EmitOpcode(fp,ad.specialInstructions['fetch-'] | ixBank,'fetch- '+bankName);
41
    ad.EmitOpcode(fp,ad.specialInstructions['fetch'] | ixBank,'fetch '+bankName);
42 4 sinclairrf
 
43 3 sinclairrf
  ad.EmitFunction['.fetchvector'] = emitFunction;

powered by: WebSVN 2.1.0

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