Author Topic: byte count  (Read 2407 times)

Offline greco558

  • Jr. Member
  • *
  • Posts: 32
byte count
« on: July 10, 2017, 11:47:27 AM »
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

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2379
  • Country: us
Re: byte count
« Reply #1 on: July 11, 2017, 05:37:51 AM »
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


Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Re: byte count
« Reply #2 on: July 12, 2017, 01:26:25 AM »
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

Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Updated Bytect
« Reply #3 on: July 13, 2017, 06:58:21 PM »
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
« Last Edit: July 17, 2017, 11:01:15 AM by greco558 »

Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Update: Header Change
« Reply #4 on: July 17, 2017, 11:09:30 AM »
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
« Last Edit: July 18, 2017, 11:24:30 AM by greco558 »

Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Byte count bug fix
« Reply #5 on: March 09, 2018, 07:39:11 PM »
Fixed Bug I found in bytect program.

If count of byte was greater then 256, display of that bytes count would not be accurate because
I was storing count in a byte sized memory  location, change to dword size and adjusted index into
count memory EBX*4 and counting is now accurate for number of bytes in file greater 256.


Best Regards
John
 

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2379
  • Country: us
Re: byte count
« Reply #6 on: March 09, 2018, 08:43:44 PM »
Thanks John!

I missed that. My computer crashed recently, so I'm re-collecting my collection of examples.

Best,
Frank


Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Re: byte count
« Reply #7 on: March 09, 2018, 08:53:04 PM »
Thanks, But I just fixed what I hope is the last Bug.

It just had to do with -c option greater than 255.

Fixed in this new program.



Best Regards
John