Literals/Integer: Difference between revisions

Content added Content deleted
Line 1,355: Line 1,355:


Metafont numbers can't be greater than 4096, so that the maximum octal and hexadecimal legal values are <tt>7777</tt> and <tt>FFF</tt> respectively. To be honest, <tt>"100"</tt> is a string, and <tt>oct</tt> is an "internal" "''macro''"; but this is the way Metafont specifies numbers in base 8 and 16.
Metafont numbers can't be greater than 4096, so that the maximum octal and hexadecimal legal values are <tt>7777</tt> and <tt>FFF</tt> respectively. To be honest, <tt>"100"</tt> is a string, and <tt>oct</tt> is an "internal" "''macro''"; but this is the way Metafont specifies numbers in base 8 and 16.

=={{header|MIPS Assembly}}==
This ultimately depends on the assembler you're using.
{{works with|https://github.com/Kingcom/armips ARMIPS}}
Hexadecimal numbers are prefixed with <tt>0x</tt>, binary with <tt>0b</tt>. A number with no prefix is decimal.

If fewer than the maximum number of digits is specified, the number is padded with zeroes to fill the declared space.

<code>.byte</code> is 8-bit, <code>.halfword</code> is 16-bit, and <code>.word</code> is 32-bit.

The endianness of your CPU determines what order the bytes are actually stored in. Bytes are always stored in the order they are declared, but words and halfwords will be endian-swapped if you are assembling for a little-endian MIPS CPU such as the PlayStation 1. On a big-endian MIPS CPU (e.g. Nintendo 64), words and halfwords are assembled as-is.

You can have multiple declarations on the same line separated by commas, and if you do, you only need to specify the data type once for that entire line. (Everything in that line is understood to be the same data type.) Or, you can put each on its own line with the data type declaration in front of each. Either way, the memory layout of the declared literals is the same. How you present the data in your source code is up to you, so it's best to display it in a way that maximizes readability and communicates your intent.

<lang mips>.word 0xDEADBEEF
.byte 0b00000000,0b11111111,0,255
.halfword 0xCAFE,0xBABE</lang>


=={{header|Modula-3}}==
=={{header|Modula-3}}==