machine assembly address C++ 34010002 # ori $1, $0, 2 # mem 00 ( 0) # sum = 2 34020001 # ori $2, $0, 1 # mem 04 ( 4) # y = 1 34030001 # ori $3, $0, 1 # mem 08 ( 8) # z = 1 34040000 # ori $4, $0, 0 # mem 0C (12) # n = 0 00002800 # add $5, $0, $0 # mem 10 (16) # i = 0 90060040 # lw $6, x # mem 14 (20) # loop limit = 10 10a60007 # top: beq $5, $6, done # mem 18 (24) # if (i=10) end loop 00432000 # add $4, $2, $3 # mem 1c (28) # n = y + z 00240800 # add $1, $1, $4 # mem 20 (32) # sum = sum + n 00601000 # add $2, $3, $0 # mem 24 (36) # y = z 00801800 # add $3, $4, $0 # mem 28 (40) # z = n 34070001 # ori $7, $0, 1 # mem 2c (44) # (for the next line) 00a72800 # add $5, $5, $7 # mem 30 (48) # i++ 1000fff8 # beq $0, $0, top # mem 34 (52) # repeat for loop b0010044 # done: sw $1, sum # mem 38 (56) # none fc000000 # exit # mem 3c (60) # none 0000000a # x: .word 10 # mem 40 (64) # none 00000000 # sum: .word # mem 44 (68) # none Here's the equivalent C++ program: void main() { int sum = 2; // to store the sum of Fibonacci numbers int y = 1; // to store the previous Fibonacci number int z = 1; // to store the current Fibonacci number int n = 0; // to store the next Fibonacci number for (int i=0; i<10; i++) { n = y + z; // calculate next Fibonacci number sum = sum + n; // add new Fibonacci number to sum y = z; // set previous number to current number z = n; // set current number to next number } }