#lang racket " i ← 1 while i < length(A) j ← i while j > 0 and A[j-1] > A[j] swap A[j] and A[j-1] j ← j - 1 end while i ← i + 1 end while " (define tc201sort '((start input 0) ;; read in numbers to sort. end with 0 ( skipzero 0) ( jump storeit) ;; add the input number to the list ( jump sort) (storeit storei next) ( load next) ;; next++ ( add one) ( store next) ( load count) ;; count++ ( add one) ( store count) ( jump start) ;; Note: i is set to zero at the start. can increment at start of loop (sort load i) ;; i = i+1 ( add one) ( store i) ( load count) ;; i < length[A} ( sub i) ( skippos 0) ( jump print) ( load i) ( store j) (inner skippos 0) ;; j > 0 ( jump sort) ( load begin) ;; temp = address(A[j]) ( add j) ( store temp) ( loadi temp) ( store tempAj) ;; tempAj = A[j] ( load temp) ;; temp = address(A[j-1]) ( sub one) ( store temp) ( loadi temp) ;; acc = A[j-1] ( store tempAj1) ;; tempAj1 = A[j-1] ( sub tempAj) ;; acc = A[j-1] - A[j] ( skippos 0) ( jump sort) ( load tempAj) ;; A[j-1] = A[j] ( storei temp) ( load temp) ( add one) ( store temp) ( load tempAj1) ( storei temp) ;; A[j] = A[j-1] ( load j) ;; j = j-1 ( sub one) ( store j) ( jump inner) (print load count) ;; print out the result ( skippos 0) ( halt 0) ( loadi begin) ( output 0) ( load count) ( sub one) ( store count) ;; count-- ( load begin) ( add one) ( store begin) ;; begin++ ( jump print) (count data 0) ;; the size of the list (one data 1) ;; constant 1 (i data 0) ;; i = 0 (j data 0) (temp data 0) (tempAj data 0) (tempAj1 data 0) (begin data astart) ;; the address of the start of the list (next data astart) ;; a pointer to the end of the list (astart data 0))) ;; the start of the list of numbers (define (doit) (simulate-lite+n 10000 (init-config (assemble tc201sort)))) (define simulate-lite+n (lambda (n config) (if (or (halted? config) (<= n 0)) (list config '*** (- 10000 n)) (simulate-lite+n (- n 1) (next-config config)))))