-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.asm
62 lines (50 loc) · 1.24 KB
/
generator.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
option casemap:none
null equ 0;
.data
minimalValue qword ?
maximalValue qword ?
_length byte ?
.code
externdef rand:proc ; rand c function
externdef srand:proc ; srand c function
externdef time:proc ; time from ctime
public Generate
Generate proc
mov qword ptr _length, rcx
sub rsp, 40 ; required by ABI
mov rcx, null ; we put function parameter to rcx.
call time
call srand
call rand
; calculating minimal number
push rax ; we want to save result
mov rax, 10 ; to calculate minimal number we shall multiply 10 (length-1) times
mov rbx, qword ptr _length
sub rbx, 2 ; rbx now length-1
mov rcx, 0 ; rcx is counter, like i in for cycle
mov r8, 10 ; we can`t use mul with numbers, so we put number to register
startLoop:
cmp rcx, rbx
je endLoop
inc rcx
mul r8
jmp startLoop
endLoop:
; loop end
mov minimalValue, rax
;calculating maximal number
mov rbx, 10
mul rbx ; now rax is minimalValue * 10
dec rax ; now we got maximalValue!
mov maximalValue, rax
pop rax ; restored result
mov rdx, 0
div maximalValue ; we divided rdx:rax by maximalValue, now remainder of the division
; is in rdx, this value can`t be greater than maximalValue.
; result
mov rax, rdx
add rax, minimalValue
add rsp, 40
ret
Generate endp
end