![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 297
Rep Power: 4
![]() |
[MASM32] Working with arrays
Hi!
I am working on a system managing key presses in a MASM application. The problem is that I must be doing something wrong with the array that keeps the press status of each key. (bool g_keys[256] // Position 0x20 means VK_SPACE i e.) The "input_set_key" function always returns a non-zero value like my memset hasn't done anything with the array. What can be the problem? I can't see it... Thanks alot for your helpfulness! /Klarre .data g_keys dd 0 ; Pointer to the array of keys .code ; ------------------------------------------------------------------------------ input_create proc invoke crt_malloc, 256 ; Allocate 256 Bytes for the key array mov g_keys, eax ; Store the key array pointer invoke crt_memset, g_keys, 0, 256 ; Make sure no buttons are pressed invoke input_is_key_pressed, 27 ; DEBUG TEST. Returns a non-zero value xor eax, eax ret input_create endp ; ------------------------------------------------------------------------------ input_is_key_pressed proc key:dword lea eax, [g_keys] ; Get the key array address add eax, key ; Offset to the correct position in the array mov eax, [eax] ; Read the value on the position in the array ret input_is_key_pressed endp end
__________________
http://www.klarre.se Last edited by Klarre; Mar 3rd, 2008 at 2:58 PM. |
|
|
|
|
|
#2 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 297
Rep Power: 4
![]() |
Re: [MASM32] Working with arrays
After finding the "Memory" debug window in Visual Studio, it was pretty simply to solve the bug. The functions is now looking like this and seems to work fine.
; ------------------------------------------------------------------------------ input_create proc invoke crt_malloc, 256 ; Allocate 256 Bytes for the key array mov g_keys, eax ; Store the key array pointer invoke crt_memset, g_keys, 0, 256 ; Make sure no buttons are pressed ret input_create endp ; ------------------------------------------------------------------------------ input_is_key_pressed proc key:dword mov eax, g_keys ; Get the key array address add eax, key ; Offset to the correct position in the array mov ah, [eax] ; Read the value on the position in the array .if(ah) mov eax, 1 .else mov eax, 0 .endif ret input_is_key_pressed endp
__________________
http://www.klarre.se |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2008
Posts: 9
Rep Power: 0
![]() |
Re: [MASM32] Working with arrays
IsKeyPressed proc Key:DWORD
mov ecx, [dwKey]
movzx eax, byte [gKeys+ecx]
test eax, eax
sete al
ret
IsKeyPressed endp
InputCreate proc
push 256d
push GPTR ; memory is filled with 0's
call GlobalAlloc
push 27d
push IsKeyPressed
ret
InputCreate endpAlso, a word to the wise. Don't use MSVCRT in ASM, it completely destroys the purpose of using ASM. The converting is fairly easy too: malloc -> GlobalAlloc memset -> stosb/stosw/stosd/stosq |
|
|
|
|
|
#4 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 297
Rep Power: 4
![]() |
Re: [MASM32] Working with arrays
Thanks for your input Irwin. I removed the msvcrt dependency from my project and changed the malloc function call to HeapAlloc since I read on MSDN that GlobalAlloc wasn't recommended.
Another question you may be able to answear on: Is it possible to link a program using the Visual Studio linker without linking with msvcrt.lib? I have set the entry point to main, but still got two linker errors I can't get rid of. So I guess it is impossible, right? Error 1 error LNK2001: unresolved external symbol __RTC_Shutdown main.obj Error 2 error LNK2001: unresolved external symbol __RTC_InitBase main.obj
__________________
http://www.klarre.se |
|
|
|
|
|
#5 | |
|
Newbie
Join Date: Mar 2008
Posts: 9
Rep Power: 0
![]() |
Re: [MASM32] Working with arrays
Quote:
Also, you can completely remove any CRT dependency from an application by adding the /NODEFAULTLIB linker flag, then coupling it with the /entry:main (or whatever your entry function is called). |
|
|
|
|
|
|
#6 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 297
Rep Power: 4
![]() |
Re: [MASM32] Working with arrays
Ah, I see. Going to read up a little bit about the alloc functions.
I am using the /NODEFAULTLIB linker flag and have set the entry point. But this will not get rid of the linker errors...
__________________
http://www.klarre.se |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Mar 2008
Posts: 9
Rep Power: 0
![]() |
Re: [MASM32] Working with arrays
Post your complete source and assembler/link flags and I'll find your problem.
|
|
|
|
|
|
#8 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 297
Rep Power: 4
![]() |
Re: [MASM32] Working with arrays
The source file:
int main() { return 0; }The linker command line (debug configuration): /OUT:"G:\workspace\linktest\linktest\Debug\linktest.exe" /INCREMENTAL /NOLOGO /MANIFEST /MANIFESTFILE:"Debug\linktest.exe.intermediate.manifest" /NODEFAULTLIB /SUBSYSTEM:CONSOLE /ENTRY:"main" /MACHINE:X86 /ERRORREPORT:PROMPT 1>Linking... 1>main.obj : error LNK2001: unresolved external symbol __RTC_Shutdown 1>main.obj : error LNK2001: unresolved external symbol __RTC_InitBase 1>G:\workspace\linktest\linktest\Debug\linktest.exe : fatal error LNK1120: 2 unresolved externals The linker command line (release configuration): /OUT:"G:\workspace\linktest\linktest\Release\linktest.exe" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"Release\linktest.exe.intermediate.manifest" /NODEFAULTLIB /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG /ENTRY:"main" /MACHINE:X86 /ERRORREPORT:PROMPT 1>Linking... 1>main.obj : error LNK2001: unresolved external symbol @__security_check_cookie@4 1>G:\workspace\linktest\linktest\Release\linktest.exe : fatal error LNK1120: 1 unresolved externals
__________________
http://www.klarre.se |
|
|
|
|
|
#9 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 297
Rep Power: 4
![]() |
Re: [MASM32] Working with arrays
Oh, I meant in a C++ project, which I forgot to mention in the earlier posts.
__________________
http://www.klarre.se |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Mar 2008
Posts: 9
Rep Power: 0
![]() |
Re: [MASM32] Working with arrays
Oh, the problems aren't in your linking flags but rather your compiler flags. Just add /GS- to your compiler flags.
Good luck ![]() Also, it's fine; I also code in C(++) ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| joining associative arrays | MiKuS | PHP | 2 | Sep 6th, 2007 2:20 AM |
| Confusion With Pointers and Arrays | JawaKing00 | C | 10 | Sep 14th, 2006 7:33 AM |
| Arrays or Vectors? | can342man | C++ | 2 | Apr 20th, 2006 3:57 PM |
| Arrays in PHP | MrMan9879 | PHP | 6 | Jan 12th, 2006 9:18 PM |
| Arrays | Gunman | C++ | 17 | Oct 20th, 2005 6:11 AM |