flat assembler
Message board for the users of flat assembler.
Index
> Main > Problem with IF | if vs .if | Dilemma: to IF or NOT to IF Goto page Previous 1, 2 |
Author |
|
fasmnewbie 17 Jul 2013, 09:09
uart777 wrote: fasmnewbie: TQVM for the interesting points on the .if/if and the multi-platform ASM. Quite an eye opener. I_inc and John meant nothing bad though. They were just showing it to me where exactly I did wrong on a very specific problem. You did help too. Thanks. If you look closely at my posts (even my previous posts), my point of angle is mainly pedagogical. I am not an assembly programmer myself. I am currently working for a faculty and I am here for an independent evaluation purposes. The faculty is restructuring the programming courses and one of the main question we need to answer to the higher-up is why brilliant HLL students perform so badly during the assembly courses. You'll be surprised to see some of our preliminary findings - with unstandardized x86's view of memory being one of them - a pedagogical "bug" inherited much earlier from the HLL (C/C++, FORTRAN, JAVA) courses. And that ARM platform you mentioned earlier did catch my attention from "faculty" point of view. Thanks. |
|||
17 Jul 2013, 09:09 |
|
AsmGuru62 17 Jul 2013, 12:44
My main issue with .if is the inability to track the code flow.
The code flow is important for developing the fastest running code. I am talking about the default branch prediction. Predicted conditional branches are faster. .if makes developing code faster, but it may not be the fastest running code. |
|||
17 Jul 2013, 12:44 |
|
baldr 17 Jul 2013, 13:31
AsmGuru62,
Fastest running code (does it exist considering all those differences regarding CPU?) may be developed manually, yet it requires too much efforts (for any non-trivial task). Those macros are kinda shortcuts that are useful to make code more readable, nothing more. |
|||
17 Jul 2013, 13:31 |
|
AsmGuru62 17 Jul 2013, 15:39
I agree. Readable code is very important.
I write good code with good label names and comments. |
|||
17 Jul 2013, 15:39 |
|
uart777 18 Jul 2013, 02:45
fasmnewbie: Thanks for giving me something to talk about. No matter how much we learn, there's always so much that we don't know and we're all newbies at certain things (example: I'm a beginner at MIPS ASM).
Quote: John meant nothing bad though. As for I_inc, never had a problem with him. I have learned quite a bit about FASM's preprocessor from people who come here and post macros/examples. I am thankful for people like this; in a way, they are partially responsible for the programs I create and there is a chain reaction of positive effects when you consider those who may be inspired my creations (?). Quote: My main issue with .if is the inability to track the code flow. The code flow is important for developing the fastest running code. I am talking about the default branch prediction. Predicted conditional branches are faster. What do you think about C/C++ programmers who say "Don't use goto"? Isn't that stupid? goto is a straight-forward, unconditional jmp (ip+n), but in their minds, goto is like cheating or a HL feature, "not real C/C++". New C/C++ programmers are taught to write code that intentionally avoids the use of goto in situations where it seems perfectly logical (example: to exit a loop) and would create fast executable code. Writing the equivalent with ass-backwards "if+for (x;y;z)" loops that are deeply nested will confuse HL compilers and produce suboptimal code. Don't blame goto for "spaghetti code", blame programmers who write sloppy code! baldr wrote: Quote: Anyway, trying to outperform compiler at optimizing using fasm macros is futile attempt, I think. Ultimate language: http://board.flatassembler.net/topic.php?t=15588 |
|||
18 Jul 2013, 02:45 |
|
baldr 18 Jul 2013, 07:52
uart777 wrote: So, don't even try? uart777 wrote: Don't use goto P.S. Guys, use copy/paste for nicknames, l_inc is neither i_inc nor I_inc. |
|||
18 Jul 2013, 07:52 |
|
AsmGuru62 18 Jul 2013, 14:46
There is a very nice goto equivalent in C/C++ and it is called break.
Also, too deep nesting and 1000 line loops in C/C++ is a sign of illogical code design. |
|||
18 Jul 2013, 14:46 |
|
TmX 18 Jul 2013, 20:00
goto is used quite extensively in Linux kernel (e.g for error handling).
as long as you're code is readable, I think it's fine. Linux: using goto in the kernel code |
|||
18 Jul 2013, 20:00 |
|
l_inc 18 Jul 2013, 22:40
uart777
Quote: So, you recommend using a C compiler instead of FASM I never said "instead". I recommend C as an example of higher level language, that would allow to feel both: convenience of high level constructions and connection to the low level mechanisms. Moreover I find discussions like "Why FASM? And NOT C/C++" absolutely pointless. Same as "Why screwdriver and not a hammer?", "Why refrigerator and not a microwave?" and "Why a hanky and not pampers?" baldr Quote: Guys, use copy/paste for nicknames, l_inc is neither i_inc nor I_inc Thank you very much. That's really frustrating, that people don't see the difference when typing the nickname. _________________ Faith is a superposition of knowledge and fallacy |
|||
18 Jul 2013, 22:40 |
|
JohnFound 18 Jul 2013, 22:57
About "goto" - read my signature.
I never liked this analogy of programming languages with general ironware tools. I am working with hammers and screwdrivers as well as with programming languages every day. And can say from personal experience - both have nothing in common. While with screwdriver you can only turn some screws, in assembly you can program everything. Can you see the difference? _________________ Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9 |
|||
18 Jul 2013, 22:57 |
|
uart777 19 Jul 2013, 03:32
baldr:
Quote: my grandfather taught me one precious lesson: "use proper tool for each task" Quote: I'm still waiting for a language that have equivalent of Forth's BEGIN … WHILE … REPEAT loop Guru: Quote: I write good code with good label names Anyone who wants to understand HL syntaxes (.if/.while/.for/etc) and how to convert them? And see 1,000s of good names for identifiers? Check out USE\LANGUAGE.INC in: CodeVu+Z77 (old, 2+ months) |
|||
19 Jul 2013, 03:32 |
|
uart777 19 Jul 2013, 12:30
One more thing: ARM .if/.else may be implemented much differently than X86 because ARM can execute any instruction conditionally. Example:
Code: ; if r0=0, r0=r1+(r2>>16) ; else, r1=r2-(r3>>16) ; ARM: 3 instructions tst r0, r0 addeq r0, r1, r2, lsr 16 subne r1, r2, r3, lsr 16 ; X86 equivelant: 9 instructions, 2 labels ; + possible branch misprediction penalty test eax, eax jnz .a shr edx, 16 add ecx, edx mov eax, ecx jmp .b .a: shr ebx, 16 sub edx, ebx mov ecx, edx .b: * ARM Information Center: http://infocenter.arm.com/help/index.jsp |
|||
19 Jul 2013, 12:30 |
|
fasmnewbie 29 Oct 2013, 16:38
baldr wrote:
De-abstracting HLL concepts back to the LL is a PITA. It is even more painful for the teachers/lecturers to do it in much lesser time since ASM is taught only as part of OS, System Organization or something similar. ASM gets all the resources, time and attentions it deserves only in more advanced compiler classes. For example, students often have difficulties understanding concepts like pointer, memory allocation, linked list, and advanced data structures while on the other hand, they could be easily explained using ASM terminologies and materials (memory, addressing, registers etc). Worse, many of these students taking advance programming courses are not even aware of the specific CPU they are programming. eg, Ask the student what could be the valid address format returned by this C's statement; Code: int myVar; printf ("The address is %p\n", myVar); The best answer they can come up with is "it returns an address". What kind of address, is it 16-bit, 32-bit or 64-bit address? Then you'll get the idea. |
|||
29 Oct 2013, 16:38 |
|
smiddy 19 Nov 2014, 12:18
Sorry to dredge up an old thread...but I think this is a good starting point for something I'm about to do/run-into. I have to do several logical compares, highly complex, sticking to 32-bit registers up front. I'd like to stay within the x86 construct and was wondering if there are examples to use logical comparisons, of multiple branches, in 32-bit on 64-bit numbers (for now unsigned). Has some one done any examples of this here? Running a search yeilded little help, but this thread is a perfect start, at least since I had no idea how to use either if/.if until reading this thread, I'd always only done multiple CMP in (F)ASM.
So, in pseudo code: Code: If EDX:EAX .is_equal. dword [variable_high]:dword[variable_low] .and. ECX:EBX .is_less_than. dword[variable2_high]:dword[variable2_low] do something here to dword[variable_high]:dword[variable_low] ...more multiple comparisons, ad nasium BTW, I am just wanting the ASM examples, and not a if/.if style of writing. |
|||
19 Nov 2014, 12:18 |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.