Information Technology Reference
In-Depth Information
the CX register and branch if the result is not zero. The addressing mode used to
access the array List [BX
þ
1] is called based addressing mode.
MOV CX, 1000
; Counter ¼ CX 1000
MOV BX, Offset
LIST
;BX pointer to LIST
MOV SI, 0
; SI used as an index
MOV AX, VAL
; AX VAL
CALL SEARCH
; Test FLAG to check whether value found
.....
SEARCH PROC NEAR
; FLAG 0
MOV FLAG, 0
Next:
CMP AX, [BX þ SI] ;Compare current value to VAL
JE Found
;Branch if equal
ADD SI, 2
; SI SI þ 2, next value
LOOP Next
;Go to next value
JMP Not_Found
Found: MOV FLAG, 1 ;Indicate value found
MOV POSITION, SI ;Return index of value in List
Not_Found: RET
SEARCH ENDP
Example 5
This is the same as Example 4 but using the stack features of the X86.
PUSH DS
;See Table 3.9
MOV CX, 1000
;Counter ¼ CX 1000
MOV BX, OFFSET LIST
;Point to beginning of LIST
PUSH BX
PUSH VAL
;VAL is a word variable
CALL SEARCH
;Test FLAG to check whether value found
;If found get index from SI register
using
POP SI
.....
SEARCH PROC NEAR
POP TEMP
;Save IP
POP AX
;AX VAL. Value to search for
POP SI
;SI OFFSET LIST and let BX ¼ SI
Search WWH ::




Custom Search