Question

OK, I'm stumped. TAOCP vol1, 3rd edition, section 1.3.2 "The MIX Assembly language" gives a simple assembly program for finding the maximum of an array. The program is given on page 145 together with the number of times each instruction is supposedly executed. On the next page it says "[...] the length of time to perform the subroutine; it is (5+5n+3A)u [...]"

BUT: When you actually sum the counts given in the listing, you end up with the factor of (4+4n+2A). Such discrepancies occur also in other algorithms. For example, in the analysis of Program A in section 1.3.3 Knuth writes "by simple addition [..] (7+5A+...)". When you actually perform the "simple addition", you end up with (5+3A+...)

What is going on here?


here's the MIX code with counts from the text in brackets by side. I have shortened label-names to two characters for ease of typing

    X EQU 1000
      ORIG 3000
MA    STJ EX      [1]
IN    ENT3 0,1    [1]
      JMP CH      [1]
LO    CMPA X,3    [n-1]
      JGE *+3     [n-1]
CH    ENT2 0,3    [A+1]
      LDA X,3     [A+1]
      DEC3 1      [n]
      J3P LO      [n]
EX    JMP *       [1]
Was it helpful?

Solution

OK, I figured this one out. The "u" after the factor in parentheses tipped me off: some instructions take longer to execute than others. When this is taken into consideration (there's a table with instruction timings in the book), everything checks out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top