-
Notifications
You must be signed in to change notification settings - Fork 0
/
lfsr.asm
98 lines (77 loc) · 1.83 KB
/
lfsr.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
%macro _output 2 ;%1=format, %2=value
push %2
push %1
call printf
add esp, 8
%endmacro
section .text
global main, shift_lfsr
extern printf
LFSR_SEED equ 01h ;define semente
main:
xor eax, eax ;eax = 0
xor ebx, ebx ;ebx = 0
mov eax, LFSR_SEED ;eax = LFSR_SEED
mov edx, 0
loop:
call shift_lfsr
mov ebx, eax
shr ebx, 20
add dword [counter + ebx*4], 1
; push eax ; insere elementos na pilha
; push edx
; _output format_num, eax ; imprime número
; pop edx
; pop eax ; remove elementos da pilha eax
inc edx
cmp edx, 0FFFFFFh ; compara com fim
jne loop ; continua loop
jmp results ;
; eax = lsfr
; retorna = eax = lsfr
shift_lfsr:
enter 4,0
pusha
pushf
mov ecx, eax ; ecx = eax
mov ebx, ecx ; ebx = ecx
shr ebx, 1 ; (ebx = lfsr >> 2) # 22
xor eax, ebx ; (0 ^ 1)
mov ebx, ecx ; ebx = lfsr
shr ebx, 2 ; (ebx = lfsr >> 2) # 21
xor eax, ebx ; (0 ^ 1 ^ 2)
mov ebx, ecx ; ebx = lfsr
shr ebx, 7 ; (ebx = lfsr >> 7) # 17
xor eax, ebx ; (0 ^ 1 ^ 2 ^ 7)
and eax, 1 ; eax = bit
shl eax, 23 ; bit << 23
shr ecx, 1 ; lfsr >> 1
or ecx, eax ; bit | lfsr
mov eax, ecx ; ret = eax = ecx
and eax, 0x00FFFFFF ; 24-bit
mov [ebp-4], eax
end:
popf
popa
mov eax, [ebp-4]
leave
ret
results:
mov eax, 0
print_results:
mov ebx, [counter + eax*4]
push eax
_output text1, ebx
pop eax
inc eax
cmp eax, 16
jne print_results
mov eax, 1 ; SYS_exit
mov ebx, 0 ; 0=OK , parametro de SYS_EXIT
int 0x80 ; chamada do kernel
section .data
format_hex: db "0x%08x", 10, 0 ;
format_num: db "%d", 10, 0 ;
text1: db "Frequencia Observada: %d", 10, 0
SECTION .bss
counter resd 16;