|
PowerBASIC Forums
![]() PowerBASIC for Windows
![]() XOR every byte in a string using inline ASM? (Page 1)
|
This topic is 2 pages long: 1 2 |
next newest topic | next oldest topic |
| Author | Topic: XOR every byte in a string using inline ASM? |
|
Wayne Diamond Member |
Dim sStr As String Would anyone be kind enough to convert this to inline assembly? I need maximum speed for large files! Im a huge fan of assembly but this is still a bit out of my reach at the moment, still much study to do ![]() ------------------ IP: Logged |
|
Lothar Pink 2 unregistered |
NOT TESTED haven't got PB at work ... ![]()
If it doesn't work, tell me what error occurs. If a GPF occurs, run Best Regards ------------------ IP: Logged |
|
Wayne Diamond Member |
quote: Hmm dont you think its time to find a new line of work then? ![]() Thanks very much Lothar! It looks spot on, I'll give it a go now and report my findings here in about 10-15 minutes ------------------ IP: Logged |
|
Lothar Pink 2 unregistered |
BTW, there's a wonderful ASM documentation at intel.com, I don't know where but I've downloaded it some time ago, and printed it (about 400 pages...) Assembler is very easy because only a few statements are needed for L. ------------------ IP: Logged |
|
Lothar Pink 2 unregistered |
I'm working at a press agenture, it's not really programming / PC related. Lothar ------------------ IP: Logged |
|
Wayne Diamond Member |
Lothar, I just had to add a ":" to the end of BeginXorLoop to make it a label, and then she compiled fine. But it GPF'd at this line: ! mov dl, [eax] Any idea why? Thanks ![]() And yes, I want to learn assembler just for string and number manipulation, it seems to be often a lot easier (and nearly always faster) when done in asm! ------------------ IP: Logged |
|
Lothar Pink 2 unregistered |
Ooops...
I'm sorry ... ------------------ (!!! two lines have been edited, copy the whole source again !!!) [This message has been edited by Lothar Pink 2 (edited March 05, 2002).] IP: Logged |
|
Wayne Diamond Member |
PERFECT! Thankyou so very muchThese sorts of things may seem simple to people like yourself who are already asm-fluent, but as im not fluent, I find these sorts of samples the best to learn from ![]() I'm sure others will get some use out of this! Best, Wayne ------------------ IP: Logged |
|
Lothar Pink 2 unregistered |
Well, all you have to know about asm, are the processor registers, the mov statement, the jmp statement and it's derivations (in combination with "cmp"), and the arithmetic statements (add, mul, dec, inc, ...) I forgot push/pop. It's very easy! Lothar ------------------ [This message has been edited by Lothar Pink 2 (edited March 05, 2002).] IP: Logged |
|
Wayne Diamond Member |
Lothar, its _too_ simple, thats probably where I get confused, thinking that something should be more complex than it really is ![]() Ive just been reading through your code now for the last 10 or so minutes, and I cant see any way that it could be optimised, at least I cant see any code that could be taken out or made faster... would you say this is about as fast as such an XOR loop could get? Thanks i love this sorta stuff!------------------ IP: Logged |
|
Lothar Pink 2 unregistered |
Well, when dealing with large strings, it would be faster to load 32 bit junks into edx, instead of loading 1-byte-junks into dl... However, the string lenght MUST be a multiple of 4 then ...
l. ------------------ CAUTION: small bug corrected ... [This message has been edited by Lothar Pink 2 (edited March 05, 2002).] IP: Logged |
|
Lothar Pink 2 unregistered |
In case you don't know, a register is a "variable" inside the procesor. A register also is a "pointer". To access the value of EAX, just write So, PB ebx = eax would be and PB ebx = @eax would be This always moves 32-bit-chunks into the registers. and in order to move 8 bits (1 byte), write al, bl, cl, dl are 8-byte-registers which are part of eax, ... In order to understand the code, you also need do know what "cmp" is... Lothar [This message has been edited by Lothar Pink 2 (edited March 05, 2002).] IP: Logged |
|
Wayne Diamond Member |
Superb thanks, Im looking through your last two posts now ![]() Incidently, I did a GetTickCount speed test using a 50mb string ("mystr = STRING$(50000000,0)") Using the normal BASIC-code version of the XOR loop that I posted at the very top of this thread, that clocked in at 31625 'ticks'. Your assembly version did it in 485 ![]() ------------------ IP: Logged |
|
Lothar Pink 2 unregistered |
Actually, a LOT of optimization can also be done in PB code, using pointers (they are VERY fast!!!) You might also test the following code:
As well as the following code for 4-byte-XOR...
The disadvantage of your code is that it allocates and frees memory Lothar ------------------ IP: Logged |
|
Steve Hutchesson Member |
Wayne, If I remember correctly I posted this algo a long time ago and its The problem with a single character XOR is that you can break the SPeed should be reasonable allowing that it handles the sequential Regards, hutch@movsd.com PS : I think you can remove the 3 register preservations at the beginning
------------------ IP: Logged |
This topic is 2 pages long: 1 2 All times are EasternTime (US) | next newest topic | next oldest topic |
![]() |
|
Copyright © 1999-2007 PowerBASIC, Inc. All Rights Reserved.