;;;; test (use sixtyfive-oh-two srfi-4 lolevel utils miscmacros) ;; Fast Multiply by 10 ;; By Leo Nechaev (leo@ogpi.orsk.ru), 28 October 2000. ; * = $1000 ; LDA #18 ; JSR MULT10 ; L1: ; JMP L1 ; MULT10: ; ASL A ;multiply by 2 ; STA TEMP ;temp store in TEMP ; ASL A ;again multiply by 2 (*4) ; ASL A ;again multiply by 2 (*8) ; CLC ; ADC TEMP ;as result, A = x*8 + x*2 ; RTS (define mult10 '#${a9 12 20 08 10 4c 05 10 0a 8d 00 20 0a 0a 18 6d 00 20 60}) (define p (make-processor)) (move-memory! mult10 (processor-memory p) (blob-size mult10) 0 #x1000) (define regs (processor-registers p)) (u8vector-set! regs 5 #x00) ; PC = #x1000 (u8vector-set! regs 6 #x10) (execute! p cycles: 100) (pp regs) (assert (= 180 (u8vector-ref regs 0))) ;;--- (let ((result (with-input-from-string ": sum ( n - ) 0 swap 0 do i + loop ;\n10000 sum . cr\n" (lambda () (with-output-to-string (lambda () ;; truly horrible (ignore-errors (compile-file "forth.scm")))))))) (pp result) (assert (string=? result "\nfig-FORTH 1.1\nOK\n-8968 \nOK\n")))