Now in the study of the Assembly, it feels very interesting. , I will write down the learning things, as a later can learn notes ~
The loop instruction is in the form of a loop designator, which takes two steps when the CPU executes the Loop command
1: (CX) = (CX)-1
2: Determine the value in CX, not zero to go to the label to execute, if zero, then execute down
From the description above, we can see the results of the execution of the impact loop instruction in CX, usually we use loop instruction to realize the loop function, the number of cycles stored in CX
Programming calculation 2^2, results stored in AX
Assembly code implementation, very simple
Assume Cs:code
Code segment
MOV ax,2
The. Ax, ax
MOV ax,4c00h
int 21h
Code ends
End
This implementation is simple, but if the power of a number of requirements is very large, it can not be so, just like in C language for the loop, with a loop to control the assembly language in the loop accumulation
Programming Computing 2^12
The code is as follows:
Assume Cs:code
Code segment
MOV ax,2
MOV cx,11
S:add Ax,ax
Loop s
MOV ax,4c00h
int 21h
Code ends
End
Analysis:
1: Marking, in assembly language, the label represents an address, this address has an instruction: add Ax,ax
In the above process, we can summarize the three key points to realize the loop function with CX and loop instructions.
(1) Number of cycles stored in CX
(2) The address identified by the label in the loop instruction should be in front
(3) The program segment to be executed is written in the middle of the label and loop instruction
The program framework for implementing the loop function with CX and loop directives is as follows
MOV cx, number of cycles
S
Loop-Executed program segments
Loop s
Okay, loop's fine.