Keil Logo

A51: TABLES WITH CALCULATED VALUES


Information in this article applies to:

  • C51 Version 5.50a
  • C51 Version 6.10a

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.

Last Reviewed: Thursday, January 18, 2001


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.