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


 

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章