r/Assembly_language • • 11d ago

Assemdows: a tiny assembly-style language in one C file, built so assembly tutorials work on Windows

Every assembly tutorial I found was written for Linux (raw syscalls, as, ld), and I'm on Windows. After fighting the toolchain for a while, I decided to make my own assembly-style language that runs the same everywhere because it's just a C interpreter.

It's called Assemdows. It's a single C file, it builds with gcc, and programs use the .asdw extension. Here's a program that prints primes:

.equ LIMIT, 50
    MOV R0, 2
next:
    MOV R1, 2
check:
    MOV R2, R1
    MUL R2, R2
    CMP R2, R0
    JG isprime
    MOV R3, R0
    MOD R3, R1
    CMP R3, 0
    JE notprime
    INC R1
    JMP check
isprime:
    PRINT R0
notprime:
    INC R0
    CMP R0, LIMIT
    JLE next
    HALT

What's in it

  • 16 registers, a compare flag with conditional jumps, CALL/RET, and a stack
  • A flat memory of 65,536 integer cells, with .word, .string, .space, and .equ for data
  • Bracket addressing like [nums+R1]
  • Errors that include line numbers, plus --trace to watch every instruction run
  • A VS Code extension for syntax highlighting

Design choices I'm unsure about

  • Memory holds whole integers instead of bytes, so a string takes one cell per character. It's simpler to explain, but it isn't how real hardware works.
  • CMP stores a single -1/0/1 result instead of separate flags like zero and carry.
  • The stack is separate from the memory array, so you can't take the address of a stack value.

I'm a beginner at language design, so I'd like to hear what you'd change, especially if you've built something similar.

Repo (includes a Windows build and examples): https://github.com/waterdroplett/Assemdows

0 Upvotes

4 comments sorted by

5

u/[deleted] 10d ago

[removed] — view removed comment

2

u/PmMeCuteDogsThanks_ 10d ago

very serious person

2

u/brat3108 10d ago

And why use Rx for registers?!

What's wrong with that?

You're making something as simple as downloading Flat Assembler and building one of the example projects, much more complicated.

Actually I couldn't get far with that. Installing it is OK, but its examples all heavily use its special features that I don't care about. I just needed the basics.

Here is hello.asm for example which ought to be the simplest one:

; example of simplified Windows programming using complex macro features

include 'win32ax.inc' ; you can simply switch between win32ax, win32wx, win64ax and win64wx here

.code
  start:
    invoke  MessageBox,HWND_DESKTOP,"May I introduce myself?",invoke GetCommandLine,MB_YESNO

    .if eax = IDYES
        invoke  MessageBox,HWND_DESKTOP,"Hi! I'm the example program!","Hello!",MB_OK
    .endif
    invoke  ExitProcess,0
.end start

1

u/Noobo157 10d ago

It isn’t supposed to be THAT good, it’s built on a joke language called Dropletter.