NASM Forum > Example Code
byte count
greco558:
Hi All,
Just another program I wrote to help me understand how to program in Linux
assembly.
Any feedback is welcome I am still learning how to do assembly.
This program counts the number of times bytes 00-FF show up in a file, text or binary.
It uses sys_brk to allocate memory then the program reads file data to allocated memory.
We scan the bytes in allocated memory and count the number of times bytes 00-FF are in file then display info to screen.
Make terminal full screen because i use columns to display info.
usage on Linux command line: ./bytect filename
Best Regards
John
Frank Kotler:
Nice! Thanks, John!
I am distressed to see that I'm apparently the only downloader. C'mon you guys, this is a nice example!
Best,
Frank
greco558:
Thanks Frank, I am still working on adding some optional command line options so you can narrow the
results that are displayed. I am adding -c minimum count, -l lower byte limit and -u upper byte limit.
Best Regards
John
greco558:
Updated bytect program to process command line arguments.
-c set minimum decimal count of bytes to display: enter decimal value ex. -c 30
-l set lower Hex limit of byte 00-ff to display: enter hex value ex. -l 1a
-u set upper Hex limit of byte 00-ff to display: enter hex value ex. -u 7f
-f followed by filename REQUIRED
-h will show help
-v will give version/info
Above switches are optional except -f filename.
You can use above switches to narrow displayed results.
By setting -u upper limit to display, -l lower limit to display or -c for minimum count to display.
You can use just -u to set upper limit to display or -l for lower limit to display or both -l and -u to
set a range -l 0a -u 89. You can also add in -c to give only bytes with minimum count you set.
For example: ./bytect -f filename -u 7e -c 45
above example will show you byte counts >= 45 and only bytes from 7e down to byte 00
Changed Header printed above display dump from a static message to
one that will change with parameters entered on command line.
Right now when entering parameters on command line you need a space between
command option and parameter example -c 30, not -c30.
Best Regards
John
greco558:
Hi All,
Here is final update on this program unless I find a Bug.
Added procedure to deal with command line switch and parameter so you can
enter switch and parameter with or without a space ex. -c 20 or -c20.
Now command line can handle switches with or without space shown below.
./bytect -ffilename -c20 -l1a -u 78
./bytect -f filename -l 1a -u 78 -c20
Changed header to show lower and upper range in HEX instead of decimal, left
count as decimal
Best Regards
John
Navigation
[0] Message Index
[#] Next page
Go to full version