www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/11/25/05:36:35

From: "Fairbairn Family" <lgcl01 AT es DOT co DOT nz>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Using AS (GAS) to produce COM files - is it possible?
Date: Sat, 25 Nov 2000 23:24:33 +1300
Organization: ihug ( New Zealand )
Lines: 127
Message-ID: <8vo4e9$m95$1@lust.ihug.co.nz>
References: <8vn57g$rol$1 AT lust DOT ihug DOT co DOT nz> <8vnig9$5sl$2 AT newsg1 DOT svr DOT pol DOT co DOT uk>
NNTP-Posting-Host: p31-max1.inv.ihug.co.nz
X-Trace: lust.ihug.co.nz 975148298 22821 203.173.222.159 (25 Nov 2000 10:31:38 GMT)
X-Complaints-To: abuse AT ihug DOT co DOT nz
NNTP-Posting-Date: Sat, 25 Nov 2000 10:31:38 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi,

> As far as I am aware AS/GAS  is 32 bit only

Quoting the Linux Assembly howto:

3.2.4. 16-bit mode

   Binutils (2.9.1.0.25+) now fully support 16-bit mode (registers and
   addressing) on i386 PCs. Use .code16 and .code32 to switch between
   assembly modes.

ld -v reports "GNU ld version 2.9.5  (with BFD 2.9.5)", all other binutil
programs report similar messages. as doesn't give any problem with using the
.code16 directive.

> .COM  files are 16 bit only (again AFAIK)

Shouldn't be a problem given the above..... I don't know if they are 16bit
only either, I'm pretty sure they are though....

> they are similar to DOS 16 .EXE files but always run at address $100 ( at
> least , when dos was still cp/m )

Still correct today, so I simply insert .org 0x100 at the top of the asm
file (at least the equivalent command in NASM [org 100h] did the job)

> are you compiling to DOS 16 or DOS 32 with NASM?

Com file format output... 16bit I suppose. I don't normally assemble for x86
(I target 68K,AVR and PICs most of the time) so forgive my ignorance when it
comes to x86 asm.

Playing around with a hex editor I have found that the produced file from
using as/ld/objcopy is very similar to the NASM generated com file - the hex
dumps follow:

From nasm (code which works)

E9 1A 00 48 65 6C 6C 6F 20 77 6F 72 6C 64 21 20 54 68 69 73 20 47 41 53 0A
24 BA 03 01 E8 05 00 B8 00 4C CD 21 B4 09 CD 21 C3

While my binutil command sequence produces

EB 1A 48 65 6C 6C 6F 20 77 6F 72 6C 64 21 20 54 68 69 73 20 69 73 20 47 41
53 0A 24 8B 16 02 01 E8 05 00 B8 00 4C CD 21 B4 09 CD 21 C3 8D 74 00
<followed by 208 00's>

The binutil generate file seems to differ slightly at the front (EB 1A vs E9
1A 00) then the ascii string follows (Hello World! This is GAS\n$), then
there is a difference again followed by a similarity (E8 05 00 B8 00 4C CD
21 C3) followed by another small difference.

The 208 00's are probably just padding as this makes the binary 256 bytes in
size.... I don't know enough about x86 opcodes to try to disasemble
this.....

The binutil sequence I've used is:

as gastest.s -o gastest.o
ld gastest.o -Ttext 0x100 -s -static -o -gastest.dat
objcopy -j .text -O binary gastest.dat gastest.com

The code I am trying to assemble with "as" is:

.code16
# .org 0x100
.text

    jmp start

kisypp_signon:
    .ascii "Hello world! This is GAS\n$"

.global start

start:
    movw kisypp_signon,%dx
    call put_string

    # Exit the program!
_exit:
    movw $0x4C00,%ax  # Give control back to DOS
    int $0x21

# Print a string which is terminated with a $ character - DX points to
string
put_string:
    movb $9,%ah  # call string display function
    int $0x21
    ret

The generated output is getting so close now that I beileve what I am trying
to do should be possible, but well see in the matter of time.

Any ideas on how I should proceed?

Thanks for your help already,
Christopher Fairbairn.

PS the code which works with NASM (which should be excatly the same as the
GAS code above - if I rewrote it properly) is as follows:

org 100h

    jmp start

kisypp_signon   db "Hello world! This is GAS",10,"$"

start:
    mov dx,kisypp_signon
    call put_string
_exit:
    mov ax, 4C00h
    int 21h

put_string:
    mov ah, 9
    int 21h
    ret

I know its not the best code and its not optomized.... but its been hacked
so many times it trying to get AS to assemble the AT&T version of this
program. I keep making this Intel (NASM) program excatly the same so that I
can compare the outputs.


- Raw text -


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