Looks like this is going to be a short thread.
I haven't programmed any fortran or nasm in at least ten years and coming back to it after that long and from 32-bit to 64-bit has been a bit overwhelming. But I persisted. The problem I was having was caused by my accidentally misdeclaring the maddr function in my fortran code as real, making me think the maddr function was at fault. See below for the code for the maddr function plus two fortran examples of its usage compared with fortran's loc function for both an x86-64 integer and an x86-64 real. If you see any slipups, please let me know.
Michael
Nasm machine address function:
global maddr_
section .text ;return the (64-bit integer) machine address of a variable
maddr_:
push rbp
mov rax, rdi
pop rbp
ret
=======Tested with loc in gfortran=======
Machine address of x86-64 integer variable
integer, external :: maddr
integer i,j
integer k
k=33
i=loc(k)
j=maddr(k)
write(*,*) i,j
end
nasm -f elf64 maddr.asm -o maddr.o && gfortran maddrtest.f90 maddr.o && ./a.out
2099635748 2099635748
Machine address of x86-64 real variable
integer, external :: maddr
integer i,j
real c
c=17.5
i=loc(c)
j=maddr(c)
write(*,*) i,j
end
nasm -f elf64 maddr.asm -o maddr.o && gfortran maddrtest.f90 maddr.o && ./a.out
1430344396 1430344396