Thank you for thrusting upon me such a wealth of information on Win32 Assembler. No way, could I have acheived such greatness with out you!;)

I have a small query:

How do I work out the actual code size of my programs? EXEs are rounded up to 512 bytes; so the EXE size can not help me.

Specifically, what I really want to know is how many bytes I have saved when I optimize a section of code. There must be a really simple way.

I just need to know what it is!
Posted on 2003-03-21 07:11:26 by GreenScreenAlternator
Check the virtual size of code. It not 100% correct solution, but at least microsoft compilers set exact size of code there.
Posted on 2003-03-21 08:07:40 by masquer

.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib


templ db "Size of code section + padding : %d",0

buf db 256 dup (?)
assume fs: nothing

invoke GetModuleHandle,0
cmp word ptr [eax], 'ZM'
jnz ImageHeaderCorrupted
assume eax : ptr IMAGE_DOS_HEADER
add eax, [eax].e_lfanew ; go to the PE header
cmp dword ptr [eax], 'EP'
jnz ImageHeaderCorrupted
add eax, SIZEOF IMAGE_NT_HEADERS ; go to the section header
assume eax : ptr IMAGE_SECTION_HEADER
mov eax, [eax].SizeOfRawData ; 1st section is code

REPT 9000

invoke wsprintf, addr buf, addr templ, eax
invoke MessageBox, 0, addr buf , 0, 0

end start

Note : VirtualSize is not reliable, but when set, it gives you the exact size of the code section (i.e. without padding)
Posted on 2003-03-21 10:59:55 by Axial
Look at the LINK MAP. :grin:
Posted on 2003-03-21 13:19:32 by S/390
To measure specific pieces of code:

; measure code size
MCS_START macro name:REQ
local mcsLabelName
MCS_CUR_NAME textequ <name>
MCS_CUR_START_LABEL textequ <mcsLabelName>

MCS_END macro
local mcsCodeSize
% mcsCodeSize textequ %($ - MCS_CUR_START_LABEL)
% echo MCS_CUR_NAME: mcsCodeSize byte(s)


MCS_START <First test code>
mov eax, edx
xor ecx, ebx
and esi, edi

MCS_START <Second test code>
int 3

Shows this when assembling:

X:\asm\sizemacros>ml /c /coff sizemacros.asm

Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.

Assembling: sizemacros.asm
First test code: 6 byte(s)
Second test code: 1 byte(s)

Posted on 2003-03-21 13:29:34 by Thomas
You could also simply do a disassembly of your code and look at the address of the last byte of code.

Posted on 2003-03-21 20:46:28 by Raymond
Wow, that's tremendous!

Thank you all, for your suggestions.
Posted on 2003-03-22 03:49:13 by GreenScreenAlternator