Calculating delay from 3 nested loops

夙愿已清 提交于 2019-12-02 07:39:16

For starters, the longest loop would load 0 not FF to the counter, but let's stick with FF so we get the expected answer. With FF the loop runs 254 times and exits on the 255th.

The general formula is 1 for ldi, (n-1) * (body + 3) for the full iterations (1 for dec and 2 for brne) and (body + 2) for the final one (1 fordec and 1 for not taken brne). body means whatever is in the loop body, for the innermost loop that's 0 as it's empty.

Thus, for the innermost loop: 1 + 254 * (0 + 3) + (0 + 2) = 765. For the middle loop, the body is the 765 from the innermost loop, thus we have: 1 + 254 * (765 + 3) + (765 + 2) = 195840. For the outermost loop the body is the 195840 from the middle loop, thus we have: 1 + 254 * (195840 + 3) + (195840 + 2) = 49939965 which is the expected answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!