From: plugd Date: Thu, 14 Nov 2019 13:03:39 +0000 (+0100) Subject: Drafted operand evaluation procedure. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=707bcb205c185815e2b94ab3fca5f769afb58264;p=jars.git Drafted operand evaluation procedure. --- diff --git a/mars.scm b/mars.scm index 2f4db9d..b1aa9db 100644 --- a/mars.scm +++ b/mars.scm @@ -67,8 +67,8 @@ (define (execute-instr ptr) (let* ((instr (vector-ref core ptr)) - (A-operand (eval-operand (instr-A-mode instr) (instr-A-num) ptr)) - (B-operand (eval-operand (instr-B-mode instr) (instr-B-num) ptr))) + (A-pointer (eval-operand (instr-A-mode instr) (instr-A-num) ptr)) + (B-pointer (eval-operand (instr-B-mode instr) (instr-B-num) ptr))) (case (instr-opcode instr) ((DAT)) ((MOV)) @@ -90,11 +90,27 @@ (define (eval-operand mode num ptr) (case mode - ((immediate)) - ((direct)) - ((indirect-A)) - ((indirect-B)) - ((pre-indirect-A)) - ((pre-indirect-B)) - ((post-indirect-A)) - ((post-indirect-B)))) + ((immediate) 0) + ((direct) num) + ((indirect-A) (+ num (instr-A-num (vector-ref core (+ ptr num))))) + ((indirect-B) (+ num (instr-B-num (vector-ref core (+ ptr num))))) + ((pre-indirect-A) + (let ((aux-instr (vector-ref core (+ ptr num)))) + (instr-set-A-num! aux-instr (- 1 (instr-A-num aux-instr))) + (+ num (instr-A-num aux-instr)))) + ((pre-indirect-B) + (let ((aux-instr (vector-ref core (+ ptr num)))) + (instr-set-B-num! aux-instr (- 1 (instr-B-num aux-instr))) + (+ num (instr-B-num aux-instr)))) + ((post-indirect-A) + (let* ((aux-instr (vector-ref core (+ ptr num))) + (old-A-num (instr-A-num aux-instr))) + (instr-set-A-num! aux-instr (+ 1 (instr-A-num aux-instr))) + (+ num old-A-num))) + ((post-indirect-B) + (let* ((aux-instr (vector-ref core (+ ptr num))) + (old-B-num (instr-B-num aux-instr))) + (instr-set-B-num! aux-instr (+ 1 (instr-B-num aux-instr))) + (+ num old-B-num))) + (else + (error "Unrecognized mode" mode))))