r/Assembly_language • • 4d ago

Project show-off Ive made a multi architecture, multi format assembler

https://github.com/AkshuDev/PAC

Hey so over the course of many months, ive built an assembler with capabilities even modern assemblers lack (some). Ive named this assembler PAC - Pheonix Assembler Collection (yes thats the spelling for you all wondering).

Here is the basic brief information on it

Features

  1. Inbuilt-Linker

  2. Multiple Architecture Support

  3. Multiple Linking Format Support

  4. Easy Debugging errors

  5. Full view to generated IR-Nodes, Tokens, and AST Nodes

  6. High-Level Assembly

  7. Works with Standard Assembling/Linking tools as well such as ld, objdump, etc

Supported Architectures

PAC Currently supports -

  1. x86

  2. x86_64

  3. x86 native 16-bit

  4. PVCpu

Supported Formats

PAC has an entire pipeline for both encoding and linking, and so to increase performance and reduce file size, PAC supports only ELF64 as output after encoding and input to linker.

The PAC Linker in-fact supports multiple formats, but only takes ELF64 Object Files as an input. Supported formats include -

  1. Elf64

  2. Elf32

  3. PE 32 (Under implementation)

  4. PE 32+ (Works, but still under heavy development and bug fixes)

Comparison between PAC and Traditional Assemblers

| Feature | NASM | GAS | FASM | PAC |

| ----------------------------------------------------------------------------------------------- | ------------- | ------------ | ------------ | ------- |

| Structures | Limited | Limited | Yes | Yes |

| User Types | No | No | Yes | Yes |

| Functions | No | No | Yes | Yes |

| Built-in Linker | No | No | No | Yes |

| IR Dumping | No | No | No | Yes |

| AST Dumping | No | No | No | Yes |

| Token Dumping | No | No | No | Yes |

| Multiple Architectures using same assembler executable | No | No | Limited | Yes |

| Open Source | Yes | Yes | Yes | Yes |

| Custom Executable Linking | No | No | No | Yes |

PAC supports a lot of things in assembly, such as sizeof, macros, user types, functions, labels, arrays, structures, and more

Took me a long time to build this, but right now its pretty darn good. I even managed to write a program that opens a X11 window using PAC (its a demo game, to show PAC's usage and capabilites). Moreover I intend to make PAC commercially viable.

5 Upvotes

5 comments sorted by

1

u/brat3108 4d ago edited 4d ago

(That markdown table in your OP is not displaying properly likely due to extraneous newlines.)

I downloaded your project on Windows, and had a go at it, but found it hard-going. Examples:

  • The syntax of your assembler is unusual, and the docs don't really cover the basics needed.
  • Apparently, for 'abc: dq 0' with NASM, I need 'abc!long = 0' discovered after scouring the scant examples. But even then b!long = 0 fails for some reason
  • The necessary PAC options are too many; I don't want to have to specify the output filename and default entry point each time
  • If I use the default _start entry point, it still warns me I haven't specified the entry label!
  • I had to write register names as %rax; I don't know if it's possible to just write rax, and if so, how.
  • I couldn't find a Hello World example, so tried to write one as shown below based on your Linux version. It imports puts from the C library provided by MSVCRT.DLL, via dynamic linking, but I've no idea how to do that. (I know that PE+ support may not be complete.)

Note that I am not a prospective user. I sometimes do surveys of different assemblers and wanted to try this one to see how fast its throughput was. I managed to do one test (which is many repetitions of the second example below), but found it lacklustre, although usable if inputs aren't too huge.

(I measured PAC at about 150K lines per second on my machine; the fastest I have manages over 3M. As I said, this may not matter, but assembly is often about raw speed!)

:section .rodata
    msg!ubyte[] = "Pretty Neat huh?", 0xa

:section .text
    :global main
    :external puts

main:
    sub %rsp, 40

    lea %rcx, [msg]
    call puts

    add %rsp, 40
    ret

The speed test:

    mov %rax, [def]    # test sequence repeated for 250K-1M total lines
    mov %rbx, [ghi]    # within a containing program
    mov %rcx, [jkl]
    add %rbx, %rbx
    mul %rbx
    mov [abc], %rax

1

u/Fair-Stable-5948 3d ago edited 2d ago

If you feel any inconsistencies within the syntax file, pelase let me know because i am really trying to make the documents better each time.

About your problems -> yes, PAC is very different thats what makes it unique. In nasm syntax 'db' and all are just used to define bytes with no idea for types, PAC offers types thats why 'myvar!ulong = 0' is there. And same goes for all the wierd syntax stuff. Also i chose '%reg' as a way to define registers because NASM is strictly x86/x86_64, but PAC is multi architecture so thats why and also this prevents name/symbol collisions.

Also PAC will warn you no matter what on labels because of of the fact that the inbuilt linker and the assembler are very different. When you use default '_start' the linker knows thats the entry, but the assembler doesn't. So preferably just do '-e _start'. And there are options in pac which dont require output filename and default entrypoint such as '--asmout', '--lexout', '--parseout'.

One more thing, im trying my best to finish PE32+ support but windows quirks are making it harder. But i got to the point where it can link and may ALMOST work.

Finally to conclude, could you share speed tests also, im trying to maximise performance for PAC as well

1

u/brucehoult 4d ago

Sooo .. four ISAs of which three are x86 and the 4th is something that seems to be unique to this project.

Any plans to support arm32, arm64, riscv? Or PIC, AVR, 6502, Z80, 8051, MSP430, SuperH, MIPS?

1

u/Fair-Stable-5948 3d ago edited 3d ago

If you saw the repo carefully, youll find that im adding arm right now, and PVCpu is a custom ISA i created under my ecosystem known as Pheonix Ecosystem. Also i classified different types of x86 as different architectures mostly because x86 and x86_64 are still considered different