I want to convert simple loops in high-level languages into assembly language (for emu8086) say, I have this code:
for(int x = 0; x<=3; x++)
{
//Do something!
}
or
int x=1;
do{
//Do something!
}
while(x==1)
or
while(x==1){
//Do something
}
How do I do this in emu8086?
For-loops:
For-loop in C:
The same loop in 8086 assembler:
That is the loop if you need to access your index (cx). If you just wanna to something 0-3=4 times but you do not need the index, this would be easier:
If you just want to perform a very simple instruction a constant amount of times, you could also use an assembler-directive which will just hardcore that instruction
Do-while-loops
Do-while-loop in C:
The same loop in assembler:
While-loops
While-loop in C:
The same loop in assembler:
For the for-loops you should take the cx-register because it is pretty much standard. For the other loop conditions you can take a register of your liking. Of course replace the no-operation instruction with all the instructions you wanna perform in the loop.