What are the differences between MASM and Visual Studio 6.0 linker ? Thanks !
Posted on 2001-05-10 03:43:00 by karim
karim, Yes, basically alignment, the linker that comes with MASM32 is from the WIN98DDK and it aligns files at 512 byte intervals. Build an identical file using the default linker options in the VC6 version and it will build much larger. You can change this with the VC6 linker by setting the option /align:4096 but from memory, it will produce a warning as it links the file. If you are building modules in MASM for VC6, you should use the VC6 linker for it when you build the VC program. Regards, hutch@pbq.com.au
Posted on 2001-05-10 04:26:00 by hutch--
As far as I remember, you have to use /FILEALIGN:512 for the file alignment. Lower values will only work on some windows versions, so don't go lower. /ALIGN: is for the section memory alignment. This cannot go lower than 4096 for a standard PE file. However, you can make it larger, as long as it's a power of two (which has the effect of also being a multiple of 4096, the page size). Hope this clears up things a bit.
Posted on 2001-05-10 05:37:00 by f0dder
Thanks for your answers. I use the VC IDE to compile and build asm programs. I compile all my files with ml.exe and I build the executable with the VC linker (because I don't know how to use the MASM linker to generate debug info) I had problems with self modifing code (see the thread in the forum), and I thought it could have something to do with the VC linker.
Posted on 2001-05-10 06:12:00 by karim
I have a question in the Align issue. I've never really understood its purpose, only that it has certian abilities to optomize 32 bit code/data sequences? Can anyone out there help me out with when and why to use the Align statement in MASM?? And is this the same action as the above discussions?? NaN
Posted on 2001-05-12 14:42:00 by NaN
Yes it's possible, and it makes coding and debugging faster and easier ! Someone in the message board (sorry I don't remember his name) explains me how. First, create an empty project. Add your asm files in the Source directory and the include files in the Header directory. Right click on the "Source files" and select "Settings". In "General", select "Always use custom build step" In "Custom build", put the following line in the "Command" field : \masm32\bin\ml.exe /coff /nologo /W3 /c /Zf /Zi /Zd /FR"Debug/$(InputName).pcb" /FR"Debug\$(InputName).bsc" /Fo"Debug\$(InputName).obj" $(InputPath) In the "Outputs" field, write : Debug/$(InputName).obj It will compile all the files in the source directory with debug info. Now click "Settings" in the "Project" menu. Select "Custom build" and put the following line in the "Commands" field \masm32\bin\link.exe kernel32.lib user32.lib gdi32.lib /nologo /entry:"start" /subsystem:windows /incremental:no /pdb:"Debug/P4.pdb" /debug /debugtype:both /machine:I386 /nodefaultlib /out:"Debug/P4.exe" /libpath:"./Debug \masm32\lib" If you need other lib, put them after "user32.lib" in the list. Normally you should be able to compile and link your source files. You can even set breakpoints directly in your source file and use the VC debugger. You can also display the MASM keywords in blue. Edit a file with all the MASM keywords you want to highlight, one keyword per line. Save this file as "usertype.dat" in the "Program files\Common\MsDev98\bin\" directory and close the editor. Restart VC. Load the source file in the text editor. Select "Properties" in the "View" menu. Select "C/C++" in the "Language" list. It will highlight the keywords in the source file. You have to repeat the operation for all your files. Good luck!
Posted on 2001-05-12 14:50:00 by karim
Select "New" in the "File" menu, then select "Projects". Click on "Win32 application", choose a name for your project, click ok and select "Empty projects". Post a message if you have a problem
Posted on 2001-05-12 18:18:00 by karim
Sorry I don't know how use VC to compile in 16 bit mode. Try this line in the "Custom build" menu for all your source files : Commands : \masm32\bin\ml.exe /c /Cp /W3 $(InputName).asm Outputs Debug\$(InputName).obj The problem with link16 is that it ask you questions. It's possible to put all the responses in a text files and pass the file to the linker. So write a file with the following lines : In the project settings, select "Custom build" and replace the "Commands" with link16 @ I don't if works but it's less pratical. Sorry I can't be much help here
Posted on 2001-05-13 04:51:00 by karim
i am answering to NaN that asked about ALIGN, align for memory means that in computer memory all the data is aligned in packets. One packet is 4KB or 4096B. This is needed because of memory levels. In PC you have cache level1, level2 then sysmem...and the data from system memory is transfered into cache. It is not transfered like one byte...but in packets, each one 4096. For example you have two .obj each about 1.2KB. If linker do it 'wrong', it will assign each .obj in different packet. If we simplify, you code will be 8KB!...there is a lot of wasted memory eh:),so with all this switches etc you can make all this stuff fit into one packet of 4096. Hope this helps, btw on disk you have some pretty same issue,when you format disk you can set cluster size 512,1024...that means that each file will take at least 512,1024..whatewr you choose B of disk, even if it is just one BYTE in that file. i hope i helped you a bit
Posted on 2001-05-13 09:59:00 by Geecko

 Karim,

 anyway, that's not important. the only problem is the lINKER.
 it doesn't know where to find it. But that IDE still come ha-
 ndy for detecting error in the process of ML (assembling)
 and for the linking, I think I can do it by hand.


 by the way, things work perfectly fine if you set the warning
 level to 2.

 /W3 becomes /W2
 check it out :)

 thanx for helping me out!!
Posted on 2001-05-13 14:27:00 by disease_2000
Geecko, Thank you very much, as soon as you drew the hard-drive analogy it became very clear of its purpose. Thanx again! NaN
Posted on 2001-05-13 21:53:00 by NaN
Geecko is not entirely correct. First of all, "cache line" size can change. It used to be 32bytes, as far as I remember, but processors are free to choose whatever suits them best. The 4096byte section alignment isn't *really* necessary by any means, it's just to make windows' job a bit easier. It all comes down to paging (which happens to be done in 4k blocks on x86). The minimum of 4k section alignment is probably because each section can have different characteristics (write, read, execute), and windows would not be able to combine conflicting section. As for multiple OBJ files, this shouldn't be a problem at all, since multiple sections with same name is merged *without* doing section align. Section align is only used on different-named sections. As for filealignment, dunno why you must have minimum a 512byte alignment. I mean, the PE loader uses the cache system, so in theory it shouldn't have to care. However, if you bypass the cache system in ReadFile or whatever, it seems that you must make transfers of 512-byte multiples, and that might be in some way related to the minimum filealign.
Posted on 2001-05-14 03:11:00 by f0dder
The ALIGN directive in masm is different to the linker align switches. It all comes down to a simple problem. You system memory (RAM) is aligned. If you try to access a DWORD at the location 00403000h in memory, the CPU issues to the memory banks the command to retrive the DWORD at that loction. However if you try to access the location 00403001h, the CPU can only read the bytes on an alignment of 4! Thus, it will have to perfrom to reads, one at 00403000h and one at 00403004h and then extract the DWORD from the two reads. However, this is becoming less and less important, as things such as paging, and caches come into play.
Posted on 2001-05-15 04:48:00 by George
George, you're *almost* right. The part where you are wrong is
However, this is becoming less and less important, as things such as paging, and caches come into play.
Paging is always done on 4k boundary, thus a page will always be 4k aligned, and shouldn't hurt any ALIGN you're using in masm. So you should still align your data structures and critical loops, as it will help speed. I'm not a guru on this subject, but from the various intel docs and optimization manuals out there, aligned access should always be faster, cached or not.
Posted on 2001-05-15 07:01:00 by f0dder