Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Assembly code with Borland's C compiler

6 views
Skip to first unread message

Hul Tytus

unread,
Dec 27, 2009, 12:23:59 PM12/27/09
to
comp.arch.embedded
Assembly code with Borland's C compiler

Anyone have suggestions regarding the form for assembley code files used
with Borland's version C compiler? The code below, assembled by masm6, doesn't
satisfy the linker (Borland's).
The segment names are a guess for the most part - taken from masm6's
accrued examples on other projects. "cs:DGROUP" appears off but, if the error
is due to segment names, maybe someone here knows suitable names?
The code & bat file & error messages are included below.

Hul

*********************************************************
; wedtst.asm
name SUPP32 ; ???

.386p
public _wedtst

; Segments & groups
DGROUP group _TEXT

_TEXT segment
assume cs:DGROUP,ds:DGROUP

_wedtst proc ; awk (WORD gdtsize, DWORD flataddr) void public
push bp ;save bp
mov bp,sp ; -> stack frame
mov eax, 66
pop bp ;restore bp
ret
_wedtst endp
_TEXT ends
end

******** bat file
SET BC55PATH=C:\BOR5

%BC55PATH%\bin\bcc32 -c -tW -a4 -g20 -I.. -I%BC55PATH%\include windil.c >
compout.txt
rem %BC55PATH%\bin\brc32 -i%BC55PATH%\include windil.rc >> compout.txt
%BC55PATH%\bin\ilink32 -L%BC55PATH%\lib -c -aa -Tpe c0w32+windil+wedtst,windil,
NULL,import32.lib+cw32.lib,, >> compout.txt
type compout.txt | more

******* compout.txt
C:\bor5\wed>SET BC55PATH=C:\BOR5
C:\bor5\wed>C:\BOR5\bin\bcc32 -c -tW -a4 -g20 -I.. -IC:\BOR5\include windil.c
1>compout.txt
C:\bor5\wed>C:\BOR5\bin\ilink32 -LC:\BOR5\lib -c -aa -Tpe c0w32+windil+wedtst,
windil,NULL,import32.lib+cw32.lib,, 1>>compout.txt
C:\bor5\wed>type compout.txt | more
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
WINDIL.C:
Warning W8057 WINDIL.C 48: Parameter 'hPrevinstance' is never used in function
WinMain
Warning W8057 WINDIL.C 48: Parameter 'szCmdLine' is never used in function
WinMain
Warning W8065 WINDIL.C 200: Call to function 'pooi' with no prototype in
function WndProc
Warning W8065 WINDIL.C 262: Call to function 'iitoaa' with no prototype in
function pooi
Warning W8070 WINDIL.C 265: Function should return a value in function pooi
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external '_wedtst' referenced from C:\BOR5\WED\WINDIL.OBJ

Rich Webb

unread,
Dec 27, 2009, 1:09:37 PM12/27/09
to
On Sun, 27 Dec 2009 17:23:59 +0000 (UTC), Hul Tytus <h...@panix.com>
wrote:

>comp.arch.embedded
>Assembly code with Borland's C compiler
>
> Anyone have suggestions regarding the form for assembley code files used
>with Borland's version C compiler? The code below, assembled by masm6, doesn't
>satisfy the linker (Borland's).
> The segment names are a guess for the most part - taken from masm6's
>accrued examples on other projects. "cs:DGROUP" appears off but, if the error
>is due to segment names, maybe someone here knows suitable names?
> The code & bat file & error messages are included below.

It's been ages since I fiddled with X86 assembly but this might help.

For "Borland C++ 5.5.1" (the version with BCB5), and running
"bcc32 -S hello.c" on
---
#include <stdio.h>

main()
{
puts("Hello, world!");
return 0;
}
---

we get "hello.asm" as
---
.386p
ifdef ??version
if ??version GT 500H
.mmx
endif
endif
model flat
ifndef ??version
?debug macro
endm
endif
?debug S "hello.c"
?debug T "hello.c"
_TEXT segment dword public use32 'CODE'
_TEXT ends
_DATA segment dword public use32 'DATA'
_DATA ends
_BSS segment dword public use32 'BSS'
_BSS ends
DGROUP group _BSS,_DATA
_TEXT segment dword public use32 'CODE'
_main proc near
?live1@0:
;
; main()
;
push ebp
mov ebp,esp
;
; {
; puts("Hello, world!");
;
@1:
push offset s@
call _puts
pop ecx
;
; return 0;
;
xor eax,eax
;
; }
;
@3:
@2:
pop ebp
ret
_main endp
_TEXT ends
_DATA segment dword public use32 'DATA'
s@ label byte
; s@+0:
db "Hello, world!",0
align 4
_DATA ends
_TEXT segment dword public use32 'CODE'
_TEXT ends
public _main
extrn _puts:near
?debug D "C:\Program Files\Borland\CBuilder5\Include\_nfile.h"
10303 10240
?debug D "C:\Program Files\Borland\CBuilder5\Include\_null.h"
10303 10240
?debug D "C:\Program Files\Borland\CBuilder5\Include\_defs.h"
10303 10240
?debug D "C:\Program Files\Borland\CBuilder5\Include\_stddef.h"
10303 10240
?debug D "C:\Program Files\Borland\CBuilder5\Include\stdio.h"
10303 10240
?debug D "hello.c" 14050 28522
end
---

--
Rich Webb Norfolk, VA

Jon Kirwan

unread,
Dec 27, 2009, 1:27:47 PM12/27/09
to
On Sun, 27 Dec 2009 17:23:59 +0000 (UTC), Hul Tytus <h...@panix.com>
wrote:

>comp.arch.embedded


>Assembly code with Borland's C compiler
>
> Anyone have suggestions regarding the form for assembley code files used
>with Borland's version C compiler? The code below, assembled by masm6, doesn't
>satisfy the linker (Borland's).
> The segment names are a guess for the most part - taken from masm6's
>accrued examples on other projects. "cs:DGROUP" appears off but, if the error
>is due to segment names, maybe someone here knows suitable names?
> The code & bat file & error messages are included below.
>
>Hul

I don't have time right now to dig into this. But could you post the
error messages? The exact details of those you are getting?

I gather from the above you are using a Microsoft assembler's output
and linking it together with the output from a Borland c compiler
using the Borland linker. Another thing to keep in mind is that the
records placed in the OBJ file (aside from naming issues you above
suggest) might be somewhat different -- in short, the Borland linker
may not recognize every record in the output of the Microsoft
assembler. Though it may. I just don't know. The error messages may
help to disambiguate here.

Jon

ArarghMai...@not.at.arargh.com

unread,
Dec 27, 2009, 1:57:37 PM12/27/09
to
On Sun, 27 Dec 2009 17:23:59 +0000 (UTC), Hul Tytus <h...@panix.com>
wrote:

>comp.arch.embedded

Unless I have missed something, this will generate a 16-bit object,
and it looks like the c code (from below) is 32-bit. That generally
don't work.

Try something more like:

.386
.model flat
.code


_wedtst proc ; awk (WORD gdtsize, DWORD flataddr) void public
push bp ;save bp
mov bp,sp ; -> stack frame
mov eax, 66
pop bp ;restore bp
ret
_wedtst endp

end

--
ArarghMail912 at [drop the 'http://www.' from ->] http://www.arargh.com
BCET Basic Compiler Page: http://www.arargh.com/basic/index.html

To reply by email, remove the extra stuff from the reply address.

Tim Wescott

unread,
Dec 27, 2009, 2:03:29 PM12/27/09
to
On Sun, 27 Dec 2009 17:23:59 +0000, Hul Tytus wrote:

> comp.arch.embedded
> Assembly code with Borland's C compiler
>
> Anyone have suggestions regarding the form for assembley code files
> used
> with Borland's version C compiler? The code below, assembled by masm6,
> doesn't satisfy the linker (Borland's).
> The segment names are a guess for the most part - taken from masm6's
> accrued examples on other projects. "cs:DGROUP" appears off but, if the
> error is due to segment names, maybe someone here knows suitable names?
> The code & bat file & error messages are included below.
>

-- snip --

If I'm working with a tool chain that supports compiling to assembly I
cheat. I write a framework file in C and compile to assembly, then find
the insides of the functions and start writing code.

It may not be manly, but it works just fine.

--
www.wescottdesign.com

Jon Kirwan

unread,
Dec 27, 2009, 2:22:34 PM12/27/09
to
On Sun, 27 Dec 2009 10:27:47 -0800, I wrote:

><snip>


>I don't have time right now to dig into this. But could you post the
>error messages? The exact details of those you are getting?

Hehe. Cripes. In my rush to dash off a reply I didn't read the
"mess" I saw below the OP's post. My fault. I'll look, later.

Jon

Hul Tytus

unread,
Dec 27, 2009, 5:42:32 PM12/27/09
to
comp.arch.embedded
Assembly code with Borland's C compiler

Anyone have suggestions regarding the form for assembley code files used
with Borland's version C compiler? The code below, assembled by masm6, doesn't
satisfy the linker (Borland's).
The segment names are a guess for the most part - taken from masm6's
accrued examples on other projects. "cs:DGROUP" appears off but, if the error
is due to segment names, maybe someone here knows suitable names?
The code & bat file & error messages are included below.

Hul

*********************************************************
; wedtst.asm
name SUPP32 ; ???

.386p
public _wedtst

; Segments & groups
DGROUP group _TEXT

_TEXT segment
assume cs:DGROUP,ds:DGROUP

_wedtst proc ; awk (WORD gdtsize, DWORD flataddr) void public
push bp ;save bp
mov bp,sp ; -> stack frame
mov eax, 66
pop bp ;restore bp
ret
_wedtst endp
_TEXT ends
end

******** bat file

Hul Tytus

unread,
Dec 27, 2009, 6:45:06 PM12/27/09
to

d...@kbrx.com

unread,
Dec 27, 2009, 6:49:47 PM12/27/09
to
Thanks Rich - those segment names look like an improvement. I'll give them
a try.

Hul

d...@kbrx.com

unread,
Dec 27, 2009, 6:54:21 PM12/27/09
to
Jon - as you suggest, mixing Borland & MS object code requires optimism.
The error from the linker is at the bottom of the message.

Hul

d...@kbrx.com

unread,
Dec 27, 2009, 6:57:30 PM12/27/09
to
I'll give it a try & see what happens.

Hul

d...@kbrx.com

unread,
Dec 27, 2009, 6:59:01 PM12/27/09
to
Tim
Sounds good - I'll try it.

Hul

ArarghMai...@not.at.arargh.com

unread,
Dec 27, 2009, 9:43:34 PM12/27/09
to
On Sun, 27 Dec 2009 23:57:30 +0000 (UTC), d...@kbrx.com wrote:

>I'll give it a try & see what happens.

And DON'T use '/coff' on the command line. You should get 32-bit OMF
files, which is what I think the Borland linker expects. Never used
Borland products, so don't really know.

<snip>

Chris H

unread,
Dec 28, 2009, 4:13:47 AM12/28/09
to
In message <xaudnWLLO9McMqrW...@web-ster.com>, Tim Wescott
<t...@seemywebsite.com> writes

I always recommended that method. Particularly when people wanted in
line assembly or a small amount of assembly in a C program.

write an empty c function call, with all the parameters, compile to
assembler and out the body in by hand.

This sorts out all the parameter passing and you can call it with a
standard C include file. Much more efficient.

Of course at one time all compilers went to assembly code Then you
assembled and linked. Actually even the compilers tended to be 3 pass
affairs. Now it is a single pass to object code ...

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Vladimir Vassilevsky

unread,
Dec 28, 2009, 10:02:58 AM12/28/09
to

Chris H wrote:

> In message <xaudnWLLO9McMqrW...@web-ster.com>, Tim Wescott
> <t...@seemywebsite.com> writes
>

>>If I'm working with a tool chain that supports compiling to assembly I


>>cheat. I write a framework file in C and compile to assembly, then find
>>the insides of the functions and start writing code.
>>
>>It may not be manly, but it works just fine.
>
>
> I always recommended that method. Particularly when people wanted in
> line assembly or a small amount of assembly in a C program.
>
> write an empty c function call, with all the parameters, compile to
> assembler and out the body in by hand.

The simple and stupid way for passing parameters between C and assembler
is by global variables. It is trivial, it is portable, and independent
from possible changes in the calling agreements of the future versions
of the same toolset. The aesthetes can implement some sort of locking or
roll their own stack to ensure atomic access to globals.

Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com

Marco

unread,
Dec 28, 2009, 10:31:53 AM12/28/09
to
On Dec 27, 10:23 am, Hul Tytus <h...@panix.com> wrote:
> comp.arch.embedded
> Assembly code with Borland's C compiler
>
>    Anyone have suggestions regarding the form for assembley code files used
> with Borland's version C compiler?

What embedded target is this for?

Chris H

unread,
Dec 28, 2009, 12:19:46 PM12/28/09
to
In message <d6b5e078-9226-4f28...@o28g2000yqh.googlegroup
s.com>, Marco <prenom...@yahoo.com> writes

X86 AFAIK Borland only did compilers for X86

Tim Wescott

unread,
Dec 28, 2009, 12:25:14 PM12/28/09
to

I don't recall having a single problem with calling agreements breaking
down with toolset version. That doesn't seem to be something that
changes often -- and I've always been in an environment where we bind a
software version to a toolset version, and treat a toolset upgrade as
major.

It's certainly a dire thing when the agreement does change, though.

--
www.wescottdesign.com

FreeRTOS info

unread,
Dec 28, 2009, 12:52:03 PM12/28/09
to
Chris H wrote:
> In message <d6b5e078-9226-4f28...@o28g2000yqh.googlegroup
> s.com>, Marco <prenom...@yahoo.com> writes
>> On Dec 27, 10:23 am, Hul Tytus <h...@panix.com> wrote:
>>> comp.arch.embedded
>>> Assembly code with Borland's C compiler
>>>
>>> Anyone have suggestions regarding the form for assembley code files used
>>> with Borland's version C compiler?
>> What embedded target is this for?
>
> X86 AFAIK Borland only did compilers for X86

I thought that until recently - but apparently they did others too. We
had a request the other day for some other CPU. Although I forget which
it was exactly I think it was an old Motorola thing, maybe 68K?

Maybe this has already been written here as I have not read the whole
thread, but Borland C 5.5 I think is now (legitimately) free. Paradigm
have their own version that is still updated and supported. OpenWatcom
have some nice alternative solutions too (not Borland based).

--

Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers. More than 7000 downloads per month.

+ http://www.SafeRTOS.com
Certified by T�V as meeting the requirements for safety related systems.

Jim Stewart

unread,
Dec 28, 2009, 12:55:55 PM12/28/09
to
Hul Tytus wrote:
> comp.arch.embedded
> Assembly code with Borland's C compiler
>
> Anyone have suggestions regarding the form for assembley code files used
> with Borland's version C compiler? The code below, assembled by masm6, doesn't
> satisfy the linker (Borland's).

You might want to dig around on our download page..

http://www.jkmicro.com/downloads/downloads.html

I know that FC.ZIP

http://www.jkmicro.com/downloads/zip/fc.zip

implements an interrupt-driven frequency counter
in asm along with a Borland host environment.

Chris H

unread,
Dec 28, 2009, 3:10:45 PM12/28/09
to
In message <hhar7v$jbt$1...@news.eternal-september.org>, FreeRTOS info
<noe...@given.com> writes

>Chris H wrote:
>> In message <d6b5e078-9226-4f28...@o28g2000yqh.googlegroup
>> s.com>, Marco <prenom...@yahoo.com> writes
>>> On Dec 27, 10:23 am, Hul Tytus <h...@panix.com> wrote:
>>>> comp.arch.embedded
>>>> Assembly code with Borland's C compiler
>>>>
>>>> Anyone have suggestions regarding the form for assembley code files used
>>>> with Borland's version C compiler?
>>> What embedded target is this for?
>>
>> X86 AFAIK Borland only did compilers for X86
>
>I thought that until recently - but apparently they did others too. We
>had a request the other day for some other CPU. Although I forget which
>it was exactly I think it was an old Motorola thing, maybe 68K?

That would be Pascal. Borland did do some Pascal stuff in the beginning
(this is from memory but it was decades ago) hence their Delphi was
based on Pascal.


>Maybe this has already been written here as I have not read the whole
>thread, but Borland C 5.5 I think is now (legitimately) free.

I believe the Borland x86 C and C++ compilers are available on free
download.

d...@kbrx.com

unread,
Dec 28, 2009, 4:07:47 PM12/28/09
to
Thanks Chris. I'll follow your suggestion.

Hul

d...@kbrx.com

unread,
Dec 28, 2009, 4:15:34 PM12/28/09
to
Jim - I'll look at those, thanks.

Hul

Hul Tytus

unread,
Dec 28, 2009, 4:54:39 PM12/28/09
to
comp.arch.embedded
Assembly code with Borland's C compiler

More working with Borland's compiler: trying to link 2 .obj files generated
by Borland's compiler without any errors indicated, untill the .exe is
executed. Then windows pops a window saying, roughly, this application has
generated an error and we are closing the application - an error log is being
created.
Anyone know where Microsoft hides their error logs?

Hul


Stefan Reuther

unread,
Dec 28, 2009, 5:40:12 PM12/28/09
to
Vladimir Vassilevsky wrote:
> Chris H wrote:
>> I always recommended that method. Particularly when people wanted in
>> line assembly or a small amount of assembly in a C program.
>>
>> write an empty c function call, with all the parameters, compile to
>> assembler and out the body in by hand.
>
> The simple and stupid way for passing parameters between C and assembler
> is by global variables.

It depends. On some architectures, fetching a few values from parameter
registers is a lot easier than constructing a global variable address in
an address register and dereferencing that.

The best way is, of course, to use GNU-style asm operand constraints.


Stefan

Marco

unread,
Dec 29, 2009, 11:37:16 AM12/29/09
to
On Dec 28, 10:19 am, Chris H <ch...@phaedsys.org> wrote:
> In message <d6b5e078-9226-4f28-9f2d-db945618a...@o28g2000yqh.googlegroup
> s.com>, Marco <prenom_no...@yahoo.com> writes

>
> >On Dec 27, 10:23 am, Hul Tytus <h...@panix.com> wrote:
> >> comp.arch.embedded
> >> Assembly code with Borland's C compiler
>
> >> Anyone have suggestions regarding the form for assembley code files used
> >> with Borland's version C compiler?
>
> > What embedded target is this for?
>
> X86  AFAIK Borland only did compilers for X86

CPU type is fairly obvious. Not what I meant.
Is the OP targeting some kind of DOS like target, bare-metal (Phar
Lap like target) or some kind of Win32 based target?

To me it sounds like he may be trying to target something Win32
based and needs to contact the specific vendor. Most people don't mix
Microsoft and Borland for DOS or bare metal targets.


Marco

unread,
Dec 29, 2009, 11:39:23 AM12/29/09
to

Is this an embedded target?

What OS ?

This is an embedded news group.

Jim Stewart

unread,
Dec 29, 2009, 2:20:22 PM12/29/09
to

There are literally hundreds of thousands
of embedded DOS computers out there. I know,
I built a few tens of thousands of them...

Chris H

unread,
Dec 30, 2009, 4:20:25 AM12/30/09
to
In message <hhdkpj$851$1...@news.eternal-september.org>, Jim Stewart
<jste...@jkmicro.com> writes

Apart from that the 386 was quite widely used in embedded work. There
was a specific embedded version AFAIr. Whilst not as common as some MCU
the x86 family was used in embedded work with and without a DOS & BIOS

Where x86 was used for embedded work the Borland compiler tended to be
the compiler of choice. I have a rom kit for the Borland compilers if
anyone is interested.

invalid

unread,
Dec 30, 2009, 5:28:12 AM12/30/09
to
"Chris H" <ch...@phaedsys.org> wrote in message
news:yDd6G6BZ...@phaedsys.demon.co.uk...

>
> Apart from that the 386 was quite widely used in embedded work. There
> was a specific embedded version AFAIr. Whilst not as common as some MCU
> the x86 family was used in embedded work with and without a DOS & BIOS
>
> Where x86 was used for embedded work the Borland compiler tended to be
> the compiler of choice. I have a rom kit for the Borland compilers if
> anyone is interested.
>

The 80186(&8)EA/B/C series were used in embedded applications with the
Borland compiler, requiring a very small BSP to furnish BIOS compatibility.
Nigel Roles (of York University) did much of the groundwork.


0 new messages