0
点赞
收藏
分享

微信扫一扫

汇编.if 和.endif的应用

;***********************************************

 TITLE .IF和.ELSEIF

 ;***********************************************




 ;***********************************************

 ;程序运行平台

 .386

 .MODEL FLAT,STDCALL

 OPTION CASEMAP:NONE

 ;***********************************************



 ;***********************************************

 ;文件包含

 INCLUDE Irvine32.inc

 ;***********************************************


 ;***********************************************

 .DATA

 result byte ?

 str1 byte "测试成功",0dh,0ah,0

 str2 byte "测试失败",0dh,0ah,0

 testByte byte 234

 ;***********************************************


 ;***********************************************

 ;代码段

 .CODE

 main proc

   .if testByte>200

      mov result,1

   .else

      mov result,0

   .endif

   .if result>0

      mov edx,offset str1

      call WriteString

   .else

      mov edx,offset str2

      call WriteString

   .endif

   exit

 main endp

 end main
;***********************************************

;***********************************************************
 TITLE 查找数组中一共有多少个0
 ;***********************************************************

 ;***********************************************************
 ;程序运行平台说明
 .386
 .MODEL FLAT,STDCALL
 OPTION CASEMAP:NONE
 ;***********************************************************

 ;***********************************************************
 ;文件包含
 INCLUDE Irvine32.inc
 ;***********************************************************

 ;***********************************************************
 ;数据段定义
 .DATA
 testArray byte 1,1,4.2,89,0,23,89,56,0,45,0,12
 arrayLength=$-testArray
 strSucess byte "the number of Zero is ",0
 ;***********************************************************

 ;***********************************************************
 ;代码段定义
 .CODE
 ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ;函数说明:寻找全局数组中0的个数
 ;函数参数:ecx 
 ;返回值  :无
 getZeroCount proc uses esi eax
    mov esi,arrayLength;
    dec esi
    xor eax,eax
    .while esi!=0
      .if testArray[esi]==0
          inc eax
      .endif
      dec esi;     
    .endw
    push eax
    mov edx,offset strSucess
    call WriteString
    pop eax
    call WriteInt
    ret;
 getZeroCount endp
 ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 main proc
    call getZeroCount
    exit
 main endp
 end main
 ;***********************************************************

;*********************************************
 TITLE 数组求和
 ;*********************************************


 ;*********************************************
 ;程序运行平台说明
 .386
 .MODEL FLAT,STDCALL
 OPTION CASEMAP:NONE
 ;*********************************************

 ;*********************************************
 ;文件包含
 INCLUDE Irvine32.inc
 ;*********************************************


 ;*********************************************
 ;数据段定义
 .DATA
 arrayW DWORD 10,60,20,33,72,89,45,65,72,18
 sample DWORD 50
 ArraySize DWORD sizeof arrayW/type DWORD
 sum DWORD  0
 strSuc BYTE "the sum is",0
 ;*********************************************


 ;*********************************************
 ;代码段定义
 .CODE
 main proc
    mov ecx,ArraySize      
    dec ecx
    mov eax,ecx
    shl eax,2
    .while ecx>0
       mov ebx,arrayW[eax]
       .if ebx>sample
           mov ebx,arrayW[eax]
           add sum,ebx
       .endif
       dec ecx
       mov eax,ecx
       shl eax,2
    .endw
    mov edx,offset strSuc
    call WriteString  
    xor eax,eax 
    mov eax,sum
    call WriteInt
    exit
 main endp
 end main
 ;*********************************************

举报

相关推荐

0 条评论