Assembly Count to Zero
16:44 02 Oct 2012

I am trying to teach myself Assembly (out of curiosity and interest of learning) and have developed some code that counts from five to 0. Thats all it does. I was wondering if the following code was efficient?

.386
.model flat, stdcall

.data
i dd 5

.code
main:
    MOV cx, 5
    lp:
    LOOP lp
    MOVZX eax, cx  
RET 
END main

Notice that I use the MOVZX instruction to copy the value of cx into eax (what my compiler uses to return). I do this because my program won't assemble if I simply use MOV. Is using MOVZX desireable? Or is there a more efficient way I should be doing this?

You will notice also in my code that I have i dd 5 my original plan was to MOV cx, i but my compiler refuses to assemble when I attempt that. (MOVSX yields the same result). So my second question is, how can I move the value of i into the cx register?

loops assembly mov