• C

asm 386 to C program?

I want a program that convert an assembly program in 386 to a C program.

If you having any information for this please help me.
javadpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

javadpAuthor Commented:
Edited text of question.
0
rbrCommented:
Check
http://www.skwc.com/essent/prognotebook.html and see there will be no such programm which will be able to do this task. If it is short put in the source here and I will convert it for you.
0
javadpAuthor Commented:
Thank rbr,

I have two question from

1 - I want use procedure in my assembly file , so I make .OBJ file , How I can use that procedures in my C program.

2 - How can I have this command in C
asm { shr eax,1}
(compiler error that eax not defined)
0
Redefining Cyber Security w/ AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Join our webinar on Sept. 21st to learn more about leveraging AI and machine learning to protect your business.

graham_kCommented:
2) wht variable is in EAX? Let's call it "fred".  Code in C as

fred = fred >> 1;
0
javadpAuthor Commented:
graham_k

for this work i would change my program assembly code
0
graham_kCommented:
oops, sorry, that was never meant to be an answer. I only meant a little comment.
0
mrmickCommented:
You can copy the assembly procedure into your c project.  For example:
MyAsmProc()
{
   __asm
   {
      <assembly here>
      shr eax, 1 ;or whatever
   }
}
0
AlexVirochovskyCommented:
More simple back way :
creates Asn code from C/C++ :
example from BC:
bcc32.exe -S myfile.c genarates
myfile.asm and you can learn what you
want.
0
javadpAuthor Commented:
Hi mrmick ,

your code message this error :
Undefined symbo eax
0
AlexVirochovskyCommented:
Inline Assembler Register Symbols

In the Borland C++ inline assembler, the following reserved symbols denote CPU registers:

Symbols      Registers

AX BX CX DX      16-bit general purpose
AL BL CL DL      8-bit low registers
AH BH CH DH      8-bit high registers
SP BP SI DI      16-bit pointer or index
CS DS SS ES      16-bit segment registers
ST      8087 register stack

When an operand consists solely of a register name, it is called a register operand. All registers can be used as register operands.

Register Indexing

The base registers (BX and BP) and the index registers (SI and DI) can be written within square brackets to indicate indexing.
These are valid index register combinations:

[BP]
[BP+DI]
[BP+SI]
[BX]
[BX+DI]
[BX+SI]
[DI]
[SI]

Segment Overriding

The segment registers (ES, CS, SS, and DS) can be used in conjunction with the colon (:) segment override operator to indicate a different segment than the one the processor selects by default.
For example:

asm mov AX, 0xb000
asm mov ES, AX
asm mov SI, WORDPTR es:[0]

Borland C++ 5.0 Programmer's Guide
0
javadpAuthor Commented:
Hi AlexVirochovsky ,
& thank you for your comment

but another assembly command for example
Rep stod
or
jmp lable
or
call procedure

not work truely in asm { }
segment of c program
0
javadpAuthor Commented:
Hi AlexVirochovsky ,
& thank you for your comment

but another assembly command for example
Rep stod
or
jmp lable
or
call procedure

not work truely in asm { }
segment of c program
0
AlexVirochovskyCommented:
Next is exaple(from BCB4) using
labels and call to function

void __fastcall TIBEventAlerter::RegisterEvents(void)
{
  ValidateDatabase( Database);
  if( ComponentState.Contains( csDesigning )  )
    FRegistered = true;
  else
  {
    UnRegisterEvents();
    if( Events->Count == 0 )
       return;
    for(int i = 0; i < Events->Count; i++ )
      strcpy( Buffer[i], Events->Strings[i].c_str());

    EventBufferLen = IscEventBlock(&EventBuffer,
                                   &ResultBuffer,
                                   Events->Count,
                                   Buffer[0]);

    //Below is how one would more thoroughly call IscEventBlock
    //to supply multiple string pointers on the stack.  The above method
    //only does one.
    /*
    asm
    {
      mov ecx, dword ptr [i]
      mov eax, dword ptr [bufptr]
      @@1:
      push eax
      add  eax, EventLength
      loop @@1
      push dword ptr [i]
      push dword ptr [resultBufPtr]
      push dword ptr [eventBufPtr]
      call [IscEventBlock]
      mov  dword ptr [buflen], eax
      mov eax, dword ptr [i]
      shl eax, 2
      add eax, 12
      add esp, eax
     }*/ // end asm block
    FRegistered = true;
    QueueEvents();
  }
}

And why you think, that Rep , Jmp
and other don't works truely?
Next is about jmp:

Inline Assembler Jump Optimization

The inline assembler optimizes jump instructions by automatically selecting the shortest, most efficient form of a jump instruction.
When the target is a label (not a procedure or function), this automatic jump sizing applies to JMP and to all conditional jump instructions.

Opcode      Distance to Target Label      Inline Assembler Generates



JMP      Within -128 to 127 bytes            Short jump
      NOT within -127 to 128 bytes      Near jump
Conditional      Within -128 to 127 bytes            Short jump
Jumps      NOT within -127 to 128 bytes      Short jump

Jumps to the entry points of procedures and functions are always either near or far, but never short.
Conditional jumps to procedures and functions are not allowed.

Borland C++ 5.0 Programmer's Guide

 But nevermind: the rule is:
use Inline assemler only , if you really
must it!   If you read c/c++ code,
use C/C++ operators. If you want
large assemler code, use Tasm/Masm and after that link obj
file: In BC simple add myasm.obj in
project.
Alex
 


0
AlexVirochovskyCommented:
And else one thing:
if you use flat model of memory(
32b apps), you can use eax,ebx, ..
but if you make 16b apps, you must
use AX, BX, ..  
0
rbecCommented:
Hi, javadp.

I don't know if you still have problems linking assembler and C.

I see most people have tried to help you with "inline - asm" tips.  If you want to try something different, you could use assembler and C separated.

What version are you using? Borland C?

If so, you can make your procedures in a std asm language, and assemble it with MASM or TASM. (I think it's easier with MASM  because it simplifies the using of parameters in functions ... use the -c option for compile only)

After that, you add the lines :

extern  ASM_PROC_NAME;
....

where the main program begins(written in C, of course)

And then you have two options:

1. Compile the C file to produce an .OBJ file, and link all the modules using MAKE (a command line executable), LINK or TLINK (you will find them in the TC\BIN directory).  It's a little more difficult, but faster than the second ...

2. Compile and Link all the .OBJ files using a PROJECT in the IDE of Borland C, including the source C file, and the .OBJ files generated by MASM or TASM in the previous steps.

I hope this works for you.    I'll try to find an old example I have somewhere, and mail it to you (I would need your e-mail, by the way).

See you.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.