-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathArray_ItemAddress.asm
80 lines (66 loc) · 1.78 KB
/
Array_ItemAddress.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
;==============================================================================
;
; UASM64 Library
;
; https://github.com/mrfearless/UASM64-Library
;
;==============================================================================
.686
.MMX
.XMM
.x64
option casemap : none
IF @Platform EQ 1
option win64 : 11
ENDIF
option frame : auto
include UASM64.inc
.CODE
UASM64_ALIGN
;------------------------------------------------------------------------------
; Array_ItemAddress
;
; Get the address of an array item specified by the item index.
;
; Parameters:
;
; * pArray - pointer to the array.
;
; * nItemIndex - the index of the array item to return the address for.
;
; Returns:
;
; The address of the array item, or 0 if an error occurred.
;
; Notes:
;
; This function as based on the MASM32 Library function: arrget
;
; See Also:
;
; Array_ItemLength, Array_ItemSetData, Array_ItemSetText
;
;------------------------------------------------------------------------------
Array_ItemAddress PROC FRAME USES RCX RDX pArray:QWORD, nItemIndex:QWORD
.IF pArray == 0
mov rax, 0
ret
.ENDIF
mov rax, pArray ;[esp+4] ; write array adress to EAX
mov rcx, nItemIndex ;[esp+8] ; write required index to ECX
mov rdx, [rax] ; write member count to EDX
cmp rcx, 1
jl error1 ; lower bound error
cmp rcx, rdx
jg error2 ; upper bound error
mov rax, [rax+rcx*8] ; write array member address to EAX
ret ;8
error1:
mov rax, 0 ; -1 ; return -1 on lower bound error
ret ;8
error2:
mov rax, 0 ; -2 ; return -2 on upper bound error
ret ;8
ret
Array_ItemAddress ENDP
END