Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C/C ++ & Assembly mixed programming material

  1. Jul 17, 2011 #1
    Can anyone suggest me good books on 'C/C ++ & assembly mixed programming' for embedded system coding. I am trying to gain expertise in mixed C/C++ & assembly mixed programming for writing embedded system codes. I am fairly new to mixed programming. I know C/C++ and assembly languages. Now, I need to know mixed programming. Can you please suggest me any good books for mixed programing.
    Last edited: Jul 17, 2011
  2. jcsd
  3. Jul 17, 2011 #2


    User Avatar
    Homework Helper

    If you know C++ and assembly, then you're almost there already. I've worked on embedded systems, and normally each source module is all C, C++, or assembly, and not mixed (no _asm() directives used in C code, because it interferes with the optimizer). Generally the amount of assembly code is small, mostly for the operating system used in a device, and perhaps some time critical routines. In the case of a cpu with a lot of registers, like an ARM with 16 registers, it's difficult to improve on the optimization of the code, but you need assembly to deal with context switching and dealing with interrupts (ARM uses secondary shadow registers for fast interrupt, normal interrupt, supervisor mode, ... ), or any math routine that needs to use low level hardware like the carry bit or paired registers.

    The other thing to learn is how parameters are used in calls (registers versus stack), and how names are "mangled" in C or C++ so you can use the proper parameters and names in assembly. This can usually be done by writing a test module in C or C++ and having the compiler produce assembly code, which gives you the parameter setup and names.

    Unless you get involved with the operating system itself, there's not much to learn. Most companies will just buy a basic operating system or hire a consultant if no one in house is famliar with the internals of an operating system.
    Last edited: Jul 17, 2011
  4. Jul 17, 2011 #3


    User Avatar
    Science Advisor

    For the assembler, it's probably a good idea to get the specific architecture manuals for the platform you are using. Get both the manuals that outline the instruction set complete with opcodes and binary representation (just in case you can't get an assembler).

    Also in the architecture manuals it should give details about the flow control of the hardware platform: this is the key thing you need for optimization and critical routines.

    As an example of what I'm talking about, when the pentium chip came out from intel, there was a thing called a U and V pipe. Now the pentium chip had only one core and one main CPU, but if you put certain instructions in a certain order it could process them quicker due to the UV pipe architecture. If you are interested in fast optimized code, its the tricks like this that will give you the speed edge.

    As for C/C++, there are plenty of resources out there and its hard to give recommendations for that.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook