Buy(Cart) Contact NSDSP Home

nshex - shrink

The shrink command shrinks a HEX image by removing blank instructions, blank pages, or blank rows. This may reduce the size of the HEX file.

Syntax

target = shrink(source,units)

Argument Description
source The Source image.
units Optional. May be one of the following:
  • word - The command removes all blank instruction words. This may not be the best way to shrink the HEX file, because it may cause fragmentation of the HEX file, and the HEX file may even become bigger than the Source image..
  • row - Default. The command removes all blank flash rows. Rows only apply to code memory. For other types of memory (UID,OTP,EEPROM etc.), each word is treated separately. The configuration bits are treated as a part of a row only if they are located within code memory. If configuration bits have a special location (such as on PIC16, PIC18 and some PIC24) then every configuration word is analyzed and blank words are removed.
  • page - The command removes all blank flash erase pages. Pages only apply to code memory. For other types of memory (UID,OTP,EEPROM etc.), each word is treated separately. The configuration bits are treated as a part of a page only if they are located within code memory. If configuration bits have a special location (such as on PIC16, PIC18 and some PIC24) then every configuration word is analyzed and blank words are removed.

Example

shrunk_code = shrink(original_code,word)

This command shrinks the original_code HEX image by removing all blank instructions or words. The new image is named "shrunk_code".

# shrink.txt - Shrink a HEX file

#read the HEX file
app = read(%1.hex)

#shrink the file and store it back
app = shrink(app,row)
write(app,%1.hex)

This example shows a command file which can be used to shrink any HEX file.

First, the HEX file is loaded. The name of the HEX file must be supplied on the command line.

Then, the HEX image is shrunk and written back, overwriting the original file.

Such command file may be applied to the HEX file which has been read from the actual chip by nsprog. nsprog reads the whole programmable memory. Therefore, the HEX files created by nsprog will often contain blank areas. The shrink command removes all the blanks:

nsprog r -d PIC18F87J94 -o chip.hex
nshex -s shrink.txt chip

Northern Software Home NSDSP Contact Us Purchase/Vew Cart

© 2007-2024 Northern Software Inc. All Rights Reserved.