|
Prev: prova
Next: time to leave?
From: rio on 2 Aug 2008 12:19 -Is it better programming in asm using top-down or bottom-up? i find good write a routine for resolve a problem. if that routine become too complex i begin to write function for sub-problems; this means i use top-down right? -is it better to have, for heavy use, a 256 table of dword or a 256 table of bytes something like xor eax, eax mov al, [esi] cmp byte[MyTable+a], 0 je .3 xor eax, eax mov al, [esi] cmp dword[MyTable+a], 0 je .3
From: NathanCBaker on 2 Aug 2008 13:58 On Aug 2, 12:19 pm, "rio" <a...(a)b.c> wrote: > -Is it better programming in asm using top-down or bottom-up? > i find good write a routine for resolve a problem. > if that routine become too complex i begin to write function > for sub-problems; this means i use top-down right? > It used to be advertised that those answers can be found here: http://betov.free.fr/B_U_Asm.zip > -is it better to have, for heavy use, a 256 table of dword > or a 256 table of bytes > something like > xor eax, eax > mov al, [esi] If the above two lines were replaced with... movzx eax, byte [esi] ...would it be faster? > cmp byte[MyTable+a], 0 > je .3 > > xor eax, eax > mov al, [esi] > cmp dword[MyTable+a], 0 > je .3 I think dword ops are generally faster. I can never remember what is faster on modern CPUs.... is 'xor eax, eax' faster than 'mov eax, 0' ??? is 'add ecx, 1' faster than 'inc ecx' ??? I suppose that we can pretend to be an important scientist working on the Large Hadron Collider. The fate of the entire world rests on our willingness to conduct a few tests! ;-) Nathan.
From: Rod Pemberton on 3 Aug 2008 03:31 "rio" <a(a)b.c> wrote in message news:489488b3$0$41665$4fafbaef(a)reader4.news.tin.it... > -Is it better programming in asm using top-down or bottom-up? In assembly, I tend to think about the available registers, and design the code to work around that. In C, I tend to use top-down and implement some elements of the bottom layer as I'm writing and thinking about them. For C, this gives an overall balance to the development of the application. Many programmers have one method they prefer. If they start at the top, they usually have problems with implementing the bottom and if they start at the bottom, problems with the top. > i find good write a routine for resolve a problem. > if that routine become too complex i begin to write function > for sub-problems; this means i use top-down right? http://en.wikipedia.org/wiki/Top-down Rod Pemberton
From: Alexei A. Frounze on 3 Aug 2008 04:29 On Aug 3, 12:31 am, "Rod Pemberton" <do_not_h...(a)nohavenot.cmm> wrote: > "rio" <a...(a)b.c> wrote in message > > news:489488b3$0$41665$4fafbaef(a)reader4.news.tin.it... > > > -Is it better programming in asm using top-down or bottom-up? > > In assembly, I tend to think about the available registers, and design the > code to work around that. In C, I tend to use top-down and implement some > elements of the bottom layer as I'm writing and thinking about them. For C, > this gives an overall balance to the development of the application. > > Many programmers have one method they prefer. If they start at the top, > they usually have problems with implementing the bottom and if they start at > the bottom, problems with the top. > > > i find good write a routine for resolve a problem. > > if that routine become too complex i begin to write function > > for sub-problems; this means i use top-down right? > > http://en.wikipedia.org/wiki/Top-down > > Rod Pemberton I'd say, normally it's a mix of both approaches. The balance, however, depends on our skills/experience and understanding the entire problem and its parts. I've recently completed a fairly large application (> 30 KLOC) in the area I was already very well familiar with when I began. I did some preliminary design on the drawing board and paper and coded up a few well-defined, relatively small and rather independent parts of the app. Then I needed to decide exactly how they would fit into the picture (not in general -- that I knew, but actually). I made a decision and moved on to the next part. Every time it was like further narrowing down the design, coding up one or two components, integrating them and repeating this until the app is done. Of course, there was some testing of the components and their integration which revealed a number of implementation bugs and a few design issues. Step by step, the execution was like this: 1. general design, low to medium level of detail (inexact APIs) 2. implement first component(s) 3. design refinement (if needed) 4. implement more components and test them (and fix bugs if needed) 5. integrate the new components and do some integration/system testing (and bug fixing if needed) 6. if not done, goto 3 7. test the whole app and fix any bugs found in it Maybe "iterative" is a more appropriate word here than top-down or bottom-up. Seems like this similar to what you've described about your approach in C. Alex
From: Wolfgang Kern on 3 Aug 2008 04:41
Nathan (Evenbit) wrote: Rosario asked: >> -Is it better programming in asm using top-down or bottom-up? >> i find good write a routine for resolve a problem. >> if that routine become too complex i begin to write function >> for sub-problems; this means i use top-down right? > It used to be advertised that those answers can be found here: > http://betov.free.fr/B_U_Asm.zip Rene will be pleased..., but RosAsm seem to mean the order of teaching things with bot2up. >> -is it better to have, for heavy use, a 256 table of dword >> or a 256 table of bytes >> something like >> xor eax, eax >> mov al, [esi] > If the above two lines were replaced with... movzx eax, byte [esi] ....would it be faster? Yes, it saves on one dependency stall and needs one byte less. >> cmp byte[MyTable+a], 0 >> je .3 >> xor eax, eax >> mov al, [esi] >> cmp dword[MyTable+a], 0 >> je .3 > I think dword ops are generally faster. I can never remember what is > faster on modern CPUs.... This merely depend an access alignment, I cannot confirm that byte access is any slower than dword access. Except for the weird: apart read of four consective bytes. > is 'xor eax, eax' faster than 'mov eax, 0' ??? Same speed, but the shorter may save some cycles in surrounding code. > is 'add ecx, 1' faster than 'inc ecx' ??? Not at all on AMDs, and again the shorter will win. [seems this old Intel optimisation made it into public guessing] This two aren't identical instructions anyway, but beside this: ADD dword [ecx],1 are three more bytes than: ADD dword [ecx],byte 1 which show same speed as: INC dword [ecx] but INC [reg] are only two bytes. INC byte [ecx] may suffer on alignment and partial write ADD byte [ecx],1 but here too. > I suppose that we can pretend to be an important scientist working on > the Large Hadron Collider. The fate of the entire world rests on our > willingness to conduct a few tests! ;-) :) I just rely on the output from my own tools. __ wolfgang |