Редактирование: Константы
Внимание! Вы не авторизовались на сайте. Ваш IP-адрес будет публично видимым, если вы будете вносить любые правки. Если вы войдёте или создадите учётную запись, правки вместо этого будут связаны с вашим именем пользователя, а также у вас появятся другие преимущества.
Правка может быть отменена. Пожалуйста, просмотрите сравнение версий, чтобы убедиться, что это именно те изменения, которые вас интересуют, и нажмите «Записать страницу», чтобы изменения вступили в силу.
Текущая версия | Ваш текст | ||
Строка 1: | Строка 1: | ||
CONST := | CONST := | ||
− | ['-'] NUMBER # | + | ['-'] NUMBER # Decimal integer |
− | | 's_' FP # | + | | 's_' FP # Single-precision float |
− | | 'd_' FP # | + | | 'd_' FP # Double-precision float |
− | | $IDENT # | + | | $IDENT # Global symbol |
− | |||
− | |||
− | + | Throughout the IL, constants are specified with a unified syntax and semantics. Constants are immediates, meaning that they can be used directly in instructions; there is no need for a "load constant" instruction. | |
− | |||
− | + | The representation of integers is two's complement. Floating-point numbers are represented using the single-precision and double-precision formats of the IEEE 754 standard. | |
− | + | ||
+ | Constants specify a sequence of bits and are untyped. They are always parsed as 64-bit blobs. Depending on the context surrounding a constant, only some of its bits are used. For example, in the program below, the two variables defined have the same value since the first operand of the subtraction is a word (32-bit) context. | ||
%x =w sub -1, 0 | %x =w sub -1, 0 | ||
%y =w sub 4294967295, 0 | %y =w sub 4294967295, 0 | ||
− | + | Because specifying floating-point constants by their bits makes the code less readable, syntactic sugar is provided to express them. Standard scientific notation is prefixed with s_ and d_ for single and double precision numbers respectively. Once again, the following example defines twice the same double-precision constant. | |
− | |||
%x =d add d_0, d_-1 | %x =d add d_0, d_-1 | ||
%y =d add d_0, -4616189618054758400 | %y =d add d_0, -4616189618054758400 | ||
− | + | Global symbols can also be used directly as constants; they will be resolved and turned into actual numeric constants by the linker. | |
− | |||
− |