www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/08/01:33:36

From: frolikcc AT indy DOT net (Chris Frolik)
Newsgroups: comp.os.msdos.djgpp
Subject: in-line __asm__
Date: 7 Jul 1997 03:08:33 GMT
Organization: IndyNet - Indys Internet Gateway
Lines: 50
Message-ID: <5ppmjh$onp$1@news.indy.net>
NNTP-Posting-Host: ip72-83.ts.indy.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I am starting to learn assembly language, and I am already pretty familiar 
with C and C++.  I would like to try some in-line assembly code in DJGPP, but 
I am not quite sure how.

I tried the following C program:

/* BEGIN program */

#include <stdio.h>

int multiply(char); /* function prototype */

int main()
{
   char x=5;
   int result;

   result = multiply(x);
   printf("\nThe result of the multiplication is %d\n", result);
   return 0;
}

int multiply(char c)
{
   short int r;

   /* Assembly routine to multiply c by 2: */
   __asm__ ("
      movb  $2,%ax
      imulb c
      movw  %ax,r
   ");
 
   return (int)r;
}

/* END program */

I just wrote this to see if I could get inline assembly routines to work with 
DJGPP.  When I compile, it tells me that 'c' and 'r' are undefined.  I am 
assuming it means they are undefined within the assembly code.  I read the FAQ 
on this, and then the text info docs that it pointed me to.  I didn't 
understand the method it tells me to use, and I want to use the standard ANSI 
C inline assembly method, like in Pascal.  So, my question is how do I pass 
variables to assembly routines in this method?  I apologize if my assembly 
code is incorrect since I am still trying to learn the language.  It is bad 
enough that my tutorial book covers Intel assembly, and DJGPP requires AT&T 
assembly.  Thanks,

-Chris

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019