How to create nested loops in x86 assembly language

a 夏天 提交于 2019-11-28 14:38:41

Sure, it's possible. Since every computer program eventually boils down to assembly - it is naturally the most powerful language possible (excluding direct bit manipulation).

The actual code depends on your system, compiler and applied optimizations, but basically it should be something like this (example for 2 nested loops, not 3):

           mov ecx, 0

outerLoop:

           cmp ecx, 10
           je done
           mov ebx, 0

innerLoop:
           mov eax, ecx        ; do your thing here
           add eax, ebx

           cmp ebx, 10
           je innerLoopDone
           inc ebx
           jmp innerLoop

innerLoopDone:

           inc ecx
           jmp outerLoop
done:

Note, you don't need local variables, you've got general-purpose registers for the usage that you need. If you insist on having variables, you can use memory addresses for that and read/write using register pointers.

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