Is assembly code and machine code specified by the architecture? I know that how you implement the architecutre is uo to you(it is up the microarchitecture can implement the architecture). But I don't understand if the assembly or machine code is specified by the architecture?

- 328,167
- 45
- 605
- 847

- 243
- 1
- 10
-
A distinction can be made up, but it doesn't matter in practice. Eventually, to create or run a program, you need machine code, and for writing/generating machine code, you need to know the architecture, and maybe (for optimizations) the microarchitecture. – pts Dec 16 '22 at 19:11
-
The notion *instruction set architecture* also includes specifying the machine code: https://en.wikipedia.org/wiki/Instruction_set_architecture – pts Dec 16 '22 at 19:12
-
1There may be many different assembly syntaxes for the same instruction set architecture. For example, for 32-bit x86, there are: MASM, TASM, TASM ideal mode, NASM, FASM, GNU as (AT&T syntax), and many more. – pts Dec 16 '22 at 19:14
-
The microarchitecture is effectively "set in stone" by the manufacturer. We're not able to program in microcode even if we wanted to. Machine code is the "lowest" form of programming that we, the end users, can reach. (Unless you're creating your own CPU architecture of course.) – puppydrum64 Dec 22 '22 at 14:32
1 Answers
Machine code is decoded by the CPU; its format, and the behaviour of each instruction, are part of the instruction-set architecture implemented by the CPU.
Assembly source code is arbitrary, only dealt with by software (assemblers and disassemblers). As @old_timer likes to say, assembly is defined by the software tool, not the CPu.
Often the vendor will define an asm syntax so they can use it in their manual when documenting how the ISA works, like register names and instruction names. So it gets used in the ISA documentation, but primarily as a way to describe it to humans. (Or also as a specification for an assembly language recommended by the vendor.)
- What's the relationship between assembly language and machine language?
- Are Instruction set architecture binary (not readable) or human-readable?
- Do assembly instructions map 1-1 to machine language? - mostly yes, but some allow pseudo-instructions
- What is the relation between machine code and assembly language?
For many real-world ISAs, nobody felt the need to invent a different text syntax for the same machine-code format. (Except maybe Go and the Plan 9 ecosystem it's derived from.)
But some ISAs, most notoriously x86, have many different text syntaxes. x86 machine code has some redundancy in how the same instruction can be encoded, and some syntaxes allow overrides to specify the details. But that wasn't the reason for people inventing different syntaxes.
There are multiple flavours of Intel syntax (https://stackoverflow.com/tags/intel-syntax/info), the syntax used in Intel and AMD's manuals. MASM/TASM are very similar, vs. NASM/FASM having some different interpretations. And that's just for the instruction syntax; directives also differ between assemblers that mostly agree on the syntax for instructions, operands, and addressing modes.
AT&T was designed to look more like PDP-11 syntax, with destination operand on the right, and with %
decorations on register names to make parsing simpler. https://stackoverflow.com/tags/att/info

- 328,167
- 45
- 605
- 847