Brass Core Plugins


Evaluates a snippet of code contained in a string.




The expression can contain expressions and assembly source code (including directives). The macro preprocessor is run as normal on source code in the string.


Two's complement 16-bit negation for the Z80.

; A function to negate 16-bit register pairs on
; the Z80 (which can only negate 8-bit registers
; natively).
.macro neg_16(register)
    ; Convert the passed register to a string.
    registerstr = strtoken(register)

    ; Preserve A and F:
    push af

    ; Get the most and least significant;
    ; registers from the register pair:
    hi = strsub(registerstr, 0, 1)
    lo = strsub(registerstr, 1, 1)

    ; We can only perform one's complement
    ; on A, so we need to copy the register
    ; to complement to and from A.
    cpl = "ld a,{0} \\ cpl \\ ld {0},a"

    ; Complement both registers:
    eval(strformat(cpl, hi))
    eval(strformat(cpl, lo))

    ; Restore A and F:
    pop af

    ; Increment the 16-bit pair by one to
    ; complete the two's complement operation.
    eval("inc " + hi + lo)


; Negate HL: