ARM Technical Support Knowledge Articles

TABLES WITH CALCULATED VALUES

Applies to: A51 Macro Assembler

Answer


Information in this article applies to:


QUESTION

Is there an easy way in assembly to create a table of values that are calculated at assemble-time?

ANSWER

There are several ways to do this. For tables that use values that are outside the range supported by the A51 assembler, you may create a table in C and generate assembler output. For example, the following C file:

#pragma SRC

#define DIVISOR   517
#define STEP     4165

code unsigned int J_TABLE [] =
  {
  (1 * STEP) / DIVISOR,
  (2 * STEP) / DIVISOR,
  (3 * STEP) / DIVISOR,
  (4 * STEP) / DIVISOR,
  (5 * STEP) / DIVISOR,
  };

Generates the following .SRC file when compiled.

?CO?TEST             SEGMENT CODE
        PUBLIC  J_TABLE

        RSEG  ?CO?TEST
J_TABLE:
        DW      00008H
        DW      00010H
        DW      00018H
        DW      00020H
        DW      00028H

; #pragma SRC
;
; #define DIVISOR   517
; #define STEP     4165
;
; code unsigned int J_TABLE [] =
;   {
;   (1 * STEP) / DIVISOR,
;   (2 * STEP) / DIVISOR,
;   (3 * STEP) / DIVISOR,
;   (4 * STEP) / DIVISOR,
;   (5 * STEP) / DIVISOR,
        END

Which you can either include in your assembler files or use as an external table.

Article last edited on: 2001-01-18 00:00:00

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential