4 ms·
> While Intel always used a dst, src operand ordering for its assembler, there was no particularly compelling reason to adapt this convention and the UNIX assem
by codetrotter 6y ago
> While Intel always used a dst, src operand ordering for its assembler, there was no particularly compelling reason to adapt this convention and the UNIX assembler was written to use the src, dst operand ordering known from the PDP11.
Tangential but I like to see this as sort of two ways of thinking where the operands are in both cases ordered so that what you “have” is closer to “you”.
So in Intel syntax it’s like you are thinking from the CPU perspective and what you “have” are places that you want to put data into. So dst, src.
In AT&T syntax it’s like you are thinking from the perspective of a program, and what you “have” is data that you want to put into places. So src, dst.
I’m not suggesting that this is the reason mind you. Just saying how I like to think about it.
- JJMcJ 6y agoUnix on DEC hardware originally predates even the Intel 4004, so of course they used the DEC standard. Also, GNU as assembler has switches to allow Intel syntax if that's what is desired.
- pjmlp 6y agoIt wasn't always like that, and I am sure it isn't at the same level as nasm/yasm/masm/tasm.
- Someone 6y agoIf that’s true, most programming languages work from the CPU perspective. I think that suggests the syntax may have come from consistency with “A = B” in programming languages (similar to the initially weird looking argument order of strcpy and friends in C), or, maybe, programming languages followed what assemblers did, or the two are similar because of some other common reason. What I don’t like about Intel’s syntax is that the normal phrase is ‘move A to B’, but ‘mov A, B’ moves what’s in B to A. (The reason I don’t like it may be because the first CPU I programmed was a 6502, which had separate load and store instructions. Unfortunately, that doesn’t work well with memory-to-memory (which the 6502 doesn’t have) or register to-register (for which the 6502 used a T for ‘transfer’, as in TXA for ‘copy X register into Accumulator) instructions)
- eru 6y agoMathematical formulas, especially definitions, are often written like E = m * c^2 or pV = n k * T or F = m * a. Ie the simpler stuff often goes to the left. So that tradition might have been where most programming languages picked the convention up from?
- mhh__ 6y agolowercase n should be nRT under modern conventions, to be pedantic (else you're off by a factor of N_a)
- eru 6y agoYes. Though ideally, we would redefine temperature units so we could get rid of R and Avogadro's constant in that formula. Ie so that it becomes T := N / (p * V) where N is measured in number of molecules, not in number of moles. So we'd measure temperature in Joule (or electron-volt) per degree of freedom.
- cbm-vic-20 6y agoAlso, DEC's MACRO-11 looks a lot different than the Bell Labs' Unix "as" assembly, for the same hardware.
- exmadscientist 6y agoI've always understood it as coming from mathematics: if you're used to writing "let X = <complex expression>" in papers, then the high-level syntax "var X = complex_expression();" or low-level syntax "mov dstX, src" are all directly relatable.
- Someone 6y agoBut then, why call it ‘mov’, and not ‘let’, ‘set’, or ‘copy’ (“copy what is in A to B” translates nicely to “copy A,B”)
- ksaj 6y agoWe're similar that way. I think of Intel as saying if you want to retrieve something, you need an accessible place to put it first. So MOV is literally "move into this register I can access, this value that I can't access until it in a register." For example, a wordy version of how I think through MOV AX,5 could be: "move into AX, the value 5" where AX is an accessible container for the value 5. I did assembler coding for more than a decade, so I'm pretty nostalgic about it. Nothing I do really calls for it anymore these days.
- ac42 6y agoIf it's so close to Unix, why do all the C functions have it the other way around? e.g. memcpy(dst,src,n) I've always thought AT&T syntax is made for machines & debugging compiler output while Intel syntax is made for people and large scale coding...