Re: Programming: Not stressful? Yeah, right...




On Sun, 30 Oct 2005 spinoza1111@xxxxxxxxx wrote: ["Helpful" tips for assembly programming]

(1) Think in terms of the goal of each set of instructions and hang a comment to the right of each set (but don't comment every line).

Good advice, except that I'd replace "to the right of" with "above."
The problem with "to the right" comments is that as soon as you start
putting comments and code on the same line, you have to face a tradeoff
among having short lines, having readable comments, and having maintainable code formatting. Consider:


movl (%ebx,%esi,4),%eax # If array[esi] is less than array[edi]...
movl (%ebx,%edi,4),%edx
cmpl %eax,%edx
jnle @swapped # then swap the array elements and set our "swapped flag" ecx to 1
mov %eax,(%ebx,%edi,4)
mov %edx,(%ebx,%esi,4)
mov $1,%ecx
@swapped:


versus

        movl    (%ebx,%esi,4),%eax   # If array[esi] is
        movl    (%ebx,%edi,4),%edx   # less than array[edi]...
        cmpl    %eax,%edx
        jnle    @swapped             # then swap the array elements
        mov     %eax,(%ebx,%edi,4)   # and set our "swapped flag"
        mov     %edx,(%ebx,%esi,4)   # ecx to 1
        mov     $1,%ecx
      @swapped:

versus

          # If array[esi] is less than array[edi],
          # then swap the array elements and set our
          # "swapped flag" ecx to 1.
        movl    (%ebx,%esi,4),%eax
        movl    (%ebx,%edi,4),%edx
        cmpl    %eax,%edx
        jnle    @swapped
        mov     %eax,(%ebx,%edi,4)
        mov     %edx,(%ebx,%esi,4)
        mov     $1,%ecx
      @swapped:


(2) Use "virtually structured" style such that if you use go to, it
flows downward, not to instructions but to pseudo-instruction
placeholders defined only as the location of the next instruction
(often called EQ or EQUATE), or upward to a similar statement in a
structured loop.

Huh? Does anyone know what Nilges is trying to say? It looks to me like his "pseudo-instructions" are what people these days call "labels."

A "virtually structured" assembler program is one whose flowchart is
restricted to the Bohm-Jacopini structured constructs exclusively.

(Some people would get rid of the word "virtually" in that sentence. I don't think it adds any useful meaning.)

(3) Make friends with the macro processor for common small sequences of
instructions. In C the corresponding preprocessor is mostly a waste of
time whereas in assembler it allows the symbolic representation of
otherwise generically named registers and facilities and processing
that depends upon conditions set at assembler time.

Good advice.

(4) Use Hungarian notation

Bad advice. Although I suppose it's possible to make a slightly better case for HN in some assembly languages than in high-level languages, where
the typechecking is better --- still, HN should basically be avoided at
all costs. Most assembly languages are obfuscated enough, without adding
extra obfuscation to the names of the labels.


-Arthur
.



Relevant Pages

  • Re: Insert a byte
    ... CLR eax and 'then' ADD? ... will not MOV eax |OR eax,eax become less foreward stalling? ... but in practice there is also a result register with ... therefore the assembler generates ...
    (alt.lang.asm)
  • Re: Multi-Statements Lines
    ... Instructions are not isolated things, ... mov eax 0 ... assembler instructions as having one function. ... bash at learning Windows assembler programming. ...
    (alt.lang.asm)
  • Re: Free x86 C compiler wanted
    ... for this problem you may need to use assembler. ... (theoretically there should be an option for this in the linker). ... has to be right there (a stub, if used, will often complete tasks like ... mov ax, cs ...
    (comp.compilers)
  • Re: Multi-Statements Lines
    ... Instructions are not isolated things, ... mov eax 0 ... a News Group that is supposed to address Assembly Programmers, ... Also when dealing specifically with assembler, it further separates the source from the disassembled code, making it even more difficult to debug nasty problems. ...
    (alt.lang.asm)
  • Multi-Statements Lines
    ... Therefore, i have developed and proposed a new Assembler, with ... Instructions are not isolated things, ... mov eax 0 ... a News Group that is supposed to address Assembly Programmers, ...
    (alt.lang.asm)