-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfreqdump.g
70 lines (61 loc) · 1.33 KB
/
freqdump.g
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
; output byte frequency of input file
; fasmg freqdump.g -i "FileName equ 'freqdump.g'"
;
; performance: bytes seconds
; 1,126,964 1.2
; 20,968,922 45.4
; 510,018,886 534.9
match =FileName,FileName
display 10,'usage: fasmg freqdump.g -i "FileName equ ''your_file''"',10
err 'missing FileName expected'
else
virtual at 0
source::
file FileName
end virtual
AreaFrequency source
; we can verify total equals length
total = 0
postpone
assert total = sizeof source
end postpone
; display array of values
repeat 256, i:0
repeat 1, N:source.i
display `N,','
total = total + N
dd N ; and store to output
end repeat
end repeat
end match
calminstruction AreaFrequency area*
local offset, var, val, i
compute offset, 0
; set all byte frequency counts to zero
compute i, 256
clear:
compute i, i - 1
arrange var, area.i
publish var, offset
check i
jyes clear
; increment frequency counts for each byte
jump zero
more:
load val, area:offset, 1
compute val, 0+val ; convert string to number
arrange var, area.val
compute val, var + 1
publish var, val
compute offset, offset + 1
zero:
check offset < sizeof area
jyes more
end calminstruction
; text AreaContent Some_Area
; display text
calminstruction (target) AreaContent area*
local string
load string, area: 0, sizeof area
publish target, string
end calminstruction