Instruction vs Data

A software programme is made up of a bunch of things but the main ones are: instruction and data. Instructions tell the programme what to do and is usually stored in the .text portion of the binary. Data is what the programme works on and mainly consists of the heap and stack stored in different parts of the memory.

So, with all else being equal, what is the difference between these two parts of an application and should a programmer care?

Knuth claims that it is important to select an appropriate data structure for a programme and that the selection of the right data structure can make or break an application – or something to that affect. Therefore, it is obvious that the data portion of a programme is a very important consideration. However, the trick is to have a data structure that is small and fast for two reasons.

Firstly, small data structures can be held in cache memory, speeding up processing time by reducing the number of reads and writes between the processor and memory. Anyone who cares about writing good software should already know about this trade-off. So, this should not surprise most people. Unless there is good reason to use a large dynamic data structure, a small static one may produce better performance.

Secondly, small data structures use less memory. Instructions rarely change and can actually be stored in fixed memory on a chip such as flash memory or ROM. In the case of programmes actually embedded into on-chip hardware, it is very important to minimise the use of RAM and to maximise the use of ROM for one reason – cost. It costs six-times as much per bit of RAM than ROM on a chip. It’s because SRAM contains six times as many transistors per bit.

So, for code that is embedded on-chip, it is particularly important to write code that uses less RAM and uses more ROM. So, static look-up-tables in ROM is good, while dynamic pointer linked structures in RAM is not so good.

Published by

Shawn Tan

Chip Doctor, Chartered/Professional Engineer, Entrepreneur, Law Graduate.

One thought on “Instruction vs Data”

  1. Actually, there isn’t really a difference between instructions and data.
    Programs processing data into something can be seen as compilers processing programs into something. It is just a matter how close to Turing-complete the language is, that is processed. And you’d be surprised, how close many real-life formats are. All complex document formats end up being basically programming languages.

    And modern languages deliberately do not distinguish between functions and values anymore. E.g. in Haskell.

    You can only distinguish by other things. Like: Does it take values/variables/parameters/context? Is it fully Turing-complete? Etc.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s