March 28, 2024, 12:34:53 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Duplicate Opcode!

Started by Ficko, May 06, 2007, 02:54:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ficko

I think NASM generate a duplicate opcode sometimes into the source.

You can see the sample below that an  extra â€Ã...“89C2â€Ã, -MOV EDX,EAX get inserted after the _ibstrlen function.

A = "HELLO"
B = LEN(A)

00405060   . B8 0D704000    MOV EAX,Pilot.STR00001                   ;  ASCII "HELLO"
00405065   . 89C2                MOV EDX,EAX
00405067   . B8 10004100     MOV EAX,Pilot.A
0040506C   . 89C6                 MOV ESI,EAX
0040506E   . 52                    PUSH EDX                                      ; /Arg2 => 0040700D ASCII "HELLO"
0040506F   . 56                    PUSH ESI                                       ; |Arg1 => 00410010
00405070   . E8 CB070000    CALL Pilot._ibstrcpy                          ; \_ibstrcpy
00405075   . B8 10004100    MOV EAX,Pilot.A
0040507A   . 89C2               MOV EDX,EAX
0040507C   . 52                   PUSH EDX                                      ; /Arg1 => 00410010
0040507D   . E8 21080000    CALL Pilot._ibstrlen                          ; \_ibstrlen
00405082   . 89C2               MOV EDX,EAX
00405084   . 89D0               MOV EAX,EDX
00405086   . 89C2               MOV EDX,EAX
00405088   . B8 0F014100    MOV EAX,Pilot.B
0040508D   . 89C6               MOV ESI,EAX
0040508F   . 8916               MOV DWORD PTR DS:[ESI],EDX
00405091   .^E9 9AFFFFFF    JMP Pilot._ib_finish

Just an observation...

Ionic Wind Support Team

Look closely, it's not a duplicate.  Not necessary, but not a duplicate.

And it has nothing to do with NASM which doesn't generate the assembly, it takes the assembly and makes it into machine code.

What you are seeing is the result of a compiler that doesn't do a third pass optimization.  Compilers are by no means efficient when it comes to spitting out assembly code.  The compiler keeps track of register states and sometimes ends up moving around values just to keep everything from colliding, even if it means the redundant instuction here and there.

In this case you are seeing an inefficiency in the assignment operator because it has to handle more than just a simple assignment.  If you used the assignment operator to initiallize an array it would make more sense...

a[0] = 1,2,3,4,5,6,7

Which is where you come in as a programmer.  If you are looking for more speed out of a routine then let the compiler generate the initial code, and then hand modify it to remove redundancies. 

Some of the assembly code the parser generates was a tradeoff between usability, convenience and speed.  Some BASIC compilers out there might generate better assembly for simple operations but try and get them to handle a complex equation like:

a= (len(a) + sqrt(b)) / z + (a+(y * 2))

And they will fail miserably, mainly because the developer never anticipated running out of registers or using the stack properly. 

If you get the source code license you can see how and why I did things like that ;)

Paul.

Ionic Wind Support Team

Ficko

May 07, 2007, 01:21:48 AM #2 Last Edit: May 07, 2007, 09:00:39 AM by Ficko
Ok I didn’t look at the assembly generated by the compiler just disassembled the machine code and assumed it has to do with the assembler.

But you right when I closely look the code it looks very much like â€Ã...“placeholderâ€Ã, for a possible crossing or simile.

I just wondering that something like a â€Ã...“assembler optimizerâ€Ã, exist or not there out on the net?
Even if you have to edit the findings manually.

Optimizing machinecode propable would not help because such things are more like â€Ã...“harmless errorsâ€Ã, than not optimal code choices.

Csaba

P.S.
I do think about buying the EB source if I manage to beef up my budget! :D