Click to See Complete Forum and Search --> : SCASB and SCASW
Mitsukai
May 8th, 2006, 09:05 AM
i am making a string class in C++, and for it to be fast i will need to use SCASB and SCASW asm functions, i wan to make an function in c++ that will ues this ASM language , though im not femiliar with ASM could anyone help me out
nolxev
May 8th, 2006, 09:34 AM
Don't make confusion between strings "this is a string" and ASM strings, ASM ones are strings of bit, those functions manipulate strings of bit, of course you can use those functions to speed up your string class, but if you're not familiar with ASM avoid them or you'll get a headache.
Mitsukai
May 8th, 2006, 12:11 PM
i know that char is a byte, i know that strings are just a block of memory. i am loking for some directions here. if i need to i will get to learn asm.
nolxev
May 8th, 2006, 03:00 PM
There are ASM function to move a byte from one register to another, to move a word from register to memory and so on, they operate only with one element, if you want to perform a copy of 2000 bytes you can use the functions that operate with bit strings, and yes, you have to learn ASM before doing that, those functions are in the middle of a book, of course you can understand how they works, but it's better start from beginning, trust me, especially if it deals with ASM.
Mitsukai
May 9th, 2006, 08:40 AM
i dont need copy functions i todl you im using C++ and i only need a scan function that is coded in ASM
nolxev
May 9th, 2006, 04:51 PM
All you have to do is googling until to find some code fragments.
Mitsukai
May 10th, 2006, 02:45 AM
http://www.int80h.org/strlen/
global strlen
; int strlen(const char *string);
strlen:
push edi
sub ecx, ecx
mov edi, [esp+8]
not ecx
sub al, al
cld
repne scasb
not ecx
pop edi
lea eax, [ecx-1]
ret
what line determines te null char? ithink it is sub al, al?
and how to implent it in a function
Mitsukai
May 10th, 2006, 03:09 AM
By the way, 80386 processors or better include one more variant by augmenting the letter 'd'. So, we'll have movsd, and so on. The operation is done per 4-bytes at a time. Therefore, it's twice speedier than the w-variant and four times faster than the b-variant. Wonderful, isn't it? If the d-variant instructions ever need the accumulator, it means EAX, the extended version of AX. I'll explain more of this in the second lesson.
i aslo read about this
nolxev
May 10th, 2006, 10:00 AM
I can't write ASM tutorial here, sorry.
Mitsukai
May 10th, 2006, 01:12 PM
http://www.int80h.org/strlen/
global strlen
; int strlen(const char *string);
strlen:
push edi // ??
sub ecx, ecx /// set ecx 0
mov edi, [esp+8] // ??
not ecx // set ecx -1 or max
sub al, al /// set ecx 0 (to scan)
cld // ??
repne scasb // scan string bye
not ecx // set ecx -1 or max
pop edi // ??
lea eax, [ecx-1] // ??
ret // return ECX
what line determines te null char? ithink it is sub al, al?
and how to implent it in a function
could you please tell me how to wrap this up in a fucntion and how i can get an extra parameter to al?
mamut
May 15th, 2006, 10:47 PM
Here my inline code FYR. There will be a compile warning, just ignore it.
static __inline // ----------------------------
int szlen(char *string)
{
__asm cld;
__asm mov ecx, -1;
__asm mov edi, string;
__asm xor al, al;
__asm repnz scasb;
__asm mov eax, -2;
__asm sub eax, ecx;
}
Psionic1988
May 21st, 2006, 09:50 PM
global strlen
; int strlen(const char *string);
strlen:
push edi // ??
sub ecx, ecx /// set ecx 0
mov edi, [esp+8] // ??
not ecx // set ecx -1 or max
sub al, al /// set ecx 0 (to scan)
cld // ??
repne scasb // scan string bye
not ecx // set ecx -1 or max
pop edi // ??
lea eax, [ecx-1] // ??
ret // return ECX
It seems like you got this off google or something and you don't understand how it works? The parts you don't understand :
Push edi saves the original value of edi on the stack because you will be using edi to hold the address of the string. Using edi to hold the address is a requirement when using scasb, scasw, scasd etc Pop edi later retrieves the original value from the stack back into edi.
mov edi, [esp+8]
; This is where you should put the offset of the string into edi. The pointer in [esp+8] is dereferenced (if esp at this point is 12FFC0 for instance, esp+8 will be 12FFC8 which points to the address of the string) and the address of the string is stored in edi. Imo, it is not necessary to address the stack directly for something like this.
cld clears the direction flag. Used in conjunction with string primitive instructions to move the direction of string scanning forward.
Personally, i really don't think using inline asm and string primitive instructions over the standard C++ library is a good idea !
mikoil
May 23rd, 2006, 09:36 PM
Well, I didn't read the whole chat but if it's not been mentioned before I'll say that SCASB for string comparison or length check is slow compared to the functions there are today (see MASM32's homepage download and watch examples).. It seems that this function is pretty old.
Mitsukai
May 24th, 2006, 12:37 PM
Well, I didn't read the whole chat but if it's not been mentioned before I'll say that SCASB for string comparison or length check is slow compared to the functions there are today (see MASM32's homepage download and watch examples).. It seems that this function is pretty old.
those might be OS dependent functions? cus if they are old and theres a better scan function scasb wud be replaced.
nolxev
May 24th, 2006, 06:35 PM
Well, I didn't read the whole chat but if it's not been mentioned before I'll say that SCASB for string comparison or length check is slow compared to the functions there are today (see MASM32's homepage download and watch examples).. It seems that this function is pretty old.
That's true, there are onther functions, SCASB is old but it's still used for compatibility reason.
nolxev
May 24th, 2006, 06:39 PM
those might be OS dependent functions?
They could be CPU dependent not OS dependent, I remember I read that AMD REP SCASB is faster than Intel one.
Psionic1988
May 25th, 2006, 10:54 AM
Yup. SCASB/SCASW etc are definitely CPU dependant not OS dependant. Those are string primitive instructions built in the intel instruction set.
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.