© Thomas Kunz 2000
SCE 574
93
Assembler Example:
CX as a loop counter
äWe can take advantage of CX as a loop counter to speed up the program
ä MOV AX, InitialValue
ä MOV BX, OFFSET ArrayX
ä MOV CX, ArraySize
ä JCXZ DONE
äInitLoop: MOV [BX],AX
ä ADD BX,2
ä LOOP InitLoop
ä ...
äDONE:
äOnly CX can be used as a loop counter
äCompilers (good compilers) generate code to take advantage of special instructions that help reduce execution time
Will count down
instead of up!
Jump only if CX=0
Same as
DEC CX
JNZ InitLoop