News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

masm struct beginner

Started by Mantis, January 06, 2008, 08:34:17 PM

Previous topic - Next topic

Mantis

Quote from: Tedd on January 10, 2008, 12:55:25 PM
The registers ecx and edx will be modified by (almost) any api function you call, so if you want to use their value again after the function call, you must save it. Registers ebx, edi and esi will (usually) be preserved by functions you call, so there's no need to save their values - however, the same expectation is on you and you must save their previous values if you use them, and restore them before returning from your procedure.

I think you've got that anyway, just clearing up :wink

A better way to save the values, instead of creating a new variable just for that purpose, is to use the stack - push/pop:

    push edx        ;save the value of edx
    ...do stuff.. call functions...
    pop edx        ;get back the value of edx (into edx)



aha, great thanks everyone for help.

i have came to another problem whilst working on my dll, it is more todo with string comparison, now i have been told by a friend using repne scan is quicker, but for now the way i am doing i cant get to work lol, it is using a pointer from the struct to a passed pointer

i have not changed to push n pop for register, still local for now, as i had original wrote this proc, i know i have made not focused on speed atm, but to just get it working.



CheckBan proc pNick: DWord
LOCAL pEdx: DWord

mov edx, pFirstRecord ; set edx as our first record :)
assume edx:ptr TNickban ; assume it is a nickban

.while edx
mov pEdx , edx ; store edx in pedx for now :)

lea esi, [edx].nickname ;load nickname address into esi
mov edi, pNick ; pnick in edi
mov ecx, sizeof pNick ;length of pNick :)
repe cmpsb
jnz @exit

mov edx, pEdx
mov edx, [edx].next
.endw
mov eax, 0
jmp @quit
@exit:
mov eax, 1
@quit:
assume edx:nothing
ret
CheckBan endp


Tedd

Quote
i have been told by a friend using repne scan is quicker
It varies depending on the length of the string you're comparing, and the machine you're running on - and the difference isn't really something you need to worry about.


.while edx
    mov pEdx , edx ; store edx in pedx for now :)

    lea esi, [edx].nickname ;load nickname address into esi
    mov edi, pNick ; pnick in edi
    mov ecx, sizeof pNick ;length of pNick :)
    repe cmpsb
    jnz @exit

    mov edx, pEdx
    mov edx, [edx].next
.endw

Let's see..
* you're not calling any functions in there, so there's no need for saving edx :wink
* "lea esi,[edx].nickname" will give you a pointer to the start of the nickname - good
* "mov edi,pNick" assuming pNick is correct - fine
* "mov ecx,sizeof pNick" ...aaahhh. Not good. 'sizeof' returns the size of the given type - the type of pNick is dword - so you'll get 4 every time, no matter what string it happens to point to. To get the length of a string you need to count its characters (at run time; unless it happens to be a constant string literal, but this isn't.)
* "repe cmpsb" - yeah, but ecx is wrong, so you only ever compare up to the first 4 characters..

Since ecx is the maximum number of characters before rep gives up, you can just set it to "sizeof TNickban.nickname", so then it will compare up to the end of the nickname, but it would only get that far in the event that all characters match and nickname is maximum length. Otherwise, after rep stops, the value of ecx isn't much help, and neither is the status of the zero flag (since it will always be false - the reason 'rep' finished). So then you'll need to check whether the last bytes compared were zeroes (assuming you have zero-terminated strings), and if they were the strings match, otherwise they don't.
I would reconsider doing the comparison 'manually' byte-by-byte :wink
No snowflake in an avalanche feels responsible.

Mantis

thanks again tedd for reply, you are very helpful... but i do not quite understand how you mean ' doing the comparison 'manually' byte-by-byte '

thanks again :)