(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))
(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))))