X86汇编实例(使用Irvine32库) - 之二

问题:

Using the ArrayScan program in Section 6.3.4.2 as a model,
implement the search using the LOOPZ instruction.

程序:

TITLE Scanning an Array                            (ArryScan.asm)

; Scan an array for the first nonzero value.
; Last update: 06/01/2006

INCLUDE Irvine32.inc
.data
intArray SWORD    0,0,0,0,1,20,35,-12,66,4,0
;intArray SWORD    2,0,0,0
;intArray SWORD    0,0,0,0
;intArray SWORD    0,0,0,3
noneMsg    BYTE "A non-zero value was not found",0

.code
main PROC
  mov     ebx,OFFSET intArray    ; point to the array
  mov     ecx,LENGTHOF intArray    ; loop counter
  sub     ebx,2            ; move forward one element

L1:
  add     ebx,2
  cmp     WORD PTR [ebx],0    ; compare value to zero
  loopz    L1    ; continue the loop
  cmp     WORD PTR [ebx],0
  jnz     found
  jmp     notFound    ; none found

found:
  movsx eax,WORD PTR [ebx]    ; otherwise, display it
  call    WriteInt
  jmp     quit

notFound:
  mov     edx,OFFSET noneMsg    ; display "not found" message
  call    WriteString

quit:
  call    crlf
  exit
main ENDP
END main


 

Freelancer.com - 排名第一的软件兼职工作网站
兼职编程、开发, C/C++/C#, PHP, Web开发, ASP, 外包项目, 接国外私活, 程序员兼职, 外包开发, 国外项目外包, 网站外包项目
 

你可能感兴趣的:(职场,休闲,x86汇编)