The exception says it all - you're using privileged instructions (outp/inp) which the OS catches, says "Oi, user mode program, you're not doing stuff with the hardware, die, die, die."
If you want to do something with a printer, you've got three choices:-
- use WIN32 to do the printing the same way you'd display stuff on a window
- If you want direct hardware access then either...
- write a device driver with an API on it to do what you want
- write a device driver (or use someone else's) that gives you an API to read and write ports
- write a device driver (or use someone else's) to handle the exceptions, trap to kernel mode and re-execute the instructions
- perhaps get really clever and write a device driver to allow you to switch your code to running in kernel mode (on an x86 by jumping through a call or interrupt gate).
Out of all that lot the easiest by far is to use WIN32. Out of the others the best one is to grab, off the net, a DLL/device driver combo that gives you a general purpose API to read and write ports. I've used
this[
^] in the past and it seemed to work alright.