Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29559 Discussions

mixed language - fortran and assembly

Ken_Woolridge
Beginner
3,446 Views

My laptop is running Windows 10 32-bit and I use the Intel compiler "ifort".  From Fortran I can call assembly routines assembled using Masm32.  My desktop is running Windows 10 64-bit and I use the Intel OneAPI compiler "ifx".  I now assemble the assembler routine with ml64 in the Visual Studio 2022 package.  However, any calls from Fortran to an assembly routine bombs with the following error:

forrtl: severe (157): Program Exception - access violation
Image PC Routine Line Source
FF.EXE 00007FF7C66D8A19 Unknown Unknown Unknown
Exception is raised during stack walking

 

Does anyone know what this error means and how I can fix this program?

0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
3,373 Views

Don't Touch Me There - What error 157 (Access Violation) is trying to tell you - Doctor Fortran

 

The calling mechanisms on x64 are very different from IA-32, with the first few arguments passed in registers. You probably need to rewrite the assembler code to compensate.

View solution in original post

7 Replies
Steve_Lionel
Honored Contributor III
3,374 Views

Don't Touch Me There - What error 157 (Access Violation) is trying to tell you - Doctor Fortran

 

The calling mechanisms on x64 are very different from IA-32, with the first few arguments passed in registers. You probably need to rewrite the assembler code to compensate.

Ken_Woolridge
Beginner
3,063 Views

Where can I get a reference manual for 64-bit assembly language which better explains this manner of calling assembly routines?

What registers is IFX sending the assembly routine?

This document "fortran-compiler_developer-guide-reference_2025.2-767251-855933.pdf" only discusses mixed Fortran and C
programming - not assembly.  Why not assembly???
 
I need to know how IFX is calling the assembly routine in order for the assembly routine to get the correct info.
Is IFX passing addresses in the registers?  or data?
 
What a nightmare!
0 Kudos
Steve_Lionel
Honored Contributor III
2,998 Views

ifx follows the x64 calling convention. x64 Calling Convention | Microsoft Learn

 

The Intel documentation has never discussed calling assembler, as it is, nowadays, an esoteric topic.

0 Kudos
Ken_Woolridge
Beginner
2,671 Views

It is not an "esoteric topic" for me.  Is there NO information on this???

0 Kudos
andrew_4619
Honored Contributor III
2,662 Views

Esoteric for me, last used it in 1989 to talk to a "device" attached to a serial port. I asked AI and the answer was:

"Yes, assembly language is still used in modern software development, though its usage is specialized and often found in performance-critical or low-level contexts. While high-level languages are dominant for general-purpose programming, assembly remains relevant for tasks requiring direct hardware manipulation, specialized processor instructions, or optimizing performance bottlenecks. "

 

So I think the AI agent thinks it esoteric also....  A GITHUB entitled "Understanding Windows x64 Assembly" looked like it might be helpful.

0 Kudos
Steve_Lionel
Honored Contributor III
2,633 Views

If you program in assembler, and I did so for decades, there is adequate information on how calls are made and arguments passed. You will definitely want to declare your assembler routine as BIND(C) in Fortran so that arguments are passed in a more regular fashion.

I will say that in the nearly 40 years I did Fortran support, I can count the number of times I was asked about calls to assembly on one hand.

translinguist02
Beginner
138 Views

That error usually points to a calling convention or stack alignment issue especially when moving from 32-bit to 64-bit. In x64 (ml64), Windows uses a different calling convention (fastcall), so things like parameter passing, shadow space (32 bytes), and stack alignment (16-byte) really matter. If your assembly routine isn’t respecting that, you’ll hit access violations like this. Also double-check symbol naming and how the routine is declared in Fortran (bind(C) can help).

On a broader note, debugging mixed-language workflows like this is where smarter tooling and AI translation  & analysis tools can help streamline things.

0 Kudos
Reply