Method of generating a set of compacted instructions to be processed by a programmable processor, comprising the steps of a) receiving at least one input code sample representative for software to be executed on the programmable processor, the input code comprising a plurality of instructions defining a first set of instructions, b) initializing a set of removed instructions as empty, c) determining the most compact representation of the first set of instructions, wherein the instructions comprise a plurality of instruction fields that are individually compacted, the most compact representation being either the uncompacted representation or a representation obtained by compressing the first set of instructions with a selected one of a plurality of instruction compaction schemes, d) comparing the size of said most compact representation with a threshold value, e) carrying out steps e1 to e3 if the size is larger than said threshold value, e1) determining which instruction of the first set of instructions has a highest coding cost, e2) removing said instruction having the highest coding cost from the first set of instructions and, e3) adding said instruction to the set of removed instructions, f) repeating steps b-f, wherein the first set of instructions is formed by the set of removed instructions (S9, S10), g) receiving a program comprising a plurality of instructions, h) for each instruction determining the corresponding instruction compaction as determined in steps a-f, i) compressing the instruction according to said instruction compaction, j) providing the compacted instructions. a) receiving at least one input code sample representative for software to be executed on the programmable processor, the input code comprising a plurality of instructions defining a first set of instructions, b) initializing a set of removed instructions as empty, c) determining the most compact representation of the first set of instructions, wherein the instructions comprise a plurality of instruction fields that are individually compacted, the most compact representation being either the uncompacted representation or a representation obtained by compressing the first set of instructions with a selected one of a plurality of instruction compaction schemes, d) comparing the size of said most compact representation with a threshold value, e) carrying out steps e1 to e3 if the size is larger than said threshold value, e1) determining which instruction of the first set of instructions has a highest coding cost, e2) removing said instruction having the highest coding cost from the first set of instructions and, e3) adding said instruction to the set of removed instructions, e1) determining which instruction of the first set of instructions has a highest coding cost, e2) removing said instruction having the highest coding cost from the first set of instructions and, e3) adding said instruction to the set of removed instructions, f) repeating steps b-f, wherein the first set of instructions is formed by the set of removed instructions (S9, S10), g) receiving a program comprising a plurality of instructions, h) for each instruction determining the corresponding instruction compaction as determined in steps a-f, i) compressing the instruction according to said instruction compaction, j) providing the compacted instructions.