Why Does Hex Change While Code Remains the Same?

Follow+Star Public Account, don’t miss out on exciting content

Why Does Hex Change While Code Remains the Same?

Author | strongerHuang

WeChat Public Account | strongerHuang

Today in the technical exchange group, I saw such a question, which roughly means: the same code project (source code unchanged), but the program (hex) changes due to different Keil versions.

Why Does Hex Change While Code Remains the Same?

For many beginners, it’s definitely puzzling why the result is different when the code hasn’t changed.
The variable here is the Keil version changing from V5.14 to V5.28.
And the optimization options haven’t changed, so what has changed?
Yes, experienced developers will definitely see that it’s the compiler version that has changed.

Different Keil Versions May Have Different Compilers

To verify this issue, I installed the older versions of Keil V5.28 and V5.36, and the default included compilers AC (Arm Compiler), whether AC5 or AC6 versions, are different.

Keil V5.28’s default included compiler is AC5.06-6 and AC6.12:

Why Does Hex Change While Code Remains the Same?

Keil V5.36’s default included compiler is AC5.06-7 and AC6.16:

Why Does Hex Change While Code Remains the Same?

However, the source code of this project hasn’t changed, the optimization options (configuration) haven’t changed, but the compiled Hex files are different:

Why Does Hex Change While Code Remains the Same?

How to Solve This Problem?

1. Use the Same Development Environment

The development environment here mainly refers to the Keil version, for example: if you previously used Keil V5.14, continue using V5.14.

Of course, if conditions allow, it’s best to have the same operating system (Windows), as the operating system may also affect the compilation results.

I shared an article last month: Don’t Upgrade Software Tools Unnecessarily

Why Does Hex Change While Code Remains the Same?

2. Use the Same Compiler

Of course, if you cannot achieve the same software versions and systems as mentioned above (some people just prefer the new versions), you can use the same version compiler to try to maintain consistency.

Whether it’s the Keil Arm Compiler mentioned here or tools like GCC, the principle is the same.

The Keil compiler can be modified, and many may not know this, so let me explain.

Changing the Keil compiler is quite simple; just download the version of the compiler you need from the official Keil (Arm) website and install it yourself.

The method is quite simple, so I won’t elaborate here; you can refer to the article I previously shared: Step-by-Step Guide to Upgrading the Keil MDK ARM Compiler

This article ends here; if you encounter similar strange problems, feel free to leave a comment for discussion.
———— END ————
Why Does Hex Change While Code Remains the Same?
● Column “Embedded Tools”
● Column “Embedded Development”
● Column “Keil Tutorial”
● Selected Tutorials from Embedded Column
Follow the public account reply “Join Group” to join the technical exchange group according to the rules, reply “1024” to see more content.
Why Does Hex Change While Code Remains the Same?
Why Does Hex Change While Code Remains the Same?
Click “Read Original” for more shares.

Leave a Comment