mirror of
https://github.com/cc65/cc65.git
synced 2024-11-19 06:31:31 +00:00
Added zilog/intel style hex numbers
git-svn-id: svn://svn.cc65.org/cc65/trunk@3242 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
843c183698
commit
d204e4a1ad
@ -402,10 +402,10 @@ name="http://www.6502.org/source/interpreters/sweet16.htm">.
|
|||||||
|
|
||||||
<sect1>Number format<p>
|
<sect1>Number format<p>
|
||||||
|
|
||||||
For literal values, the assembler accepts the widely used number formats:
|
For literal values, the assembler accepts the widely used number formats: A
|
||||||
A preceeding '$' denotes a hex value, a preceeding '%' denotes a
|
preceeding '$' or a trailing 'h' denotes a hex value, a preceeding '%'
|
||||||
binary value, and a bare number is interpeted as a decimal. There are
|
denotes a binary value, and a bare number is interpeted as a decimal. There
|
||||||
currently no octal values and no floats.
|
are currently no octal values and no floats.
|
||||||
|
|
||||||
|
|
||||||
<sect1>Conditional assembly<p>
|
<sect1>Conditional assembly<p>
|
||||||
|
@ -72,19 +72,15 @@
|
|||||||
enum Token Tok = TOK_NONE; /* Current token */
|
enum Token Tok = TOK_NONE; /* Current token */
|
||||||
int WS; /* Flag: Whitespace before token */
|
int WS; /* Flag: Whitespace before token */
|
||||||
long IVal; /* Integer token attribute */
|
long IVal; /* Integer token attribute */
|
||||||
char SVal [MAX_STR_LEN+1]; /* String token attribute */
|
char SVal[MAX_STR_LEN+1]; /* String token attribute */
|
||||||
|
|
||||||
FilePos CurPos = { 0, 0, 0 }; /* Name and position in current file */
|
FilePos CurPos = { 0, 0, 0 }; /* Name and position in current file */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Struct to handle include files. Note: The length of the input line may
|
/* Struct to handle include files. */
|
||||||
* not exceed 255+1, since the column is stored in the file position struct
|
typedef struct InputFile InputFile;
|
||||||
* as a character. Increasing this value means changing the FilePos struct,
|
struct InputFile {
|
||||||
* and the read and write routines in the assembler and linker.
|
|
||||||
*/
|
|
||||||
typedef struct InputFile_ InputFile;
|
|
||||||
struct InputFile_ {
|
|
||||||
FILE* F; /* Input file descriptor */
|
FILE* F; /* Input file descriptor */
|
||||||
FilePos Pos; /* Position in file */
|
FilePos Pos; /* Position in file */
|
||||||
enum Token Tok; /* Last token */
|
enum Token Tok; /* Last token */
|
||||||
@ -94,8 +90,8 @@ struct InputFile_ {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Struct to handle textual input data */
|
/* Struct to handle textual input data */
|
||||||
typedef struct InputData_ InputData;
|
typedef struct InputData InputData;
|
||||||
struct InputData_ {
|
struct InputData {
|
||||||
char* Data; /* Pointer to the data */
|
char* Data; /* Pointer to the data */
|
||||||
const char* Pos; /* Pointer to current position */
|
const char* Pos; /* Pointer to current position */
|
||||||
int Malloced; /* Memory was malloced */
|
int Malloced; /* Memory was malloced */
|
||||||
@ -752,20 +748,63 @@ Again:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Decimal number? */
|
/* Number? */
|
||||||
if (IsDigit (C)) {
|
if (IsDigit (C)) {
|
||||||
|
|
||||||
/* Read the number */
|
char Buf[16];
|
||||||
IVal = 0;
|
unsigned Digits;
|
||||||
while (IsDigit (C)) {
|
unsigned Base;
|
||||||
if (IVal > (long) (0xFFFFFFFFUL / 10)) {
|
unsigned I;
|
||||||
Error ("Overflow in decimal number");
|
long Max;
|
||||||
IVal = 0;
|
unsigned DVal;
|
||||||
}
|
|
||||||
IVal = (IVal * 10) + DigitVal (C);
|
/* Ignore leading zeros */
|
||||||
|
while (C == '0') {
|
||||||
NextChar ();
|
NextChar ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Read the number into Buf counting the digits */
|
||||||
|
Digits = 0;
|
||||||
|
while (IsXDigit (C)) {
|
||||||
|
|
||||||
|
/* Buf is big enough to allow any decimal and hex number to
|
||||||
|
* overflow, so ignore excess digits here, they will be detected
|
||||||
|
* when we convert the value.
|
||||||
|
*/
|
||||||
|
if (Digits < sizeof (Buf)) {
|
||||||
|
Buf[Digits++] = C;
|
||||||
|
}
|
||||||
|
|
||||||
|
NextChar ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allow zilog/intel style hex numbers with a 'h' suffix */
|
||||||
|
if (C == 'h' || C == 'H') {
|
||||||
|
NextChar ();
|
||||||
|
Base = 16;
|
||||||
|
Max = 0xFFFFFFFFUL / 16;
|
||||||
|
} else {
|
||||||
|
Base = 10;
|
||||||
|
Max = 0xFFFFFFFFUL / 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert the number using the given base */
|
||||||
|
IVal = 0;
|
||||||
|
for (I = 0; I < Digits; ++I) {
|
||||||
|
if (IVal > Max) {
|
||||||
|
Error ("Number out of range");
|
||||||
|
IVal = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DVal = DigitVal (Buf[I]);
|
||||||
|
if (DVal > Base) {
|
||||||
|
Error ("Invalid digits in number");
|
||||||
|
IVal = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
IVal = (IVal * Base) + DVal;
|
||||||
|
}
|
||||||
|
|
||||||
/* This is an integer constant */
|
/* This is an integer constant */
|
||||||
Tok = TOK_INTCON;
|
Tok = TOK_INTCON;
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user