You are on page 1of 5

UNTIY UNIVERSITY

CMC-AREGA CAMPUS
Prepared by: ID NO;

KIDUS MICALE 00278

ANWAR NEGASH 00259

NAHOM SHEMLES 00317

ABENEZER G/KIRSTOS 00323

YASMIN AMIN 00420

Section: CSR1S2/14

Course: Computer Organization & Assembly Language

Assignment on Machine Instructions and addressing modes

Submitted to: MR. Girmay. G

Submission Date: 06/04/23

Machine Instructions and addressing modes


A. Introduction:
Machine instructions and addressing modes are fundamental concepts in computer architecture
and programming. Machine instructions are the instructions that a computer's processor can
directly execute. They define the operations that the computer performs, such as arithmetic
calculations, data manipulation, and control flow. Addressing modes, on the other hand,
determine how memory and registers are accessed in these instructions. They specify the
addressing scheme used to locate operands and results.

B. Overview of Machine Instructions and Addressing Modes:

Machine instructions are the fundamental building blocks of computer programs. They are the
low-level commands that a computer's central processing unit (CPU) can execute directly.

Machine instructions are represented in binary code and are designed to perform specific
operations, such as arithmetic, logic, data movement, and control flow. These instructions are the
building blocks of computer programs and are executed in a step-by-step manner. The CPU
fetches an instruction from memory, decodes it, and then executes it, before moving on to the
next instruction.

There are many different types of machine instructions, each with its own unique binary code
and purpose. Some examples of common machine instructions include:

- MOV: moves data from one location to another

- ADD: adds two values together

- SUB: subtracts one value from another

- JMP: jumps to a different location in the program

- CMP: compares two values

Addressing modes are a way of specifying the operand(s) of a machine instruction. An operand
is a value or an address that is used as an input or output to an instruction. Addressing modes
determine how the operand(s) are specified in the instruction and how they are accessed by the
CPU.

There are various addressing modes, such as immediate, direct, indirect, indexed, and register
addressing modes. Each addressing mode offers different ways to access operands, providing
flexibility and optimization possibilities.
Choosing the right addressing mode for a particular instruction can have a significant impact on
the performance and efficiency of the program. For example, using immediate addressing for a
large amount of data can make the program slower, as the data needs to be loaded into the
instruction each time it is executed. Using register addressing can be faster, but it can also limit
the amount of data that can be manipulated at once.

C. Examples and Case Studies:

To better grasp the practical application of machine instructions and addressing modes, let's
explore some examples and case studies. Consider an arithmetic operation where two numbers
need to be added and the result stored in a specific memory location. Different addressing modes
can be employed to achieve this

task. For instance, immediate addressing mode allows one operand to be specified directly within
the instruction, reducing the need for additional memory access. On the other hand, register
addressing mode can utilize the processor's registers, which are faster to access than memory.

In another case, suppose a program requires accessing elements of an array stored in memory.
Different addressing modes, such as indexed or indirect addressing, can be used to efficiently
iterate over the array and retrieve its elements. Each addressing mode offers its advantages and
trade-offs in terms of code complexity, execution time, and memory utilization. By analyzing
these examples and case studies, we can gain a deeper understanding of how addressing modes
impact program performance and optimize the use of system resources.

To illustrate the concepts of machine instructions and addressing modes, let's consider an
example:

Suppose we have the following assembly language program:

MOV AX, 5
ADD AX, 3
MOV BX, AX

The first instruction MOV AX, 5 transfers the value 5 to the AX register using immediate
addressing. The second instruction ADD AX, 3 adds the value 3 to the AX register using
immediate addressing. The third instruction MOV BX, AX transfers the value of the AX register
to the BX register using register addressing.

Another example is:

LDA 100
ADD 101
STA 102
The first instruction LDA 100 loads the value at memory location 100 into the accumulator using
direct addressing. The second instruction ADD 101 adds the value at memory location 101 to the
accumulator using direct addressing. The third instruction STA 102 stores the value of the
accumulator into memory location 102 using direct addressing.

There are several common mistakes that programmers can make when programming with
machine instructions. Here are a few examples:
● Using the wrong addressing mode: Using the wrong addressing mode can lead to
unexpected results or even program crashes. For example, using direct addressing when
indirect addressing was intended can result in the wrong memory location being
accessed.
● Not checking for overflow or underflow: Arithmetic operations can result in overflow or
underflow conditions, which can lead to incorrect results. Programmers should always
check for these conditions and handle them appropriately.
● Failing to initialize registers or memory: It is important to initialize registers and memory
before using them, otherwise, their values may be undefined. This can lead to
unpredictable program behavior.
● Not properly handling interrupts: Interrupts can occur at any time during program
execution, and failing to handle them properly can result in program crashes or data
corruption.
● Writing code that is not portable: Different CPUs may have different instruction sets and
addressing modes, so it is important to write code that is portable across different
platforms. This can be achieved by using abstraction layers or by writing code that is
specific to a particular platform.
● Not optimizing code for performance: Machine instructions are executed by the CPU,
which can be a bottleneck in program performance. Programmers should always strive to
write code that is optimized for performance, using techniques such as loop unrolling or
register allocation.
By avoiding these common mistakes and following best practices for programming with machine
instructions, programmers can write efficient and reliable code.

D. Limitations and Trade-offs:

While machine instructions and addressing modes provide powerful capabilities for
programming and system design, they also come with limitations and trade-offs. One limitation
is the restricted number of addressing modes supported by specific processors or architectures.
Some processors may have a limited set of addressing modes available, which can affect the
flexibility and optimization potential of programs. Additionally, certain addressing modes may
require additional memory access or instruction cycles, leading to increased execution time.
Trade-offs also exist in terms of code complexity and maintainability. Using complex addressing
modes may result in more intricate code, making it harder to understand and debug. Moreover,
certain addressing modes may be more suitable for specific scenarios, while others may
introduce inefficiencies or compatibility issues with certain hardware architectures.

Understanding these limitations and trade-offs is crucial for making informed decisions when
selecting and utilizing addressing modes in programming. By carefully evaluating the
requirements and constraints of a particular application, developers can strike a balance between
performance, code readability, and hardware compatibility

How can different sets of instructions and addressing modes affect the portability of code?

Different computer architectures can have different sets of instructions and addressing modes,
which can impact the portability of code. Portability refers to the ability of code to run on
different platforms or computer systems without requiring significant modifications.
If code is written using instructions or addressing modes that are specific to a particular
architecture, it may not be portable to other architectures. For example, if code is written using
x86 instructions and addressing modes, it may not run on an ARM-based system without
modification. Similarly, if code is written using instructions or addressing modes that are specific
to a particular operating system, it may not run on other operating systems.
To write portable code, programmers must be aware of the differences between architectures and
operating systems and avoid using instructions or addressing modes that are specific to a
particular platform. They can use programming languages that are designed to be portable, such
as Java or Python, or write code in a way that is abstracted from the underlying hardware, such
as using libraries or APIs that provide a consistent interface across different platforms.

E. Conclusion and Q&A:

Machine instructions and addressing modes are essential concepts in computer architecture and
programming. Machine instructions are the basic commands that a CPU can execute directly,
while addressing modes determine how the operand(s) of a machine instruction are specified and
accessed. Choosing the right addressing mode for a particular instruction can have a significant
impact on the performance and efficiency of the program. By understanding how machine
instructions and addressing modes work, programmers can write more efficient and effective
code.

You might also like