程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 學 Win32 匯編[30] - 條件及循環偽指令: .IF、.WHILE、.REPEAT 等

學 Win32 匯編[30] - 條件及循環偽指令: .IF、.WHILE、.REPEAT 等

編輯:Delphi

 .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 

  .WHILE 與 .BREAK:

; 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 
   .while TRUE 
      PrintDec eax 
      dec eax 
   .break .if eax == 0 
   .endw   
   ret 
main endp 
end main 

  .REPEAT、.UNTIL: Repeat 循環偽指令:

; 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 
   .repeat 
      PrintDec eax 
      dec eax 
   .until eax == 0  
   ret 
main endp 
end main 

  .REPEAT 與 .BREAK:

; 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, 9 
   .repeat 
      PrintDec eax 
      dec eax 
   .break .if eax == 0 
   .until FALSE 
   ret 
main endp 
end main 


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved