The MASM Forum

Specialised Projects => Compiler Based Assembler => Assembler With Microsoft Visual C => Topic started by: daydreamer on February 19, 2019, 03:29:02 AM

Title: to get VC++ generate asm?
Post by: daydreamer on February 19, 2019, 03:29:02 AM
trying to use VC++ for lots of source code to get a starting point,preferably with optimization switch off to get more readable code
Title: Re: to get VC++ generate asm?
Post by: TimoVJL on February 19, 2019, 04:02:54 AM
/Fa[file] name assembly listing file    /FA[scu] configure assembly listing
Title: Re: to get VC++ generate asm?
Post by: nidud on February 19, 2019, 05:41:32 AM
deleted
Title: Re: to get VC++ generate asm?
Post by: daydreamer on February 19, 2019, 06:28:45 AM
thanks Timo,nidud I try that
Title: Re: to get VC++ generate asm?
Post by: hutch-- on February 23, 2019, 03:13:21 AM
Magnus,

To use 32 VC/VS code, set it to UNoptimised and you have some chance of making sense of it. The optimised code is very difficult to follow. Start with the un-optimised code and progressively optimise it manually and with practice you should be able to get it faster.
Title: Re: to get VC++ generate asm?
Post by: daydreamer on February 23, 2019, 09:23:56 AM
Quote from: hutch-- on February 23, 2019, 03:13:21 AM
Magnus,

To use 32 VC/VS code, set it to UNoptimised and you have some chance of making sense of it. The optimised code is very difficult to follow. Start with the un-optimised code and progressively optimise it manually and with practice you should be able to get it faster.
Quote from: hutch-- on February 23, 2019, 03:13:21 AM
Magnus,

To use 32 VC/VS code, set it to UNoptimised and you have some chance of making sense of it. The optimised code is very difficult to follow. Start with the un-optimised code and progressively optimise it manually and with practice you should be able to get it faster.
thanks, I found out I need to call all "proc's" with variables in main,otherwise they arent included in source file,any switch I can use for this kinda sizeoptimized code

?calcy@@YAHHH@Z PROC ; calcy, COMDAT
; Line 109
fld QWORD PTR __real@3fe921f9f01b866e
call __CIsin
fmul QWORD PTR __real@406fe00000000000
jmp __ftol2_sse
?calcy@@YAHHH@Z ENDP

no idea what this jmps/calls do,but they have nothing todo with SSE
so I have to decypher _CIsin and all other included libraries
fild DWORD PTR _a$[esp+28]
fmul QWORD PTR ?pi@@3NA ; pi
fadd ST(0), ST(0)
fdiv QWORD PTR __real@4076800000000000
call __CIcos
fmul QWORD PTR __real@c08f400000000000
call __ftol2_sse
mov edi, DWORD PTR _a$[esp+28]
mov ebp, DWORD PTR tv420[esp+28]
xor ebx, ebx
mov DWORD PTR tv215[esp+28], eax
add edi, 720 ; 000002d0H

overuse of esp+somevalue,I am not used to this kind of codestyle,but its probably C++ pointerbased to the variables,also many memtomem moves

also tried the mixed asmcode/sourcecode option,maybe good for reference mixed C++ proc code/asm code easier to read


Title: Re: to get VC++ generate asm?
Post by: aw27 on February 25, 2019, 07:47:16 AM
Quote from: daydreamer on February 23, 2019, 09:23:56 AM
overuse of esp+somevalue,I am not used to this kind of codestyle,but its probably C++ pointerbased to the variables,also many memtomem moves

You need to configure in Properties how you want things. It takes some time to understand Visual Studio C/C++ (which is nothing when compared with the time required to understand other compilers that produce enormous and slow bloatware under windows).
There is an option that says 'Omit Frame Pointers'. When is set to Yes it does not make the usual push ebp, etc frame.
Then you must tell through Enable Instruction Set if you want SSE, AVX or the old 8087 instructions. The default for x86 is 8087.
You can also build in release mode and set some functions for no Optimization using a #pragma optimize( "", on ) and #pragma optimize( "", off ) statement.

Title: Re: to get VC++ generate asm?
Post by: hutch-- on February 25, 2019, 12:51:59 PM
Magnus,

What I have tended to do when I find a C source that did something useful in 32 bit was to build each function alone in un-optimised form with the option to get the asm listing. You have to untangle some of the leading equates but you can generally get them to work then you manually optimise the asm listing while testing it for both speed and accuracy. Most of what you will do is get rid of redundant memory operands and jump reduction but its great practice for manual optimisation and once you get used to it you can generally but not always see a speed improvement.
Title: Re: to get VC++ generate asm?
Post by: daydreamer on February 26, 2019, 05:39:08 AM
Quote from: hutch-- on February 25, 2019, 12:51:59 PM
Magnus,

What I have tended to do when I find a C source that did something useful in 32 bit was to build each function alone in un-optimised form with the option to get the asm listing. You have to untangle some of the leading equates but you can generally get them to work then you manually optimise the asm listing while testing it for both speed and accuracy. Most of what you will do is get rid of redundant memory operands and jump reduction but its great practice for manual optimisation and once you get used to it you can generally but not always see a speed improvement.
thanks,I have lots of HLL code, I want to try to automatize the process with help of a C compiler and some proc are very complex and some are unique, to get a starting point for make it faster
@aw,thanks
Title: Re: to get VC++ generate asm?
Post by: daydreamer on February 27, 2019, 03:47:01 AM
Read some about how compilers work,maybe the code becomes less cryptic if i put all variables static first ,from local variables inside proc ?because i suspect it gets rid of many cryptic esp+number ?
Make variables static and global puts them directly in .data section
???
Title: Re: to get VC++ generate asm?
Post by: daydreamer on February 28, 2019, 06:11:39 AM
just for fun I tested optimized option,it mostly used few more fp registers to more extent than just memory and more general regs and shifts
read randy hydes books,AoA MMX section,write great code books and he brings up BSS section and different sections of memory and how compilers do ,mixed with masm code,something interesting things worth trying
Title: Re: to get VC++ generate asm?
Post by: daydreamer on March 02, 2019, 04:46:33 AM
another exercise using VC++ and masm would be port alternative math functions to C

different VC++ versions produce different final size of code
Title: Re: to get VC++ generate asm?
Post by: daydreamer on March 02, 2019, 10:20:33 PM
Quote from: hutch-- on February 25, 2019, 12:51:59 PM
What I have tended to do when I find a C source that did something useful in 32 bit was to build each function alone in un-optimised form with the option to get the asm listing. You have to untangle some of the leading equates but you can generally get them to work then you manually optimise the asm listing while testing it for both speed and accuracy. Most of what you will do is get rid of redundant memory operands and jump reduction but its great practice for manual optimisation and once you get used to it you can generally but not always see a speed improvement.
how about improve esp pointer to local arrays codestyle compiler produces with save esp at the beginning of proc to a variable and restore at the end of proc?as long as I use mov's instead of push/pop to save registers in that section,so lots of movss xmm0,[esp] instead of movss xmm0,[esp+offset]
nonarray variables moved into static global section
Title: Re: to get VC++ generate asm?
Post by: daydreamer on March 03, 2019, 03:24:32 AM
Progress so far:
Because so many functions are based on trigonometry
Cosine
Sine
Sincos
Calcx proc
Wraps cosine + mul
Calcy proc
Wraps sine+ mul

functions need to be tested and real8 versions need to be made
Title: Re: to get VC++ generate asm?
Post by: hutch-- on March 15, 2019, 12:25:29 AM
Magnus,

The ESP or EBP numbers are just memory operands that are usually LOCAL in scope, with a stack frame it will be EBP, with no stack frame it will be ESP and you will just have to get used to it. I suggested using the UN optimised output options as they can usually be understood and you then have the choice of how to optimise it. It will need things like redundant jump removal and memory operand removal where possible.

Now with a stack frame in 32 bit that has 3 arguments, you start at [ebp+8], next arg is [ebp+12] and the third argument is [ebp+16]. A NO stackframe procedure uses [esp+4], [esp+8] and the third arg is [esp+12] but it starts to get complicated once you use PUSH to preserve registers.

If you have to preserve ESI and EDI, you PUSH them in order then the ESP addresses have to be corrected by 8 (2 pushes). What I tend to do to keep track of the arguments is use a notation like this, [esp+4][8], [esp+8][8] and [esp+12][8].

It looks messy and you have to get it right but it comes with practice.
Title: Re: to get VC++ generate asm?
Post by: fearless on March 15, 2019, 02:34:25 AM
Quote from: daydreamer on February 23, 2019, 09:23:56 AM
no idea what this jmps/calls do,but they have nothing todo with SSE
the __ftol2_sse is a ms visual c library function to convert float to long - the code in __ftol2_sse checks to see if it can use sse to calc that, otherwise it defaults to whatever normal non sse code is in that function.
Title: Re: to get VC++ generate asm?
Post by: TimoVJL on March 15, 2019, 03:13:32 AM
To avoid SSE:
/QIfist[-] use FIST instead of ftol()
/arch:IA32 - use no enhanced instructions and use x87 for floating point
Title: Re: to get VC++ generate asm?
Post by: daydreamer on March 16, 2019, 04:51:21 AM
thanks Steve,Timo,fearless
Title: Re: to get VC++ generate asm?
Post by: daydreamer on May 11, 2019, 01:47:15 AM
this IDE and C++ compiler seem like a way to make a bigger project,mixing masm code and C++ code
enjoy use masm code in a project,while C++ code to make you more productive where speed doesnt matter, to maybe finally put together a big project
but also fun in compare a long switch with a jumptable
Title: Re: to get VC++ generate asm?
Post by: daydreamer on August 07, 2019, 04:49:10 AM
it would be nice to learn howto also make macros inside VC++,because I read "_inline" is just bad suggestion to compiler that its probably not will follow
Title: Re: to get VC++ generate asm?
Post by: TimoVJL on August 07, 2019, 09:17:04 PM
Why ?
msvc x64 don't support inline  assembler.
read about msvc __forceinline, if you just stick with 32-bit.

I don't know how those #defines affect to optimizer.


Title: Re: to get VC++ generate asm?
Post by: daydreamer on August 09, 2019, 02:22:15 AM
Quote from: TimoVJL on August 07, 2019, 09:17:04 PM
Why ?
msvc x64 don't support inline  assembler.
read about msvc __forceinline, if you just stick with 32-bit.

I don't know how those #defines affect to optimizer.
thanks,because if SIMD needs other things than an assembler to keep on using,I have checked alternatives intrinsic looks like it has similarities to assembler but more lot complex and longer than the usual mnemonics to type
Title: Re: to get VC++ generate asm?
Post by: daydreamer on February 10, 2020, 05:56:01 PM
I got a 415kb asm file  :rolleyes:

it feels like I should do a different approach on this
Title: Re: to get VC++ generate asm?
Post by: daydreamer on March 24, 2020, 01:32:01 AM
VC++ wizard generates 46kb small.ico ,+46kb the normal .ico files,now trying to make my own maybe it would be possible to cut down on size,the windows program without the debug usually endup 120kb,console only end up about 22kb,so I suspect about 100kb of it is the resource files???
Title: weird vc++ produced exe!
Post by: daydreamer on May 31, 2020, 06:18:00 AM
I have tested vc++ and also masm produced exe on several different machines
Win10 seem to have standard installed directd and c runtime, but on win8 first works after download and install crt
On WinXP it gives similar message as try run 64bit Exe on 32bit os,something like "this is not a 32bit exe ",strange it's compiled x86
But the good part is I went back to masm32 development and the call macros combined with string macros are great for Windows programming
And works great on ancient xp machine,  2ghz amd
Title: Re: to get VC++ generate asm?
Post by: Vortex on November 11, 2020, 06:56:56 PM
Hello daydreamer,

QuoteOn WinXP it gives similar message as try run 64bit Exe on 32bit os,something like "this is not a 32bit exe ",strange it's compiled x86

I think Windows XP does not like the build numbers ( OSMajor and OSMinor version numbers ) in the Windows PE header. Could you check it?