如何仅使用jmp和eflags在masm中创建for循环?

时间:2015-04-17 21:20:25

标签: assembly x86 masm

我尝试使用Google搜索关于jmp语句和eflags的所有内容,但无济于事。这是我开始工作的唯一方法,但我认为我错了。

.386         
.model flat,stdcall
.stack 4096

;includelib msvcrt   ;printf function

Sleep proto arg1:DWORD  ;Sleep proto stdcall arg1:DWORD 

printf proto c arg1:Ptr BYTE, printlist:vararg 
scanf  PROTO c arg2:Ptr BYTE, inputlist:vararg

.data 

num db 1,2,3,4,0

fmtmsg1 db "%d",0   


.code
public main

main proc  

    mov cl,0 ; for loop counter 

repeat_loop:

    ;preserve for loop counter 
    push ecx

    ;move the contents of the pointer into the accumulator 
    mov al,[num]

    ;print the contents of the accumulator
    invoke printf,addr fmtmsg1,al

    ;increment the address pointed to by num pointer
    inc num

    ;retrive the counter value 
    pop ecx

    ;and increment the value
    inc cl

    ;compare the counter to 4 sets the z flag to 0 if not equal to 4
    cmp cl,4

    ;repeat loop
    jne repeat_loop

    ;if jump not taken the program returns to the operating system
     ret
main endp

end main

0 个答案:

没有答案