flat assembler
Message board for the users of flat assembler.
Index
> Projects and Ideas > IDEA : FIX 3 files to only one... |
Author |
|
vid 23 Nov 2006, 23:04
can't help myself, but i believe this program could be written much more efficiently. Could you please explain closer what it does?
|
|||
23 Nov 2006, 23:04 |
|
revolution 23 Nov 2006, 23:16
Looks like a vaiant of a simple majority rules selection using byte by byte comparison. Although I can't understand why the files would be currupted in such a way unless he/she has unreliable RAM or HDD.
|
|||
23 Nov 2006, 23:16 |
|
Remy Vincent 23 Nov 2006, 23:18
Some weeks ago, I tried to download some BORLAND programs: from their "external but borland" web site .turboexplorer. : english version of Turbo delphi was unpacking, but not french version of TURBODELPHI,... so I tried to download 3 times, and as I am unlucky, the 3 files were unable to unpack... That's why I tried to do the previous very hard algorithm, to be able to join, and fix, 3 corrupted files... but may be too much reading is less clear than a "graphical" explanation:
- DOWLOADED FILE 1 (unable to unpack) - DOWLOADED FILE 2 (unable to unpack too) - DOWLOADED FILE 3 (unable to unpack also) CMP3FILE.exe "Fil_1.exe" "Fil_2.exe" "Fil_3.exe" TRYTOFIXIT.exe This is what I call "IDEA : FIX 3 files to only one..." Is it possible in FASM?? or are we REACHING THE "ROOF" of what could be done with assembler??? That is a question: does assembler programming aloud very complex algorithms... Yeah, what could absolutly be impossible to program only with assembler, without any call to any external DLL done in another High Level Language??? |
|||
23 Nov 2006, 23:18 |
|
LocoDelAssembly 24 Nov 2006, 00:20
Using arrays instead of "VarNameX" where X is in 1..3 can help a lot. For the part that choose the minimun can be done by first sorting the array and then picking the appropiate cell. Rewrite it using arrays, it will make the job of porting it to fasm easier IMHO
|
|||
24 Nov 2006, 00:20 |
|
Remy Vincent 24 Nov 2006, 00:56
LocoDelAssembly wrote: Using arrays instead of "VarNameX" where X is in 1..3 can help a lot. For the part that choose the minimun can be done by first sorting the array and then picking the appropiate cell. Rewrite it using arrays, it will make the job of porting it to fasm easier IMHO ? With a vararray, do you think it would be possible to process more than 8 or 9 files with less program lines than the program lines needed to process 3 files ? |
|||
24 Nov 2006, 00:56 |
|
vid 24 Nov 2006, 01:09
now i understand. here is the idea for "find min length" and "common parts". Which is MUCH nicer in assembly (gotos) than in HLL
Code: ;load values to registers mov ebx, [G_ByteRead1] mov ecx, [G_ByteRead2] mov edx, [G_ByteRead3] ;find min count mov eax, ebx cmp eax, ecx cmova eax, ecx cmp eax, edx cmova eax, edx mov [G_jMinCount], eax ;determine next step ;check case 1=2 cmp ebx, ecx jne @f mov eax, 0 cmp ebx, edx je .next_step_done mov eax, -3 cmp edx, ebx jl .next_step_done mov eax, 3 jmp .next_step_done ;check case 1=3 @@: cmp ebx, edx jne @f mov eax,-2 cmp ecx, ebx jl .next_step_done mov eax, 2 jmp .next_step_done ;check case 2=3 @@: cmp ecx, edx jne .next_step_done ;in this case you don't set those variables at all mov eax, -1 cmp ebx, ecx je .next_step_done mov eax, 1 .next_step_done: mov [G_jNextStep], eax you see, no problem Last edited by vid on 24 Nov 2006, 02:38; edited 2 times in total |
|||
24 Nov 2006, 01:09 |
|
vid 24 Nov 2006, 01:12
in fact, whenever you see something like this:
Code: end; end; end; end; end; then you can be sure it can be writen nice in ASM |
|||
24 Nov 2006, 01:12 |
|
LocoDelAssembly 24 Nov 2006, 01:50
Your algorithm is too big to fit in my brain so forgive me if the following pseudo-code is not what you spected :
Code: first we read all file into their respective buffers at the array We find the which is the most amount of bytes read this way: max_size := -1; FOR i:= 1 TO N DO IF files[i].G_ByteRead > max then max := files[i].G_ByteRead; { This part is incredible easy with ASM if you have a PPro class CPU (look at vid's code above) } Now that we know which buffers has max_size bytes we compare all of them to see which one has more coincidences: max_occurrencies:= 0; max_buffer := 1; FOR i := 1 to N DO BEGIN IF files[i].files[i].G_ByteRead < max then continue; {skip this step} ocurrencies := 0; FOR j := i+1 to N DO IF files[i].buffer = files[j].buffer THEN inc(ocurrencies); IF ocurrencies > max_occurrencies THEN BEGIN max_buffer := i; max_occurrencies := occurrencies; END; END; At this point we know which data pattern appeared more times (if a tie occured then the tie-break has been made by choosing the first pattern with max_occurrencies occurrencies). |
|||
24 Nov 2006, 01:50 |
|
Tomasz Grysztar 24 Nov 2006, 09:56
Remy Vincent wrote: That is a question: does assembler programming aloud very complex algorithms... Yeah, what could absolutly be impossible to program only with assembler, without any call to any external DLL done in another High Level Language??? Nothing would be impossible. On the other hand, some things are impossible to program only with HLL without call to assembly. And, as vid already noted, the branches allow to write algorithms in more compact and cleaner form that structural code, if only you know how to use them wisely. You also wouldn't be able to convert fasm's source into a structural form without re-arranging many parts - while converting structural code into a branched one is pretty straightforward. (Well, this is all about jumps really, not the assembly itself*. I personally very dislike languages - even though I'm sometimes forced to use them - that don't have GOTO statement... I can manage to handle problems using purely structural code, I just don't get why people hate GOTO so much... perhaps they are scared of too much power it would give to them). --- * Still the assembly has more of the nice "outside-paradigm" tricks. Recently I had trouble converting into HLL code like: Code: cmp [variable],100 ja is_above jb is_below ; here we do something when it's equal You see, it's usually impossible (without writing a macro or something like that) to do such construction in HLL without writing the name of variable twice. |
|||
24 Nov 2006, 09:56 |
|
vid 24 Nov 2006, 13:40
yes the problem with new languages is power. Power can always be misused, and todays trend is to reduce power to disallow coder misuse anything. That's why C programmers say gotos are stupid, and why C# programmers say pointers are stupid. Everything powerful can be misused, but that is not reason not to use it
|
|||
24 Nov 2006, 13:40 |
|
LocoDelAssembly 24 Nov 2006, 14:48
Quote: I just don't get why people hate GOTO so much... perhaps they are scared of too much power it would give to them). Because we learn that shit at university and to be sure that you will not have "strange ideas" of using it them disapprove you at the exams and even force you to take the course again the next year if you persist with your "revolutionary ideas". And all this shit is because they promise you that with structured code you will produce bug free code just because the blocks has one entry point and one exit point and apparently this will avoid returning wrong values at the end of the module (which has to have only one return point too...). Note that if you produce a 100 lines code using goto over the same code using structured code but with 1000 lines they still thinking that structured code is better University concepts sucks You learn great things at there but unfortunately they cut your creativity by things like this and some courses goes beyond and disapprove you if you write an algorithm in a way not seen at the course and no matter if your algorithm is better and uses HLL constructs seen at the course :S |
|||
24 Nov 2006, 14:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.