1. Overview
In this tutorial, we’ll discuss the basics of computer programs and instructions. We’ll also present the core differences between them.
2. What Is a Computer Program?
A computer program consists of a set of instructions in an ordered sequence in order to execute some user-specified tasks. Programs are generally stored in the main memory. A computer executes one instruction at a time.
Computer programs are also known as software applications. We generally write programs using programming languages. Programming languages offer an easy and friendly interface to write computer codes. Using a computer programming language, we can write a computer program that is understandable by humans.
A computer can’t execute high-level code. It only understands binary machine code. Hence, a computer first converts the high-level codes into binary machine-executable codes. Finally, the computer executes the binary machine-executable codes and performs the task specified by the user:
We can divide computer programs into two categories: interactive and batch programs.
An interactive user provides input to an interactive program. The user can manage, modify, and manipulate data while the program is in a running state. Most of the software programs are interactive in nature as they need some interaction from the user in order to operate smoothly. An example of an interactive program is a web browser.
On the other hand, a batch program can run without any user data. This type of program doesn’t need any interaction from the user. A batch program stops automatically when it completes execution.
A major disadvantage is that all the data and information needed to execute a certain task must be coded in advance. An example of a batch program is a printing application.
3. Introduction to Computer Instructions
Now we know computers can only understand binary machine codes. Computer instruction is a set of binary machine understandable code which is executed by a CPU. It contains the steps which tell the CPU to do a specific task.
For example, we need to specify each step to draw a square on a computer screen. The computer will execute each step one by one:
forward 50
right 90
forward 50
right 90
forward 50
right 90
forward 50
The output would be:
In general, modern computers contains a 16-bit instruction register (IR). Each instruction consist of fields: mode, opcode, and address field:
The mode field defines how a computer can locate the operand. The opcode or operation code field describes the operations to be executed by the CPU. Finally, the address field contains the address of the operand, like memory location or register address.
We can be divide computer instructions into categories based on the code format: memory, register, and input/output reference instruction.
In the memory reference instruction, we use bit to specify the memory address, bit for the opcode, and bit for setting the mode as indirect addressing mode:
In the register reference instruction, the instructions are executed on the register. Moreover, it contains a bit register operation address. Out of the remaining bit, bit is used for the opcode, and bit is utilized for setting the mode:
Finally, input/output instruction is used for communication between the environment and the computer. Moreover, it contains a bit input/output operation address. Out of the remaining bit, bit is used for the opcode, and bit is utilized for setting the mode:
4. Differences Between Program and Instruction
At this point, we know the fundamentals of computer programs and instructions. Now let’s discuss the core difference between them:
Program
Instruction
Consists of a set of instructions.
Consists of the ordered binary machine code.
Given to a computer and written using programming languages.
Given to a computer using any input device such as keyboard, mouse.
Instructs to execute tasks like formatting, calculation.
Performs discreet actions like load, move.
Examples are web browser, game, media player.
Examples are flow control, integer instruction.
5. Conclusion
In this tutorial, we discussed the fundamentals of computer programs and instructions with examples. We also presented the core differences between them.