20 likes | 104 Views
Original situation. Memory:{ n,i } n(VA1376) is used to store the “n” in test1 and test2 i (VA300) is used to store the code{+1,-1} Register:{R,A1,A2,B1,B2} Test1 and Test2 don’t share registers Therefore the result of test1 and test2 will be: Print integer:9
E N D
Original situation • Memory:{n,i} • n(VA1376) is used to store the “n” in test1 and test2 • i(VA300) is used to store the code{+1,-1} • Register:{R,A1,A2,B1,B2} • Test1 and Test2 don’t share registers • Therefore the result of test1 and test2 will be: • Print integer:9 • n=9, i=-1 A1 load n=9, B1 load i=-1 R=A1+B1=8n=8, i=-1 • … • n=7, i=-1 A1 load n=7, B1 load i=-1switch to test2n=20, i=1 • Note that B1 hasn’t been freed • Print integer:20 • n=20,i=1 A2 load n=20, B2 load i=1 R=A2+B2=21n=21, i=1 • … • n=23,i=1 A2 load n=23, B2 load i=1 R=A2+B2=23n=24, i=1 • Print integer:24 • switch to test1 R=A1+B1=6n=6, i=1 • this step is still correct because memory with wrong value hasn’t beet read • Print integer:6 • n=6,i=1 A1 load n=6, B1 load i=1 R=A1+B1=7n=7, i=1 • Print integer:7 • …
After we fix the memory mapping • Memory:{n1,i1,n2,i2} • Register:{R,A1,A2,B1,B2} • Test1 and Test2 don’t share registers • Therefore the result of test1 and test2 will be: • Print integer:9 • n1=9, i1=-1 A1 load n1=9, B1 load i=-1 R=A1+B1=8n1=8, i1=-1 • … • n1=7, i1=-1 A1 load n1=7, B1 load i1=-1switch to test2n2=20, i2=1 • Note that B1 hasn’t been freed • Print integer:20 • n2=20,i2=1 A2 load n2=20, B2 load i=1 R=A2+B2=21n2=21, i2=1 • … • n=23,i=1 A2 load n=23, B2 load i=1 R=A2+B2=23n2=24, i2=1 • Print integer:24 • switch to test1 R=A1+B1=6n1=6, i1=-1 • Print integer:6 • n1=6,i1=-1 A1 load n1=6, B1 load i1=-1 R=A1+B1=5n1=5, i1=-1(leave for loop) • …