Another option is to run a 6502 assembler in FORTH hosted on a 6502.
If you're OK with a FORTHish syntax (to reuse the FORTH command line parsing) the assembler logic is straightforward.
Some 6502 implementations are
"typists assembler" in Tali FORTH,
& 6502 assembler in FIG FORTH.
Here is the console log of a 65816 example:
Code:
\ FORTHish assembler simple demo ok
ok
: UM*S ( u1 u2 -- ud ) \ start a subroutine (word) definition compiled
\ ud=u1*u2 simple multiply compiled
\ https://forth-standard.org/standard/core/UMTimes compiled
[ \ shift FORTH interpreter from compile to interpret state ok
0 ## lda, \ init product hi ok
2 d,x lsr, \ initial shift u1 ok
16 ## ldy, Begin, \ for each u1 bit ok
IfCs, ok
clc, 0 d,x adc, Then, ok
rora, 2 d,x ror, \ shift right product & u1 ok
dey, UntilEq, ok
0 d,x sta, \ store product hi, product lo already in place ok
] \ shift FORTH interpreter from interpret to compile state compiled
; \ end the subroutine (word) definition ok
ok
SeeLatest \ disassemble last word
04DB A90000 LDA #$0000 {' SInIndx0}
04DE 5602 LSR $02,x
04E0 A01000 LDY #$0010 {' SInIndx2}
04E3 9003 BCC $04E8 {UM*S+000D}
04E5 18 CLC
04E6 7500 ADC $00,x
04E8 6A RORA
04E9 7602 ROR $02,x
04EB 88 DEY
04EC D0F5 BNE $04E3 {UM*S+0008}
04EE 9500 STA $00,x
04F0 60 RTS
ok
ok
1234 23456 UM*S D. \ test the new subroutine 28944704 ok
ok
ok
: DUM/ModB ( uq_dividend ud_divisor -- ud_rem ud_quot ) \ unsigned divide 64/32=32,32 compiled
[ ok
8 d,x lda, LRefA @Word jsr, 8 d,x sta, ok
10 d,x lda, LRefA @Word jsr, 10 d,x sta, ok
inx, inx, inx, inx, ok
' 2Swap jmp, ok
ok
LDef @Word ok
asla, Tmp sta, \ save dividend word & get next bit ok
16 ## ldy, Begin, \ for each bit in word ok
6 d,x rol, 4 d,x rol, LRefR @8 bcs, \ rol dividend hi ok
6 d,x lda, 2 d,x cmp, 4 d,x lda, 0 d,x sbc, \ compare ok
IfCs, \ if ok
LDef @8 ok
6 d,x lda, 2 d,x sbc, 6 d,x sta, \ subtract ok
4 d,x lda, 0 d,x sbc, 4 d,x sta, ok
sec, Then, ok
Tmp rol, \ add bit to quotient word, get next dividend lo bit ok
dey, Untileq, ok
Tmp lda, \ return quotient word ok
] ; ok
ok
SeeLatest
04FC B508 LDA $08 {Tmp},x
04FE 201105 JSR $0511 {DUM/ModB+0015}
0501 9508 STA $08 {Tmp},x
0503 B50A LDA $0A {Tmp+0002},x
0505 201105 JSR $0511 {DUM/ModB+0015}
0508 950A STA $0A {Tmp+0002},x
050A E8 INX
050B E8 INX
050C E8 INX
050D E8 INX
050E 4CB08C JMP $8CB0 {2Swap}
0511 0A ASLA
0512 8508 STA $08 {Tmp}
0514 A01000 LDY #$0010 {' SInIndx2}
0517 3606 ROL $06,x
0519 3604 ROL $04,x
051B B00A BCS $0527 {DUM/ModB+002B}
051D B506 LDA $06,x
051F D502 CMP $02,x
0521 B504 LDA $04,x
0523 F500 SBC $00,x
0525 900D BCC $0534 {DUM/ModB+0038}
0527 B506 LDA $06,x
0529 F502 SBC $02,x
052B 9506 STA $06,x
052D B504 LDA $04,x
052F F500 SBC $00,x
0531 9504 STA $04,x
0533 38 SEC
0534 2608 ROL $08 {Tmp}
0536 88 DEY
0537 D0DE BNE $0517 {DUM/ModB+001B}
0539 A508 LDA $08 {Tmp}
053B 60 RTS
ok
ok
$9abcdef0. $12345678. $98765432. DUM/ModB D.Hex Space D.Hex 1E9131AB 91430F8A ok
ok