This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

MDU unit

hello ,
i am having some problems with the multiplication division unit of the xc878 infineon microcontroller.
i am trying to do a shift operation. the number to be shifted is a 32 bit. lets say i want to do this: 0x00FB00FF >> 16. i would require the MD0,MD1,MD2,MD3 registers. now my problem. i can load the MD0 and MD1 registers but i dont know how to load the MD2 and MD3 registers. please kindly help out.
stephen

Parents
  • You would normally do:

    MDU_MD01 = param_5;
    MDU_MD23 = param_5 >> 16;
    

    and often even show the compiler that you know about the difference in size between left-hand and right-hand side of the assign:

    MDU_MD01 = (uint16_t)param_5;
    MDU_MD23 = (uint16_t)(param_5 >> 16);
    

    The compiler should be smart enough to figure out that a shift right with 16 steps for the second assign is the same as picking up the two most significant bytes - so no real shifting performed.

    Personally, I would prefer a function that accesses 32-bit physical registers to use int32_t or uint32_t as argument type instead of using long int or unsigned long - but it isn't too important since the full function is most definitely not portable anyway. Note that uint16_t etc require that you #include <stdint.h>

Reply
  • You would normally do:

    MDU_MD01 = param_5;
    MDU_MD23 = param_5 >> 16;
    

    and often even show the compiler that you know about the difference in size between left-hand and right-hand side of the assign:

    MDU_MD01 = (uint16_t)param_5;
    MDU_MD23 = (uint16_t)(param_5 >> 16);
    

    The compiler should be smart enough to figure out that a shift right with 16 steps for the second assign is the same as picking up the two most significant bytes - so no real shifting performed.

    Personally, I would prefer a function that accesses 32-bit physical registers to use int32_t or uint32_t as argument type instead of using long int or unsigned long - but it isn't too important since the full function is most definitely not portable anyway. Note that uint16_t etc require that you #include <stdint.h>

Children