Author |
Message |
Cerium Server Help Squatter

Age:42 Gender: Joined: Mar 05 2005 Posts: 807 Location: I will stab you. Offline
|
Posted: Tue Nov 28, 2006 10:03 pm Post maybe stupid Post subject: Attn: Assembly Nerds |
 |
|
|
|
I'm having a bit of trouble dereferencing a pointer in (x86) asm. The block of code Im working with is:
invoke ReadConsoleInput, hConsoleHandle, dwEventAddr, 1, addr dwEventsRead
mov ax, (INPUT_RECORD PTR [dwEventAddr]).EventType
cmp (INPUT_RECORD PTR [dwEventAddr]).EventType, KEY_EVENT
(Note: The mov instruction is strictly for debugging purposes so I can see what the cmp instruction is doing. It will eventually be removed).
Here's the problem:
After the call to ReadConsoleInput, dwEventAddr contains the address of a INPUT_RECORD struct. I can view the info in the struct by putting "(INPUT_RECORD*) dwEventAddr" into VS' watch window and it appears to be correct. However, the mov instruction does not get the value of the EventType field, but rather moves the lower 16 bits of dwEventAddr into ax. (IE: After the mov instruction, dwEventAddr contains 0x001529c8, and AX contains 0x29c8).
What I'm trying to do is mov the value of the EventType field into ax, but I can't figure out how to use what I have to reference it. It seems every bit of casting and dereferencing results in the same instruction (mov ax, word ptr [dwEventAddr]). Any and all help would be appreciated.
-C _________________ There are 7 user(s) ignoring me right now. |
|
Back to top |
|
 |
Cerium Server Help Squatter

Age:42 Gender: Joined: Mar 05 2005 Posts: 807 Location: I will stab you. Offline
|
Posted: Wed Nov 29, 2006 12:05 am Post maybe stupid Post subject: |
 |
|
|
|
Ok, you guys are friggen slow...
invoke ReadConsoleInput, hConsoleHandle, dwEventAddr, 1, addr dwEventsRead
mov eax, dwEventAddr
cmp (INPUT_RECORD PTR [eax]).EventType, KEY_EVENT |
Seems adding brackets to a variable does nothing, where on a register they do what I expected them to do (Translation: I'm not entirely sure why this works, so if anyone can provide some insight, please do so). |
|
Back to top |
|
 |
K' You can win any war if you start a year early

Gender: Joined: Jul 13 2006 Posts: 271 Location: Southtown Offline
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Wed Nov 29, 2006 11:00 am Post maybe stupid Post subject: |
 |
|
|
|
I've never been too sure about how much you can do in one instruction with ASM, but your problem is probably just that you have to have the structure ptr in a register before you can do anything to it. Doesn't make much sense to me, but that's why people don't code in ASM anymore...
(Implied question: why are you?) _________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him. |
|
Back to top |
|
 |
Cerium Server Help Squatter

Age:42 Gender: Joined: Mar 05 2005 Posts: 807 Location: I will stab you. Offline
|
Posted: Wed Nov 29, 2006 11:22 am Post maybe stupid Post subject: |
 |
|
|
|
From what I gather, you can only dereference a pointer in a register, not a variable. It doesn't make sense to me either, but that's how it works.
I'm doing this because my asm instructor wont let me turn in my projects in C.
Not that asm is terribly hard (or much extra work, for that matter), there's just a few oddities in the syntax that other languages don't have to deal with. I doubt I'll ever write any large scale programs in asm, but I have no problem writing small utilities/libraries with it. |
|
Back to top |
|
 |
K' You can win any war if you start a year early

Gender: Joined: Jul 13 2006 Posts: 271 Location: Southtown Offline
|
Posted: Wed Nov 29, 2006 5:12 pm Post maybe stupid Post subject: |
 |
|
|
|
Cyan~Fire wrote: | Doesn't make much sense to me, but that's why people don't code in ASM anymore... |
I agree.
Most new coders nowdays are far inferior and lacking in intelligence to be able to manage ASM.
http://www.theprodukkt.com |
|
Back to top |
|
 |
|