From 76cd607babbdff874eaa632d543a188716c83f2b Mon Sep 17 00:00:00 2001 From: John Lorentzson Date: Thu, 3 Jul 2025 20:12:59 +0200 Subject: [PATCH] Add COMPILE-IR method for IR-MINUS --- .../user-side-compiler/backend/code-generator.lisp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/wip-duuqnd/user-side-compiler/backend/code-generator.lisp b/wip-duuqnd/user-side-compiler/backend/code-generator.lisp index 99764b6..4f7eaf5 100644 --- a/wip-duuqnd/user-side-compiler/backend/code-generator.lisp +++ b/wip-duuqnd/user-side-compiler/backend/code-generator.lisp @@ -92,6 +92,7 @@ (define-normal-emitter emit-lda #xa9 #xa5 #xad) (define-normal-emitter emit-sta (error "STA has no immediate mode.") #x85 #x8d) (define-normal-emitter emit-adc #x69 #x65 #x6d) +(define-normal-emitter emit-sbc #xe9 #xe5 #xed) (define-normal-emitter emit-cmp #xc9 #xc5 #xcd) (defun emit-store-data (data) @@ -163,6 +164,17 @@ (emit-adc :address (data-reference (second (inputs inst))))) (emit-store-data (output inst))) +(defmethod compile-ir ((inst ir-minus)) + (unless (= (length (inputs inst)) 2) + (error "During the final code generation step, IR-MINUS must have exactly 2 operands.")) + (emit-load-data (first (inputs inst))) + (emit-asm-instruction :opcode #x38 :byte-length 1) ; Set Carry + (if (eql (strategy (allocation-details (second (inputs inst)))) + :constant) + (emit-sbc :immediate (ir-constant-value (second (inputs inst)))) + (emit-sbc :address (data-reference (second (inputs inst))))) + (emit-store-data (output inst))) + (defmethod compile-ir ((inst ir-assign)) (emit-load-data (input inst)) (emit-store-data (output inst)))