Uploaded image for project: 'Embedded Software & Tools'
  1. Embedded Software & Tools
  2. EXT_EP-10403

Does not truncate 32-bit variables when used in 16-bit computation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Not Prioritized Not Prioritized

      The attached test case has these two source lines ...

          iTempLAAx = (int)((int)CurU - (int)32612);
          ...
          iTempLAAx = (int)((int)CurW - (int)32612);
      

      Build it ...

      % cl2000 -@options.txt file.c
      

      Inspect the assembly code associated with these statements. Here is the code for the first statement ...

      ;----------------------------------------------------------------------
      ; 21044 | iTempLAAx = (int)((int)CurU - (int)32612);
      ;----------------------------------------------------------------------
              MOVL      ACC,@_CurU            ; [CPU_ALU] |21044| 
              SETC      SXM                   ; [CPU_ALU] 
              SUB       AL,#32612             ; [CPU_ALU] |21044| 
              MOV       ACC,AL                ; [CPU_ALU] |21044| 
              MOVL      *-SP[2],ACC           ; [CPU_ALU] |21044| 
      

      CurU is a 32-bit global variable. All of it is loaded into the accumulator. But because of the (int) cast, only the lower part should be loaded.

            syncuser TI User
            syncuser TI User
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: