Re: Programming: Not stressful? Yeah, right...
- From: cri@xxxxxxxx (Richard Harter)
- Date: Mon, 31 Oct 2005 06:26:21 GMT
On Sun, 30 Oct 2005 11:22:16 -0500 (EST), "Arthur J. O'Dwyer"
<ajo@xxxxxxxxxxxxxxxxxxxxx> wrote:
>
>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:
I disagree. I found it better to comment each line tersely to the
right and also put in header blocks. The function of the line comment
is only to annotate the line; the function of heading comment blocks
is to explain intent and strategy.
Richard Harter, cri@xxxxxxxx
http://home.tiac.net/~cri, http://www.varinoma.com
I started out in life with nothing.
I still have most of it left.
.
- References:
- Programming: Not stressful? Yeah, right...
- From: Dave
- Re: Programming: Not stressful? Yeah, right...
- From: spinoza1111
- Re: Programming: Not stressful? Yeah, right...
- From: Arthur J. O'Dwyer
- Programming: Not stressful? Yeah, right...
- Prev by Date: Re: What is a "null loop" in the programming language context?
- Next by Date: Re: Programming: Not stressful? Yeah, right...
- Previous by thread: Re: Programming: Not stressful? Yeah, right...
- Next by thread: Re: Programming: Not stressful? Yeah, right...
- Index(es):