13.07.2015 Views

TASKING VX-toolset for 8051 User Guide

TASKING VX-toolset for 8051 User Guide

TASKING VX-toolset for 8051 User Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>TASKING</strong> <strong>VX</strong>-<strong>toolset</strong> <strong>for</strong> <strong>8051</strong> <strong>User</strong> <strong>Guide</strong>__rom char hello[] = "Hello\n"; /* initialized array in ROM only */__rom char *world = "world\n"; /* initialized pointerto string in ROM */Example with #pragma romstring:#pragma romstring__rom char hello[] = "Hello\n"; /* initialized array in ROM only */__rom char *world = "world\n"; /* initialized pointerto string in ROM */#pragma ramstringStrings in library routinesLibrary routines containing pointer arguments always expect the target memory of these pointers to bethe default RAM of the memory model used to make this library. For example:int printf( const char *<strong>for</strong>mat, ... );In the large memory model, this means printf() expects the address of the <strong>for</strong>mat string (the firstargument) to have memory type __xdata. There<strong>for</strong>e, the C startup code of the large memory modelcopies all strings from ROM to XDATA. So, the statement:printf( "Hello world\n" );is executed correctly, because the <strong>8051</strong> compiler passes the address of the allocated XDATA area (filledat C startup time) to printf().With the --romstrings option specified, the string is put in ROM only and the standard printf/scanf likelibrary routines will fail.You will need to create your own __rom qualified versions. All library sources aredelivered. For example, you can use the source of printf() (in module printf.c) to create a__rom_printf(). The prototype could be:int __rom_printf( __rom char *<strong>for</strong>mat, ... );Modifying string literalsThe <strong>8051</strong> accepts that string literals are modifiable when strings are in both ROM and RAM. You can dothis with pointers, or even with a construct like:"st ing"[2] = 'r';Of course, when you use the --romstrings option this statement is not allowed.1.9. Switch StatementThe <strong>TASKING</strong> C compiler supports three ways of code generation <strong>for</strong> a switch statement: a jump chain(linear switch), a jump table or a binary search table.30

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!