I found about LPSTR searching our forum, and it was the recommended one. Would you clarify me on this?
Windows.inc:
LPSTR typedef DWORDIt's exactly the same type. 90% of all code in assembler deals with dwords, the rest being REAL4/8/10, byte and word variables.
Now what is right here? Raise the question and find yourself in an ideological war between the old "hey, it's 4 bytes, isn't it?" fraction and those who come from C/C++ and see their world crumbling if you "mistype" LPSTR as DWORD :P
Btw if there is a real problem, the assembler will shout at you, at least in the 32-bit world. So don't worry.
Re LoadFile: Works like a charm, well done :t
You over-optimise a little bit, though. Once your code is running, it's always nice to see it through the eyes of a debugger...
pLoad proc, string:LPSTR ;=============== Load, Parse file & fill array ========
int 3 ;make Olly stop here when hitting F9
and ebx,0 ;loop
xor ebx, ebx ;shorter way of zeroing a register
m2m esi, InputFile(string) ;Source file (ecx ret. size)
m2m edi, offset Map ;Destination
mov edi, offset Map ;shorter - offsets are big numbers ;-)
@@:
m2m ecx, cWidth ;shorter, cWidth is a small number
mov ecx, cWidth ;lenght of line
rep movsb ;copy
inc edi ;Skips 0s
inc ebx ;loop
cmp ebx, cHeight
jb @B
free esi ;closes it
ret
pLoad endp00401032 ³. CC int3
00401033 ³. 83E3 00 and ebx, 00000000
00401036 ³. 33DB xor ebx, ebx
00401038 ³. 68 14224000 push offset 00402214 ; ÚArg3 = LoadFile.402214
0040103D ³. 68 10224000 push offset 00402210 ; ³Arg2 = LoadFile.402210
00401042 ³. FF75 08 push dword ptr [ebp+8] ; ³Arg1 => [Arg1]
00401045 ³. E8 C6000000 call 00401110 ; ÀLoadFile.00401110
0040104A ³. 8B0D 14224000 mov ecx, [402214]
00401050 ³. A1 10224000 mov eax, [402210]
00401055 ³. 50 push eax ; m2m esi, InputFile(string)
00401056 ³. 5E pop esi
00401057 ³. 68 00204000 push offset 00402000
0040105C ³. 5F pop edi
0040105D ³. BF 00204000 mov edi, offset 00402000
00401062 ³> 6A 0A Úpush 0A
00401064 ³. 59 ³pop ecx
00401065 ³. B9 0A000000 ³mov ecx, 0A
0040106A ³. F3:A4 ³rep movsbNote, for example, that
m2m esi, InputFile(string) results in a
push eax, pop esi sequence;
mov eax, esi has the same size, so no need to optimise here. In fact, the only valid cases for m2m are 1. memory-to-memory transfers between variables (that's why the macro was written) and 2. mov reg32, small integer (-128...+127).
A hard-core optimiser, btw, would save one byte by using
xchg InputFile(string), esi:
00401045 ³. E8 C6000000 call 00401110 ; ÀLoadFile.00401110, read_disk_file
0040104A ³. 8B0D 14224000 mov ecx, [402214]
00401050 ³. A1 10224000 mov eax, [402210]
00401055 ³. 96 xchg eax, esi ; m2m esi, InputFile(string)Don't make this a habit, though: You risk losing a lot of time chasing single bytes instead of concentrating on good code.
For better understand the disassembly, here an excerpt from \masm32\macros\macros.asm:
InputFileA MACRO lpFile
...
invoke read_disk_file,reparg(lpFile),
ADDR ipf@__@mem@__@PtrA,
ADDR ipf@__file__@lenA
mov ecx, ipf@__file__@lenA ;; file length returned in ECX
mov eax, ipf@__@mem@__@PtrA ;; address of memory returned in EAX
EXITM <eax>
ENDM