Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.asm.x86    |    Ahh, the lost art of x86 assembly    |    4,675 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 2,751 of 4,675    |
|    NimbUs to All    |
|    Re: interfacing ASM (ia-32) with GNU g77    |
|    28 Jun 17 12:23:09    |
      From: nimbus@nospicedham.XXX.invalid              Frank Kotler dit dans news:ois44e$njp$1@dont-email.me:              > Well, just for completeness... The Fortran code is not mine.       Got it off       > the Forum.              > program testassembly       > implicit none       > integer*8 summ,a,b       > a=2000000000       > b=2000000000       > write(6,*)summ(a,b)       > end              > The poster was trying to link against 64-bit code (as I       recall he was       > getting a segfault). This is my 32-bit version.              > section .text       > global summ_ ; leading underscore too for Windows       >       > summ_:       > push ebp       > mov ebp, esp       >       > mov eax, [ebp + 8] ; address of first parameter       > mov ecx, [ebp + 12] ; address of second parameter       > mov ebx, [eax+4] ; first parameter       > mov eax, [eax]       > mov edx, [ecx+4] ; second parameter       > mov ecx, [ecx]       > add eax, ecx ; add 'em up       > adc edx, ebx       > ; return result in edx:eax?       >       > mov esp, ebp       > pop ebp       > ret              Looks fine, save maybe - not sure if trashing EBX in a       function is safe - conventionnally use of EAX,ECX,EDX is       allowed. Here's FWIW my version of summing two integer*8,       based of Bogdan's integer*4 one upthread reads :       ____________________________________________________        section .text use32        global _sum64_        _sum64_: ; _2_ _underscores_ for Win32               %idefine a [ebp+8]        %idefine b [ebp+12]               push ebp        mov ebp, esp               ; assume both arguments of integer*8 type (64 bits)        ; Return sum in (EDX,EAX)        mov ecx, a ; ECX = address of param1        mov eax, [ecx] ; EAX = param1 dereferenced (LO       DW)        mov edx,[ecx+4]; ECX= param1 (hi DW)        mov ecx, b        add eax, [ecx]        adc edx,[ecx+4]        ; LEAVE = mov esp, ebp / pop ebp        leave        ret       ____________________________________________________                     > I assemble the .asm file first, then "g77 callsum.f summ.o -       o callsum"       > (no Makefile for this). As you can see, the .asm file       "expects" 64 bits       > and attempts to return 64 bits. This "seems to work" but g77       complains       > if I use a larger integer.              Do you mean using an integer /constant/ larger, in absolute       value, than 31-bits in the Fortran source ? That's a       misfeature of g77, you /cannot specify/ such a constant       directly to the compiler. Need to use a variable and either       have the large integer computed at run time, or play some       trickery with Fortran EQUIVALENCE...              > Perhaps "implicit none" is a problem? I don't       > even know how to comment it out!              'Implicit none' is accepted by g77. As for commenting a line       out, in Fortran there are several ways, historically it has       been by "punching" a 'C' in the first column of the "card"       (source line) :=)              Regards              --       NimbUs              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca