Program to calculate the factorial of a number read in by using a loop. (The previous example for this problem was solved in class by using a procedure invoking itself recursively.) Pascal equivalent (well almost) --------------------- begin readln(n); i := 1; fact := 1; while i < (n+1) do begin fact := (fact * i); i := (i + 1); end; writeln(fact); end --------------------- 1 in ax 2 copy n, ax 3 copy ax, #c1 4 copy i, ax 5 copy fact, ax 6 #l0 copy ax, n 7 add ax, #c1 8 copy _e0, ax 9 copy ax, i 10 cmp ax, _e0 11 jnb #l1 12 copy ax, fact 13 mult ax, i 14 copy fact, ax 15 copy ax, i 16 add ax, #c1 17 copy i, ax 18 jmp #l0 19 #l1 copy ax, fact 20 out ax 21 halt 40 n 0 41 i 0 42 #c1 1 43 fact 0 44 _e0 0 note: #l0 6 #l1 19 --------------------- Trace for an input value of 3 # AX CF FACT I _E0 N 1 3 Note: input = 3 2 3 3 1 4 1 5 1 6 3 7 4 8 4 9 1 10 B 11 12 1 13 1 14 1 15 1 16 2 17 2 18 6 3 7 4 8 4 9 2 10 B 11 12 1 13 2 14 2 15 2 16 3 17 3 18 6 3 7 4 8 4 9 3 10 B 11 12 2 13 6 14 6 15 3 16 4 17 4 18 6 3 7 4 8 4 9 4 10 NB 11 19 6 20 Note: output = 6 21