If my question sounds nonsensical, pardon me, but I am quite confused.
Say I am defining the constant buffer_size and in the code that I am studying there is a line that says: buffer_size equ 16
, which in my mind means, make buffer_size 16 big. But in other code samples that I review, numbers do have the character h
beside them, which I'm told is to tell the assembler to treat the number as hexadecimal.
If a number doesn't have the h
beside it, does it make it decimal then?
Yes, MASM (and pretty much all other modern assemblers1) are like C/C++: numeric literals are decimal by default.
You can use other bases with suffixes. See How to represent hex value such as FFFFFFBB in x86 assembly programming? for the syntax. Some assemblers, like NASM, allow 0x123
as well as 123h
, but MASM only allows suffixes.
10h
in MASM is exactly like 0x10
in C, and exactly equivalent to 16
.
The machine code assembled doesn't depend on the source representation of the number. (mov eax, 10h
is 5 bytes: opcode and then 32-bit little-endian binary number, same as mov eax, 16
.)
The same goes for foo: db 0FFh
: code that adds something to it isn't "adding hex numbers", it's just a normal binary number. (A common beginner mistake (in terminology or understanding, it's usually not clear which) is to confuse the source-code representation with what the machine is doing when it runs the assembler output.)
Footnote 1: Ancient assemblers might be different. There might be a few assemblers for some non-x86 platforms that also don't default to decimal.
The one built-in to the obsolete DOS DEBUG.EXE treats all numeric literals as hex, so mov ax, 10
= mov ax, 8+8
. (If it even evaluates constant expressions, but if not then you know what I mean.)
DEBUG.EXE doesn't even support labels, so it's basically horrible by modern standards; don't use it. These days there are free open-source assemblers like NASM, and also debuggers including at least the one built-in to BOCHS, so there's no need to suffer with old tools.
Anyway, this sidetrack about DEBUG.EXE isn't really relevant to your question about MASM; I only mention it as the only example I know of of an assembler that doesn't default to decimal. They do exist, but it's not normal these days.