flat assembler
Message board for the users of flat assembler.

Index > Heap > What is the number one goal you keep in mind when coding?

Goto page Previous  1, 2

What is the number one goal you keep in mind when coding?
size
6%
 6%  [ 3 ]
speed
4%
 4%  [ 2 ]
size/speed
33%
 33%  [ 15 ]
OS and/or processor compatibility
2%
 2%  [ 1 ]
easy to understand source code
35%
 35%  [ 16 ]
reliability/strong error checking
11%
 11%  [ 5 ]
nice UI (GUI or TUI)
2%
 2%  [ 1 ]
access/interface to something
0%
 0%  [ 0 ]
easy to configure/customize most stuff
4%
 4%  [ 2 ]
Total Votes : 45

Author
Thread Post new topic Reply to topic
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
I unfortuantely try to get my code the best possible in both speed and size which often causes I don't finish coding at all Smile. But recently I am changing more and more to write readable code rather than perfect one (which is probably unachievable)

Frank: It's OT, but I have to write this Smile. I also created some wrapper for ReadFile once and imho better is:
Code:
;        push    ebx
;        mov     ebx, esp
        invoke  ReadFile, eax, edx, ecx, esp, 0    
Just pass esp (as it will point to the 0 dword in memory). I know it's unclean solution but it works Smile
Post 22 Dec 2005, 20:13
View user's profile Send private message Visit poster's website Reply with quote
Frank



Joined: 17 Jun 2003
Posts: 100
Frank
vid, first parameter always goes to EAX, second parameter to EDX, third parameter to ECX. That's not confusing. STDCALL requires a fixed order of parameters, too.
Reverend, a really nice solution for non-overlapped file IO -- thank you.

Sorry for OT ...
Post 22 Dec 2005, 20:49
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
Frank: Afaic (as far as I code Smile) I didn't have to use overlapped IO, so I always do like this
Post 23 Dec 2005, 00:19
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
hello, vid: I converted your code above to use the "IF" macros, easier to read. Vid and Tomasz have a point though, it is always nice to know how to do the "old school" assembly code to optimize inner-loops of critical code. But for the majority of programming in windows the "IF" macros make your code look organized, easier to make additions to, and more fun to tweak, at least this is my expericence when I began coding the direct3d (and other) examples a while back.

Code:
mov     edx, [n] ;line number
.repeat
        invoke  getline, edx
        mov     ebx, eax  ;line object
        mov     ecx, [n] ;item number
        .repeat
                invoke getitem, ebx
                .if     eax, e, [searchkey]
                        jmp      itemfound
                .endif
                invoke  move_to_next_item, ebx
                sub     ecx, 1
        .until  ecx, e, 0
        invoke  mov_to_next_line
        dec     edx
.until  edx, e, 0
itemfound:
    
Post 23 Dec 2005, 01:55
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
madmatt: well, if you meant assembly-style than okay, these macros are sometimes okay. not always, sometimes branching with jumps comes more natural, like when body of .if block is very large or so. I thought you stand for standard structured HLL code, which by all means is restrictive to algorithmical thinking.

If you think "repeat this [n] times", then ".repeat" is natural solution, but when you think, if this happens (exceptinal case) i want to do this, otherwise use "normal" flow, then jump somewhere outside of normal flow is more natural solution, better than ".if" and +1 indent and one more unidentificable "endif".

But it is matter of personal preference, i agree sometimes these macros come nice, but for me this is much more natural, it reflects way how i see algorithm in my head:
Code:
mov     edx, [n] ;line number 
.repeat 
        invoke  getline, edx 
        mov     ebx, eax  ;line object 
        mov     ecx, [n] ;item number 
        .repeat 
                invoke getitem, ebx 
                cmp eax, [searchkey] 
                je       itemfound 
                invoke  move_to_next_item, ebx 
                sub     ecx, 1 
        .until  ecx, e, 0 
        invoke  mov_to_next_line 
        dec     edx 
.until  edx, e, 0 
itemfound:    
Post 23 Dec 2005, 02:26
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
rob.rice



Joined: 20 Dec 2003
Posts: 54
rob.rice
just getting it to run
every thing else comes after that
Post 19 Feb 2006, 08:34
View user's profile Send private message Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
Frank: I've never heard about fastcall. Could you explain it, please?
Code:
; ------------------------------------------------------------------------------
; Wrapper for the API-function ReadFile
;
; Input:        - EAX = hSource:   handle of source to read from (file, console, ...)
;               - EDX = lpBuffer:  address of buffer receiving the data
;               - ECX = nMaxBytes: max. number of bytes to read
;
; Return:       - EAX:          number of bytes read, or -1 on failure
;
; Interna:      According to the Platform SDK (February 2003), ReadFile sets the
;               number-of-bytes-read variable to zero anyway. Hence we do not
;               need to initialize it ourselves.
;

fastcall read, hSource,lpBuffer,nMaxBytes

        push    ebx

        push    ebx                     ; create space for a DWORD on the stack
        mov     ebx,    esp             ; EBX = address of stack-variable
        stdcall ReadFile, eax,edx,ecx,ebx,0
        cmp     eax,    1               ; set carry-flag if ReadFile returns 0 ( = error)
        pop     eax                     ; EAX = number of bytes read
        sbb     edx,    edx             ; EDX = -1 if error, 0 otherwise
        or      eax,    edx             ; EAX = -1 if error, unchanged otherwise

        pop     ebx

        ret

endp
    

Is the order of registers allways the same? What is passed to EBX?
And how to call this function? I just pass the values to the registers and "call read"?

Thanks!
Post 19 Feb 2006, 16:10
View user's profile Send private message Reply with quote
Frank



Joined: 17 Jun 2003
Posts: 100
Frank
OzzY, see your PM (answered there because I have already been sufficiently off-topic in this thread).
Post 20 Feb 2006, 20:06
View user's profile Send private message Reply with quote
bogdanontanu



Joined: 07 Jan 2004
Posts: 403
Location: Sol. Earth. Europe. Romania. Bucuresti
bogdanontanu
Honestly, the most important think for me is: "Easy to understand code"
all other come seccond, unless i am in avery very tight inner loop... but even there I do prefer writting 2 versions: one that is very easy to understand and one that is super fast.
Post 21 Feb 2006, 07:35
View user's profile Send private message Visit poster's website Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
i use no macroinstructions or includes what so ever, this includes things like 'struc' i build and do everything manually, i do not care if others can read my code aslong as i can Cool, and i add plenty of comments for things that i might forget/not understand if i have written them in the past, my main goal is size/speed

_________________
redghost.ca
Post 22 Feb 2006, 01:22
View user's profile Send private message AIM Address MSN Messenger Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Tomasz Grysztar wrote:
Nonetheless I hope there are some people able to see my point. Wink

Don't worry, I vote for your method Wink

even though I use ifs and other 'structured' things sometimes, I always think how it processes low-level, so in my mind it happens to see only jumps/gotos. IF and only IF some trick works better with gotos/jumps (i.e more efficient code), then I immediately switch and use them at once Smile I just try to select the best from both methods Wink
I see your point, and it's pretty obvious in my C code, I use a lot of gotos which shouldn't even be there, for a high-level language anyway.

bogdanontanu wrote:
Honestly, the most important think for me is: "Easy to understand code"
all other come seccond, unless i am in avery very tight inner loop... but even there I do prefer writting 2 versions: one that is very easy to understand and one that is super fast.

lol
I also end up writing 2 versions, but the 'easier' version usually ends up in 'comments' and 'notes' (text files, etc), because I don't necessary think, in my opinion, that code is what makes programs easier to read, but rather comments/notes, because that's what explains it all (of course, I am refering to proper-designed comments).

I may be wierd, as I know many tell me this, but I care about the CPU how it executes my instructions, and I don't add unnecessary junk just because I am too lazy...

tom tobias wrote:
Thank you! Much appreciated.
Readability is the key to modification of ANY program, in ANY language.


well I disagree a bit here. Asm is a language you choose to code for speed/size most (that's why you end up with it anyway).. after all, why not use C/Pascal/high-level languages if you absolutely don't care about the CPU at *all*..

I do love the idea of easy to understand, and I see your point here, but in assembly, the code is not usually easy to understand, no matter what you try (this is not true in HLLs, but we're in LLS's). In my opinion, proper-designed comments and notes are the elements and keys to readability. Sure, as long as the auther takes care to organize his notes, it will come readable, EVEN if the code is SUPER-OPTIMIZED, you'll understand it well.
The point is, readability in my opinion (in asm) doesn't come from CODE, but from comments/label names.. and if you REALLY don't care about speed/size, I suggest using high-level languages, though, as their code is easier to understand than asm code.. notice I said code not comments.. I hope you get my point.

Of course, don't expect someone with no asm experience to be able to modify something.. not everyone is Einstein either Smile
and also, I think it's pretty false to consider something more readable than another, because that depends on the one who's reading it, and his styles/likes/preferences/experience.. sure if you say for the majority then you end up with a true statement.


I like easy to read comments and proper designed notes that explain what the authoer indeed wanted to do at the moment, and that's what really matters, because in this way you end up in thinking for better algorithms/designs, not from his code.. the code can be as well buggy, but his notes might explain what he wanted to achieve.. I hope you get my point.

I also dislik statements of the form: who cares about 1 byte?!?
well, I do not let the *popularity* or *majority* blind me from the *small* things (in this example, popularity=4GB for example, small=1 byte). I always care about the CPU/chips/designs as I am not selfish (just a metaphor) and I am not lazy.. but, I do keep 2 goals in MIND:

For code, I try to design THE BEST POSSIBLE code, and approach it to computer-logic, not human-logic!! because CODE is executed and READ by the CPU, which uses computer-logic!!
For comments, it's exactly the opposite.. I design them to be easy to understand by HUMANS, so they are near human-logic.

so, the goals are: speed/size for code, easy to understand for comments/notes. Smile (and I love to write notes/comments for readability)


Reverend wrote:
But recently I am changing more and more to write readable code rather than perfect one (which is probably unachievable)

I may not code the perfect code (it's unachievable, like you said, because we're all humans, with flaws), but at least I try to approach perfection for code, and know that it's executed (read) by the CPU much more than we read it, though.. we read comments better, after all.
Post 22 Feb 2006, 18:23
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.