Com File Inline Assembly

DOS specific questions.
Post Reply
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Com File Inline Assembly

Post by nimdays »

Hello , this is me again , i made a com file with FB
Just wandering , do you think this code is safe ?
Thanks

Code: Select all

declare sub printc naked(src as byte)

sub main naked()
 asm
  .code16
 end asm
 
 const s  = "Hello World !"
 dim i as ubyte
 dim p as byte ptr = cptr(byte ptr,@s)
 
 for i = 0 to len(s)
   printc p[i]
 next i
 
 asm
  '.code16
  int &h20
 end asm
 
end sub
sub printc(src as byte)

 asm
  '.code16
  push bp
  mov bp,sp
  mov ah,&h0e
  mov al,[bp+4]
  int &h10
  pop bp 
  ret
 end asm
 
end sub

Code: Select all

fbc -R -c test.bas
ld -e _MAIN@0 -Ttext 0x100 --oformat=binary -o test.com test.o
test
pause
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: Com File Inline Assembly

Post by nimdays »

No problem :)
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: Com File Inline Assembly

Post by MichaelW »

I get an error when I try to link, even when I add -target dos to the fbc command line:

ld: cannot perform PE operations on non PE output file 'test.com'.

As far as I can tell, and in the time I spent searching, LD does not support 16-bit code.
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: Com File Inline Assembly

Post by nimdays »

MichaelW wrote:I get an error when I try to link, even when I add -target dos to the fbc command line:

ld: cannot perform PE operations on non PE output file 'test.com'.

As far as I can tell, and in the time I spent searching, LD does not support 16-bit code.
Thanks , for ld you can try from FB-win32-dos-binutils-2.23.2.zip or use the dos version (FreeBASIC-0.90.1-dos.zip)
I believe ld from FreeBASIC-0.90.1-win32 is from mingw and not very friendly with binary ,djgpp is more friendly.
I did a test with mingw from devcpp

Code: Select all

void main()
{
 
}

Code: Select all

gcc test.c -c
ld --oformat binary test.o -o test.bin

Code: Select all

ld: cannot perform PE operations on non PE output file 'test.bin'.
About 16 bit code , maybe you're right.
DOS386
Posts: 798
Joined: Jul 02, 2005 20:55

Re: Com File Inline Assembly

Post by DOS386 »

nimdays wrote:Hello , this is me again , i made a com file with FB Just wandering , do you think this code is safe ?
Sure it's safe, assuming that it works at all ... this had been already discussed: http://www.freebasic.net/forum/viewtopic.php?t=21085

- FBC can't generate 16-bit code (only 32-bit)
- FB lib's are written in C and precompiled to 32-bit code
- FBC can generate C code and then you can compile this C code to 16-bit binary
- but you must provide 16-bit libraries (seems that your "sub printc(src as byte)" is an attempt to do this)
- GAS has limited 16-bit support, but LD definitely can't brew DOS COM -> need other linker too
Post Reply