6 ms·
It's all convention. Personally, I'd like more arithmetic convention. Instead of: MYARRAY: DEFW 100 ADD R1,R5,R7 MVI R2,R1,MYARRAY how about: MYARRAY
by drpixie 3y ago
It's all convention. Personally, I'd like more arithmetic convention. Instead of:
MYARRAY: DEFW 100
ADD R1,R5,R7
MVI R2,R1,MYARRAY
how about:
MYARRAY: WORD[100]
R1 = R5+R7
MYARRAY[R2] = R1
Not much harder top parse, and much easier to read. I see a couple of minor issues: needs a tweak to differentiate between (say) ADD and ADC; and assembler generally is small change, we're not putting much effort into it.
- vidarh 3y agoWell, this is the kind of thing HLA does (also see my other comment in this thread about a compiler I wrote), but in practice there's little demand - most of the people who write asm are used to the conventions, and few people who write asm write much of it.
- eimrine 3y agoThis is not much easier to read, this is just on much higher level. A processor does not have a conception of brackets. Infix notation blurs the real number of operations. Processor has registers and your code does not say what you are putting in EAX what in EBX etc.
- drpixie 3y agoTo be fair - the processor only has binary opcodes & operands :) My example wasn't clear enough - I wasn't proposing full expression compiling. If you think (simplistically) of assembler as a macro processor that maps text mnemonics onto opcodes, I was proposing matching basic expression terms to opcodes (but only simple terms, like "x + y", that map to individual instructions). Historically, there have been assemblers that do full expression compiling - where an expression compiles to multiple opcodes. But that's going back a way, when people still routinely used assembly. For modern purposes, where good compilers are easily available, something like that just confuses assembly with compilation.
- jcranmer 3y agoExcept it doesn't scale that well to all of the different operations. How do you distinguish between a signed and an unsigned high multiply? What do you do for operations like count-trailing-zeros or popcount, which don't map to standard operator symbols? How do you distinguish between nontemporal loads, atomic loads, sign-extended byte-to-word loads, etc.? There are a couple of different ways to understand assembly. Writing it with C-like infix expressions is a superior way to look at the code if you're trying to understand what it's doing on an algorithmic level (there's a reason we don't really hand-write assembly, after all!). But if you're working on assembly-level tooling, usually, you want very clear indications of what instruction you're working with, and "out_operands = opcode in_operands" or "opcode operands" are much, much clearer representations for such work. Most of the people who work with assembly care about the latter, and so the latter representation is more useful for them, and that's why we write assembly the way we do.
- unnah 3y agoI had a look at the TI SHARC manual at https://www.analog.com/media/en/dsp-documentation/processor-manuals/adsp-2136x_2137x_214xx_pgr_rev2.4.pdf https://www.analog.com/media/en/dsp-documentation/processor-... to see how they did it. It seems to me that the SHARC assembly instructions would tell you the exact variant with the same precision as the traditional cryptic mnemonics. Multiplication results are stored in a double-length result register called MRF. The type of inputs is indicated by a modifier word in parentheses, so that multiplication between two signed integers is indicated as MRF = R2 * R3 (SSI); whereas multiplication between a signed and unsigned integer is MRF = R2 * R3 (SUI); There is no popcount, but binary log is written like R2 = LOGB F3; and presumably similar notation could be used for popcount. Cache access seems to be controlled by mode bits in a control register. Sign extension is supported in only a few instructions, but is indicated by the trailing modifier (SE).
- drpixie 3y ago> Except it doesn't scale that well to all of the different operations. How do you distinguish between a signed and an unsigned high multiply? What do you do for operations like count-trailing-zeros or popcount, which don't map to standard operator symbols? How do you distinguish between nontemporal loads, atomic loads, sign-extended byte-to-word loads, etc.? Yes - that's where is falls down :(
- Thrymr 3y agoWhy not just use C?
- drpixie 3y agoDone that on several occasions. There are plenty of projects (and many languages) that compile to C and hand that on to the systems compiler. As an output format, C actually works very well. It hides the fiddly things like register allocation - things that are already done well by gcc and the like.