Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What assembler do you intend to target for 8086 code? #117

Open
cr1901 opened this issue May 26, 2021 · 5 comments
Open

What assembler do you intend to target for 8086 code? #117

cr1901 opened this issue May 26, 2021 · 5 comments

Comments

@cr1901
Copy link

cr1901 commented May 26, 2021

I finally got around to compiling Cowgol. For starters, I was able to get 8086 codegen working from Linux using the following:

bin/cowfe-16bit.nncgen.exe -Irt/ -Irt/msdos/ examples/mandel.cow mandel.cob
bin/cowbe-8086.nncgen.exe mandel.cob mandel.coo
bin/cowlink-msdos.nncgen.exe .obj/rt/msdos/cowgol.coo mandel.coo -o mandel.s

This gets me some shiny 8086 assembler, just how I like it :). However, this isn't quite enough to actually generate a working binary. Commit 18fc49f hints that you still need an assembler. Which assembler do you intend to target? I tried nasm and got the following error:

william@xubuntu-dtrain:~/Projects/toolchains/cowgol$ nasm mandel.s
mandel.s:17: error: parser: instruction expected

I'm guessing the assembler has yet to be written :)?

@davidgiven
Copy link
Owner

It does indeed build with nasm --- see src/build.lua, buildnasm(). I know it works because it generates binaries for the compiler tests! Might it be complaining (unhelpfully) about the segmentation instructions? The test build uses nasm -f obj and then links the result with djlink, which was the only way I found of producing small mode exes.

@cr1901
Copy link
Author

cr1901 commented May 28, 2021

@davidgiven Yes, my mistake: nasm -f obj does indeed work. I could've sworn you could build with -f bin and still have access to segments, but in retrospect I guess that doesn't make much sense. I'll have a photo of mandel.exe running on a 286 to show you later. I guess the comment about needing an assembler is out of date?

Btw, while it's on my mind, how does the naming scheme of cowfe, cowbe, etc work between the periods? It looks like a target double (or triple), but I'm not certain the order, and why some compilers have a target double and others a target triple...

@davidgiven
Copy link
Owner

It needs an assembler for DOS. I can't find an open source one which supports segments and exes. (I have to target .exe in order to get small mode executables, where the code and data are in different segments. .com only works for tiny mode.) There is a nasm for dos but it's 386 or above only. Ideally I'd write my own but the 8086 instruction encoding is a nightmare...

Re the naming scheme: it's cowlink-<target>.<host>.exe, where <target> is the platform that it's compiling for (e.g. 8086 for the code generator or msdos for the linker) and <host> is the platform it's running on; nncgen is the generic C version, which produces huge executables. If you're on Linux, try the lx386 version instead. It should behave completely identically.

@cr1901
Copy link
Author

cr1901 commented May 28, 2021

Ideally I'd write my own but the 8086 instruction encoding is a nightmare...

Maybe it can be written in Cowgol :). Uhh, for prototyping any assembler/linker, I'd prob choose Rust or Zig. Then when that works, I can think about how to write it in Cowgol due to lack of recursion (and well, compiler algorithms love recursion).

@davidgiven
Copy link
Owner

There's already a simple assembler framework in Cowgol --- look in src/cowasm. Currently it supports the TLCS90, PDP-11, 8080, and 6303. Half the instruction set is pretty orthogonal and wouldn't be too bad to implement, but there are lots of short form instructions that would have to be special cased somehow...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants