字符串、数组、结构与宏的深入探索
1. 数组填充与随机数生成
在处理数组时,我们常常需要用随机数填充数组。以下是一个将数组填充为 32 位有符号整数的示例代码,这些整数的范围在 LowerRange 和 UpperRange - 1 之间:
; Fills an array with a random sequence of 32-bit signed
; integers between LowerRange and (UpperRange - 1).
; Returns: nothing
;-----------------------------------------------------------
mov
edi,pArray
; EDI points to the array
mov
ecx,Count
; loop counter
mov
edx,UpperRange
sub
edx,LowerRange
; EDX = absolute range (0..n)
cld
; clear direction flag
L1:
mov
eax,edx
; get absolute range
call
RandomRange
add
eax,LowerRange
; bias the result
stosd
; store EAX into [edi]
loop
L1
ret
FillArray ENDP
END
上述代码的执行流程如下:
1. mov edi, pArray :将
超级会员免费看
订阅专栏 解锁全文

1

被折叠的 条评论
为什么被折叠?



