Search code examples
assemblymipsmips32opcode

MIPS-32 Opcode Format: Uppercase or Lowercase?


I'm currently taking a course in computer organization and I've been studying MIPS-32 architecture. I've noticed that the book we use lists the Opcodes all in lowercase, whereas the Professor lists the Opcodes all in uppercase. I looked this up on different websites and noticed that some websites had the Opcodes as all uppercase and others all as lowercase. I looked for a similar question on Stack overflow but couldn't find any.

For example, to add, we can have this:

ADD $s2, $s1, $s0

But, other websites and the book have it as:

add $s2, $s1, $s0

Could anyone clarify which Opcode format is more conventional? I haven't built an assembly language program yet, so I am not exactly sure if Opcodes are case-sensitive; are they?

N.B. The book I'm using is Computer Organization and Design MIPS Edition: The Hardware/Software Interface by David A. Patterson and John L. Hennessy.


Solution

  • Those aren't opcodes (part of binary machine code), they're just asm mnemonics, text input to an assembler. (Note that "opcode" sometimes gets used to mean a whole instruction in binary, including the parts that encode the operands, but that's silly because we already have the word "instruction" for that.)

    Most assemblers (and all MIPS assemblers AFAIK) are case-insensitive for mnemonics and register names.
    One good modern style convention is to use lower-case for real mnemonics and upper-case for macros.

    All upper-case (including for operands) used to be common, especially for 8-bit / 16-bit CPUs and microcontrollers (and even older early computers), but certainly used by some people for other systems, including more modern ones. Some of that was/is inertia from systems which only supported upper-case: see When did assembly source code begin to be written in lowercase? on retrocomputing.SE.

    In documentation, where you want to freely mix instruction names with text and talk about instructions, it's common to write mnemonics in all CAPS, although bold or code work too. Books and materials that have a print format in mind often favours CAPS. Online stuff, e.g. Stack Overflow answers often use code, but it can look messy in a paragraph with too many instruction or register names. CAPS tends to remain readable without drawing the eye from elsewhere in the paragraph (like this one), and can be easier to type depending on the system. (SO markdown makes code easy.)

    AND, OR, and ADD are common instructions that would be really confusing in a sentence if you didn't do anything to make them different. Less so ADDIU.

    In actual asm source files, the format of each line is fairly rigid, with comments usually indented off to the right starting at a consistent column, and always set apart by a special character (# in standard MIPS assembly). This avoids any ambiguity, although in a comment I might use that upper case convention when mixing with free-form text;

    addu $t0, $t1, $t2    # not ADD because we don't want to fault on signed overflow