Re: Programming: Not stressful? Yeah, right...
- From: "Arthur J. O'Dwyer" <ajo@xxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 30 Oct 2005 11:22:16 -0500 (EST)
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 .
- Follow-Ups:
- Re: Programming: Not stressful? Yeah, right...
- From: spinoza1111
- Re: Programming: Not stressful? Yeah, right...
- From: Richard Harter
- Re: Programming: Not stressful? Yeah, right...
- References:
- Programming: Not stressful? Yeah, right...
- From: Dave
- Re: Programming: Not stressful? Yeah, right...
- From: spinoza1111
- Programming: Not stressful? Yeah, right...
- Prev by Date: Re: seamless scrolling back
- Next by Date: Re: seamless scrolling back
- Previous by thread: Re: Programming: Not stressful? Yeah, right...
- Next by thread: Re: Programming: Not stressful? Yeah, right...
- Index(es):
Relevant Pages
|