News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How to Create .H files?

Started by extremed, April 10, 2005, 09:20:45 PM

Previous topic - Next topic

extremed

Hello. I got an asm function. I did with RADASM and MASM32. It generated an obj file.

On Devc++ (my Ide) I included the obj file. in project options

But I dont know what should I put on this .h file and then how to call it from the main.c

I did this but I am not sure.

float MyProc(float var1, float var2);




This is my assembly function
.386
.model flat, stdcall
option casemap:none



.data


.code

Myproc proc var1:REAL4, var2:REAL4
    LOCAL retval:REAL4
    finit
    fld var1
    fld var2
    fadd
    fstp retval
    fwait                ;<- is this really needed?
    mov eax, retval
    ret
Myproc endp


end;

extremed

I did this on my C program

#include "H:\Practica Arquitectura del Computador\include\flotantes.h"


float MyProc(float, float);



void sum(void)
{
     float total2;
     total2 = MyProc(3.2, 4.2);
     printf("Total is: %d", total2);
}


But I get an error

  [Linker error] undefined reference to `MyProc'


my .h file is this

#ifndef _FLOTANTE_H
#define _FLOTANTE_H


float MyProc(float var1, float var2);


#endif


Xor Stance

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.486 ; create 32 bit code
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive

include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib
include \masm32\macros\macros.asm
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.data
v REAL4 1234.5
.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
push v
push v
call Myproc
print ustr$(eax)
mov eax,input(13,10,"Press enter to exit...")
exit

Myproc proc var1:REAL4, var2:REAL4

LOCAL rval:REAL4 ; retval is the name of a MASM32 macro

finit ; initialize fpu, reset register and flags to default
fld var1 ; push var1 onto fpu stack, ST(0)=var1
fld var2 ; push var2 onto fpu stack, ST(0)=var2,ST(1)=var1
fadd ; add ST(0) to ST(1), pop stack, leave result in ST(0)
;fstp rval ; store ST(0) value to rval, pop value from fpu stack
fistp rval ; same, but value is converted to an integer
mov eax, rval
ret

Myproc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


MichaelW example was clear enough, you must always include\masm32\include\windows.inc This one must be always included and kernel32.inc
to handle ht process and managements includelib \masm32\lib\kernel32.lib

Get Iczelion tutorials I already gave you the link before.

extremed

Did u even read my post?

I already created the assembly file. the obj file.

I am having problems is in my .h or .c file.


Brett Kuntz

//my_header.h
#define MyFunc __MyFunc
extern "C" __stdcall __MyFunc(float,float);

//my_code.cpp
int whatever = MyFunc(0.01, 1.2);



he #define is just so you don't have tp type __MyFunc() every time you want to use the function.

extremed

It doesnt work yet.

This is my float.h

#ifndef _FLOTANTE_H
#define _FLOTANTE_H

#define MyProc __MyProc
extern "C" __stdcall __MyProc(float,float);


float MyProc(float var1, float var2);

#endif


This is my Assembly code



.386

.model flat, stdcall

option casemap:none

;include \masm32\include\windows.inc
;include \masm32\include\kernel32.inc

.data


.code

Myproc proc var1:REAL4, var2:REAL4
    LOCAL retval:REAL4
    finit
    fld var1
    fld var2
    fadd
    fstp retval
    fwait                ;<- is this really needed?
    mov eax, retval
    ret
Myproc endp


end;



And this is my C code.

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
#include "H:\Practica Arquitectura del Computador\include\flotantes.h"

float MyProc(float, float);

void sum(void)
{
     float total2;
     total2 = MyProc(3.2, 4.2);
     printf("Total is: %d", total2);
}


But I have this error

Compilador: Default compiler
Building Makefile: "H:\Practica Arquitectura del Computador\Makefile.win"
Ejecutando  make...
make.exe -f "H:\Practica Arquitectura del Computador\Makefile.win" all
gcc.exe -c test/pentium/main.c -o test/pentium/main.o -I"C:/Dev-Cpp/include"  -I"H:/Practica Arquitectura del Computador/include"   

gcc.exe test/pentium/main.o  -o "test\pentium\Practica.exe" -L"C:/Dev-Cpp/lib" src/pentium/pentium.obj   

test/pentium/main.o(.text+0xdc):main.c: undefined reference to `MyProc'
collect2: ld returned 1 exit status

make.exe: *** [test/pentium/Practica.exe] Error 1

Ejecución Terminada

Brett Kuntz

Then it'll be:

extern "C" unsigned long __stdcall Myproc(float, float);

or

extern "C" unsigned long __stdcall _Myproc(float, float);

or

extern "C" unsigned long __stdcall __Myproc(float, float);

No idea if/how many underscores the linker or compiler or whatever will add to the begining of your function name. Might also want to add:


.code

Myproc proc var1:REAL4, var2:REAL4
PUBLIC Myproc
    ;stuff
Myproc endp


"PUBLIC Myproc" to your asm file.

hutch--

Note that this is not a C forum, if you have C coding questions, make the postings in the subforum for questions of C coding.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php