Assembling Old-School Skills

I’ve programmed in IBM 360 and VAX Assembly before but I have been working in a Microsoft Windows environment on an Intel x86/x64 hardware platform for quite a while.  That little reminder in the back of my head has kept popping up saying it was time to learn Intel Assembler but the auto-click to “close the annoying popups” has until recently triumphed.  I finally decided to go for it.  Since I want to target Microsoft Windows on an Intel platform I figured I’d go for the MASM Assembler.

I learn pretty well through reading books so I opened up Amazon to search around for something that would help.  Much to my chagrin authors either don’t target Windows, don’t target a flat memory model (come on! it’s been a while since we were all working on 8086 processors guys), don’t target MASM or haven’t written a book on Assembly in the current century.

The best resources I’ve found so far are Internet resources.  Following are some good ones I’ve found so far:

You’d think that the MASM development environment would be integrated somehow into the Visual Studio environment but I guess it’s so rare for somebody to write anything in Assembly they don’t feel like putting in the time to develop and maintain that part of Visual Studio.  You can get an add-in for Visual Studio 2010 that does highlighting for Assembler called ‘AsmHighlighter’ but you’ll just be in a text editor not a development environment.

A very old-school (it makes you think of DOS editors) x86 development environment is installed as part of running the ‘Install.exe’ found on the ‘MASM32 SDK’ link above.  Before running the ‘Install.exe’ note all the warnings about AntiVirus scanners.  Norton Anti-Virus no longer complains, not sure about other scanners.

The x64 Assembler ML64.EXE is part of the Windows Driver Kit but note that it’s the Assembler, not a development environment.  I guess that’s why we have the very expensive text editor named ‘Visual Studio’ and the venerable notepad.

So, anyway, once you get into using Macro Assemblers you find that the “Macro” part of the Assembler means that it seems like you’re programming in a combination high-level/low-level programming language.  Some of the very repetitive sequences of instructions like setting up and tearing down call stacks (‘invoke’ keyword) and flow control statements (.IF, .ELSEIF, .WHILE, etc) are provided.  The rest of it though is a good ole Win32 programming (when is the last time you used RegisterClassEx & CreateWindowEx?) and lots and lots of push/pop/mov commands.

My original motivation for learning Intel Assembly was to be better able to diagnose program dumps and I know learning the programming methodology needed to write Windows programs in MASM is a necessary start in that directory but looking at the disassembled program code:

image

is a whole lot different than looking at:

image

So my next thought was that there has to be a good disassembler out there for Intel x86 Assembly.  After searching for a while and finding a number of virus delivery systems masquerading as disassemblers I found a very good tool named IDA at http://www.hex-rays.com/.  There is a freeware version of the tool called ‘IDA Freeware’ at http://www.hex-rays.com/products/ida/support/download_freeware.shtml.  The freeware version has limitations of course so I figured I’ll just go ahead and buy the professional version.  After catching my breath at the price of $1,059.00 I just added that software to my “I hope I have a rich uncle and he buys me this” list.  So for now I’m sticking with the freeware version Open-mouthed smile

Using ‘IDA Freeware’ for the same binary I get:

image

I have a long long way to go on getting comfortable with Intel Assembly but at least I’ve made that first step.

Passing ListView.SelectedItems as a ContextMenu CommandParameter

I spent quite a while trying all of what I thought were the obvious methods of doing this and couldn’t get anything to work.  Then I stumbled on a Blog by Richard Griffin at http://consultingblogs.emc.com/richardgriffin/archive/2007/02/23/WPF-Commands-a-scenic-tour-part-I.aspx that pointed me in the right direction.

	<ContextMenu>
	  <MenuItem Header="Schema"
	    Command="{Binding ExportSchemaCommand}"
	    CommandParameter="{Binding Path=PlacementTarget.SelectedItems, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" />
	</ContextMenu>

Rather than trying to do something obvious like use RelativeSource or ElementName to find the BindingPath use the ContextMenu.PlacementTarget.

ListView.SelectedItems is of type System.Windows.Controls.SelectedItemCollection which is marked as Internal so in your command you have to cast it as its base class which is System.Collections.ObjectModel.ObservableCollection<object>.