flat assembler
Message board for the users of flat assembler.
![]() Goto page Previous 1, 2, 3, 4, 5, 6, 7, 8 Next |
Author |
|
MichaelH 15 Dec 2006, 00:10
WytRaven wrote: Assembly is not meant to be readable If you continue to believe assembler code is not meant to be readable, that's exactly what you'll get! I think assembler can be the most readable language there is. It's never the language's fault for badly written code, it's always the coder's fault! Quote:
I totally support Tom's quest for well written readable assembler code (although I like xor eax,eax) and if you think it's population then I say, Tom, pollute away! |
|||
![]() |
|
smiddy 15 Dec 2006, 02:26
Tom, because it is written doesn't make it right (or wrong). It just means that someone preferred it that way over another way. In any of those books are there explanations as to why they chose one way or another? In Berry Brey's books he uses XOR reg,reg to accomplish an initialization of that register to zero and so does Allen Wyatt. I still contend it is a matter of choice, and if you are whimsical or pragmatic about it it doesn't matter so long as it accomplished the end result, solving the problem.
I think what has happened is there was an unintended result, however they analyzed it further and understood what it was doing and the benifits of using it, smaller code and faster processing (at least in the old days). |
|||
![]() |
|
Borsuc 15 Dec 2006, 20:59
MichaelH: Then HLLs are pointless, right?
ps.apparently I had some problems and haven't been on these forums for quite a while |
|||
![]() |
|
RedGhost 15 Dec 2006, 21:45
Plue wrote:
That is one shitty compiler. NTOSKRNL_VXE wrote:
Intel did do this, it's "mov r, 0" xor is a different instruction all together. xor enumerates and compares each bit of the dst and src operands and sets each corresponding bit in the dst to 0 if they are equal, or 1 if they differ. If you do "xor eax, eax", each bit is obviously the same in both operands as its the same value. xor wasn't designed to clear registers, it just has that functionality, as does "sub r, r" and "and r, 0". I think the old saying is "There is more than one way to skin a cat." I don't know if you are familiar with C, but I wrote a small routine to try and explain this -> Code: void xor( int *dst, int src ) { int i = 0, m = 1; for( ; i <= 31; i++ ) { /* an iteration for each bit */ if( (*dst & m) == (src & m) ) *dst &= ~m; /* clear bit */ else *dst |= m; /* set bit */ m <<= 1; /* next bit mask */ } } //--- ....... int a = 50; int b = 50; xor( &a, b ); /* this is the same as a ^= b; */ printf( "%i", a ); /* zero is printed */ _________________ redghost.ca |
|||
![]() |
|
MichaelH 15 Dec 2006, 23:15
Quote:
Hi The_Grey_Beast, yep, HLLs are totally pointless! HLL languages were created by programmers so they could get imployed and get paid to program ..... pretty clever really ![]() Problem is there are far too many people like WytRaven who don't even want to consider writing well written clear assembler code and not enough people like Tom saying that if only you try, it can be done. |
|||
![]() |
|
DOS386 15 Dec 2006, 23:35
Quote: That is one shitty compiler. Right ![]() Quote: Intel did do this, it's "mov r, 0" Unfortunately, it wastes 4 bytes storing the zero as 32-bit integer, and invites hard-core coders to invent things like "XOR EAX,EAX". Quote: I don't know if you are familiar with C, but I wrote a small routine to OK, understand the C code, also why "XOR EAX,EAX" saves memory and zeroizes EAX. So, are XOR and OR the only 2 instructions frequently used exposing such a syntax ? _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
![]() |
|
vid 16 Dec 2006, 00:03
MichaelH: you are wrong about HLLs.
|
|||
![]() |
|
MichaelH 16 Dec 2006, 01:08
Quote:
Well Vid, you're about 20 years old, so that means I've been programming in various HLL's for your entire life span ![]() ![]() |
|||
![]() |
|
Tomasz Grysztar 16 Dec 2006, 03:14
RedGhost wrote: xor enumerates and compares each bit of the dst and src operands and sets each corresponding bit in the dst to 0 if they are equal, or 1 if they differ. There's also another possible interpretation of xor operation (though the one you give here is exactly the xor definition): it negates the bits in dst specified by the mask is src. That is, the bits that are set in src specify, which bits in dst gets inverted. For this reason xoring with -1 (all bits set) is the same as negation, and xoring with 0 does nothing. This makes xor useful for switching flags, and certainly it's good for beginners to understand this interpretation, too. |
|||
![]() |
|
Kain 16 Dec 2006, 05:57
It didn't take me long to learn most of the logical tricks that assembly programmers use. This is just a part of the assembly language that every asm programmer should know and it will eventually become natural. The only reason I can think of for using mov eax, 0 rather than the shorter form is to preserve flags.
|
|||
![]() |
|
tom tobias 16 Dec 2006, 07:26
Tomasz wrote:
could not disagree more earnestly. Do NOT use Boolean operators to test flags, if you wish to write programs that others can understand. Quote:
How about REDUCING errors? XOR eax, ecx. ooops, meant to write XOR eax, eax. Do you have any idea how MUCH time it takes to debug someone else's CODE, (usually undocumented, like FASM)? Here's a hint: HIRE SOME PROGRAMMERS, pay them some money from your own pocket, and then, a few months later, about half way through the project, when they have all departed your employ, to commence work at M$, for more money, hire some more programmers, and give them the previous group's efforts. THEN, COUNT how many of the new folks, working with the previous group's CODE, suggest to you, that it would be CHEAPER, i.e. MORE COST EFFECTIVE, if they THREW AWAY the efforts of the first group, because it was essentially an undecipherable tangle of unmarked, unlabeled, illogical wires, that would require more time and effort to figure out, than rewriting the whole mess themselves. I will bet you one bottle of Pilsner Urquel, that AT LEAST 90% of the second group will make that statement, to you, within one week of receiving the CODE from the first group. My comments focus on XOR, only because it is the most obvious, most egregious error on this forum, but believe me, the same could be said about MANY other instructions, where PRECIOUS execution time is saved, or EVEN MORE PRECIOUS MEMORY is saved by using "TRICKS", like: Quote:
for what? The REAL time that one wishes to SAVE, is the time (and money!!) required for a team of programmers to work on the same project, successfully. This time, i.e. MONEY, requires TRANSPARENCY, not subtlety; programs, NOT CODE. Trickery may win prizes at the university, but not in industry. Kain wrote:
Yes, doing things improperly can indeed become "natural", history is full of illustrations. Very appropriate comment, "Kain". Tomasz wrote: xoring with 0 does nothing Are you sure? What does it do to the person who must try to figure out this "clever" rationale? Of course, perhaps that person is insignificant.... |
|||
![]() |
|
Tomasz Grysztar 16 Dec 2006, 08:19
Tom: I was not talking about programming here, I was talking about knowledge. Understanding different aspects of some mathematical operations may be useful even as a simple mental excercise, not speaking about better insight into many problems.
Sorry for off-topic, but also understanding this interpretation of xor makes it easier to understand why it is so useful for symmetric encryptions (no, I'm still not speaking about programming), as xor-ing twice with the same mask will just negate twice all the bits specified by thisk mask, and because negation is an involution, we get the original value intact... And if we xor with any set of values, in any order, but with each one exactly twice, each bit gets switched an even amount of times, what means it stays unchanged, so we've got again the original value. This means you can apply many xor encryptions and decryptions in any order and it's still going to work. |
|||
![]() |
|
RedGhost 16 Dec 2006, 17:13
Tomasz Grysztar wrote:
I think you should be writing some in-depth assembly tutorials. The number one question I get asked by new programmers is for me to point them towards a good set of tutorials, and besides iczelion's there isn't much and I usually say buck up for the Art of Assembly Language or download the Intel/AMD manuals -- and I think this sometimes discourages the new-to-asm programmer. _________________ redghost.ca |
|||
![]() |
|
Tomasz Grysztar 16 Dec 2006, 17:29
RedGhost: have seen my already started tutorial in the Documentation section? It was forgotten for a long time, however I plan to get back to it after I finish "Understanding fasm".
|
|||
![]() |
|
El Tangas 16 Dec 2006, 18:56
Mmm, another xor reg, reg thread... Can't resist posting.
Tom, do you also object to sub reg, reg? That's more obvious than xor, since we learn subtraction in elementary school, maybe even before school, or is it too obscure that subtracting something from itself results in nothing remaining? lea eax, [0] ;just because I can |
|||
![]() |
|
RedGhost 16 Dec 2006, 22:32
El Tangas wrote:
![]() Tomasz Grysztar wrote: RedGhost: have seen my already started tutorial in the Documentation section? It was forgotten for a long time, however I plan to get back to it after I finish "Understanding fasm". I had forgotten this, but it needs a bit more work, I took a look at the other articles, seem to have grown a bit. .... Before I even learned what xor did I was able to recognize "xor r, r" had the effect of clearing the register from reading forums/sources, can't see why anyone would object to it. _________________ redghost.ca |
|||
![]() |
|
WytRaven 17 Dec 2006, 00:48
Quote: Problem is there are far too many people like WytRaven who don't even want to consider writing well written clear assembler code and not enough people like Tom saying that if only you try, it can be done. I write clear comments and maintain high performance assembly. Quote: if you wish to write programs that others can understand. I don't wish to write assembly others can understand. I wish to write high performance assembly with comments that others can understand. @MichaelH: Yay tom's found a gimp! ![]() _________________ All your opcodes are belong to us |
|||
![]() |
|
tom tobias 17 Dec 2006, 09:58
El Tangas wrote:
E.W.Dijkstra CACM 18 (1975) pgs 453-7, and "A Discipline of Programming" from Prentice Hall, published the following year, 1976. WytRaven wrote: Yay tom's found a gimp! http://www.yiddishdictionaryonline.com/ "vay" apparently means "Gosh", or "OOPS", or "WOW" http://dictionary.reference.com/browse/gimp while, "gimp" apparently refers, in a derogatory sense, to someone with a disability, or infirmity. I suppose the intention here is to signal to FASM forumers disdain for another forum member, (because the person is "lame", and therefore deserves neither sympathy nor attention), simply because that member expressed a view contrary to the view of the majority....I believe that such ad hominem attacks are unproductive, particularly, in the MAIN section of the forum: http://dictionary.reference.com/browse/ad%20hominem%20 but, whether the comment is regarded by others as productive and/or dignified, or simply a distraction, as I suspect is the case, it appears irrelevant to the central question of this thread. RedGhost wrote: can't see why anyone would object to it. Well, I don't wish to annoy vid, so I will refrain from posting a recursive link to this thread in response. Perhaps I am writing too tersely again? RedGhost wrote: I think you should be writing some in-depth assembly tutorials. RedGhost wrote: but it needs a bit more work, The question then is this, Would a "tutorial" (whether in depth, or superficial, and whether authored by Tomasz, or someone (i.e. anyone!) else of lesser talent) yield a satisfactory answer to the original question posed by the author of this thread, i.e. why is it desirable to employ a Boolean (or arithmetic) operator to clear or test a register, rather than the intuitive instructions, MOV reg, zero; CMP reg, zero? My hypothesis, based upon what I have read, is that such a tutorial, if illustrated with these kind of comments could be ill suited for beginners: Tomasz wrote: Understanding different aspects of some mathematical operations may be useful even as a simple mental excercise, not speaking about better insight into many problems. ![]() |
|||
![]() |
|
gunblade 17 Dec 2006, 11:15
tom tobias wrote: The question then is this, Would a "tutorial" (whether in depth, or superficial, and whether authored by Tomasz, or someone (i.e. anyone!) else of lesser talent) yield a satisfactory answer to the original question posed by the author of this thread, i.e. why is it desirable to employ a Boolean (or arithmetic) operator to clear or test a register, rather than the intuitive instructions, MOV reg, zero; CMP reg, zero? My hypothesis, based upon what I have read, is that such a tutorial, if illustrated with these kind of comments could be ill suited for beginners. So you're fine with educational books, which are meant to teach assembly, to teach your view on the subject, Code: mov eax, 0 Code: xor eax eax Anyway, any good tutorial should (and do) first introduce the mov method for clearing a register, and then later on in the book (usually in the Optimizations section), it will introduce the xor method, as it is, clearly, an optimization on speed, whether you like it's "unclear" syntax or not. As for the subject of why fasm programmers write in cryptic code, for me, it's not meaningful. I write code which i believe is the most optimized, if that gives a cryptic output, then so be it. I'll add comments to the cryptic section to describe the purpose of the code section, or put some high level equivalent. But I don't expect my code to be read by anyone else, seeing as I usually code assembly for fun. Sadly my university course is teaching me C, java, and with a tiny bit of assembly, but less than even the simplest assembly tutorial. I code assembly on the side, because I enjoy it's power, and simplicity. Maybe some day I'll write code for a company, and that day, I'll have to adhere to coding standards, and if they want mov instead of xor, then they'll get it, because they are paying me, and if I don't stick to the rules, I'll get fired. But at the moment, I'm coding for myself, because I enjoy it, and I want to make the most optimized code I can, just because I can. I doubt this discussion will lead anywhere, because both sides (including me) are too stubborn to change their view on the subject (and I say rightly so ![]() Toodles ![]() |
|||
![]() |
|
Goto page Previous 1, 2, 3, 4, 5, 6, 7, 8 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.