I am an electrical engineer who has recently discovered the need to modify the code in the MBR. Basically I need the ability to execute code on the HDD before, the OS starts up
There are various ways of writing to the boot sector of a drive, and there is a general reference I used back when I was experimenting with homebrew OS development: http://wiki.osdev.org/
I personally just boot under linux and use dd:
Backup first
dd if=/dev/sda of=~/windows_bootloader.bin bs=512 count=1
Disassemble the bootloader
ndisasm -b16 -o7C00h ~/windows_bootloader.bin > ~/windows_bootloader.asm
Make your modifications and reassemble
nasm ~/windows_bootloader.asm -f bin ~/modified_bootloader.bin
Overwrite the bootloader
dd if=~/modified_bootloader.bin of=/dev/sda bs=512 count=1
This assumes your that 'sda' is the correct block device. And note that the step 4 doesn't just copy the file to /dev/sda (which it could, but then you might overwrite more than just the first sector if the output binary > 512 Bytes )
Obviously you're not going to want to debug this approach on a live system. It will save you a lot of headaches to use some kind of x86 emulator like bochs, qemu or VMWare Server.
However as Michael Burr has stated, this will probably be a bad idea. Modifying the Windows bootloader, will probably leave you with little or no room for your own code.