ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

学 Win32 汇编[30] - 条件及循环伪指令: .IF、.WHILE、.REPEAT 等

2021-04-30 12:07:43  阅读:32  来源: 互联网

标签:main REPEAT lib 30 伪指令 eax includelib include inc


学 Win32 汇编[30] - 条件及循环伪指令: .IF、.WHILE、.REPEAT 等


.IF、.ELSEIF、.ELSE、.ENDIF: 条件伪指令

;可以使用和 C 语言类似的条判断:
a == b
a != b
a >  b
a >= b
a <  b
a <= b
a && b
a &  b
a || b
!a

;还可以直接判断几个常用的标志位:
CARRY?    ;进位标志
OVERFLOW? ;溢出标志
PARITY?   ;奇偶标志
SIGN?     ;符号标志
ZERO?     ;零标志

; Test30_1.asm
.386
.model flat, stdcall

include    windows.inc
include    kernel32.inc
include    masm32.inc
include    debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib

.code
main proc
    xor eax, eax
    .if !eax
        PrintText 'EAX = 0'
    .endif
    ;
    mov eax, 3
    .if eax == 3
        PrintText 'EAX = 3'
    .else
        PrintText 'EAX != 3'
    .endif
    ;
    mov eax, 4
    .if eax == 3
        PrintText 'EAX = 3'
    .elseif eax > 3
        PrintText 'EAX > 3'
    .else
        PrintText 'EAX < 3'
    .endif
    ret
main endp
end main


; Test30_2.asm
.386
.model flat, stdcall

include    windows.inc
include    kernel32.inc
include    masm32.inc
include    debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib

.code
main proc
    mov eax, 1
    mov edx, 0
    .if eax && edx
        PrintText '&&'
    .endif
    
    .if eax || edx
        PrintText '||' ;
    .endif
    
    .if eax & edx
        PrintText '&'
    .endif
    ret
main endp
end main

.WHILE、.ENDW: While 循环伪指令:

; Test30_4.asm
.386
.model flat, stdcall

include    windows.inc
include    kernel32.inc
include    masm32.inc
include    debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib

.code
main proc
    mov eax, 9
    .while eax > 0 
        PrintDec eax
        dec eax
    .endw    
    ret
main endp
end main

.REPEAT、.UNTIL: Repeat 循环伪指令:

; Test30_5.asm
.386
.model flat, stdcall

include    windows.inc
include    kernel32.inc
include    masm32.inc
include    debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib

.code
main proc
    mov eax, 9
    .repeat
        PrintDec eax
        dec eax
    .until eax == 0  
    ret
main endp
end main

.While 与 .Repeat 都支持 .Break 和 .Continue

.WHILE 与 .BREAK:

; Test30_6.asm
.386
.model flat, stdcall

include    windows.inc
include    kernel32.inc
include    masm32.inc
include    debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib

.code
main proc
    mov eax, 9
    .while TRUE
        PrintDec eax
        dec eax
    .break .if eax == 5
    .endw    
    ret
main endp
end main

.REPEAT 与 .CONTINUE:

; Test30_7.asm
.386
.model flat, stdcall

include    windows.inc
include    kernel32.inc
include    masm32.inc
include    debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib

.code
main proc
    mov eax, 0
    .repeat
        inc eax
    .continue .if eax == 2
        PrintDec eax
    .until eax > 3
    ret
main endp
end main

posted on 2010-04-21 17:26  万一  阅读(6424)  评论(0)  编辑  收藏

标签:main,REPEAT,lib,30,伪指令,eax,includelib,include,inc
来源: https://blog.51cto.com/u_14617575/2745487

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有