Monday, March 3, 2025

Addressing modes in 8086 programming

 The different ways in which a source operand is denoted in an instruction is known as addressing modes. There are 8 different addressing modes in 8086 programming 

Addressing modes are the techniques used by the CPU to identify where the data needed for an operation is stored. They provide rules for interpreting or modifying the address field in an instruction before accessing the operand.

Addressing modes for 8086 instructions are divided into two categories:

1) Addressing modes for data

2) Addressing modes for branch

The 8086 memory addressing modes provide flexible access to memory, allowing us to easily access variables, arrays, records, pointers, and other complex data types. The key to good assembly language programming is the proper use of memory addressing modes.

An assembly language program instruction consists of two parts

am1

The memory address of an operand consists of two components:




IMPORTANT TERMS

  • Starting address of memory segment.
  • Effective address or Offset: An offset is determined by adding any combination of three address elements: displacement, base and index.
    • Displacement: It is an 8 bit or 16 bit immediate value given in the instruction.
    • Base: Contents of base register, BX (Base Register)or BP (Base Pointer Register).
    • Index: Content of index register SI (Source Index Register) or DI (Destination Index Register).

According to different ways of specifying an operand by 8086 microprocessor, different addressing modes are used by 8086.

Importance of Addressing Modes

  • They allow flexibility in data handling, such as accessing arrays, records, or pointers.
  • They support program control with techniques like loops, branches, and jumps.
  • They enable efficient memory usage and program relocation during runtime.
  • They reduce the complexity of programming by offering multiple ways to access data.

Types of Addressing Modes in Computer Architecture

Addressing Modes used by 8086 microprocessor are discussed below:

Implied mode

In implied addressing the operand is specified in the instruction itself. In this mode the data is 8 bits or 16 bits long and data is the part of instruction. Zero address instruction are designed with implied addressing mode.am2

Example:  CLC
(used to reset Carry flag to 0)

Immediate addressing mode (symbol #)

In this mode data is present in address field of instruction .Designed like one address instruction format. Note: Limitation in the immediate mode is that the range of constants are restricted by size of address field.

Example:  MOV AL, 35H
(move the data 35H into AL register)

Register mode

In register addressing the operand is placed in one of 8 bit or 16 bit general purpose registers. The data is in the register that is specified by the instruction. Here one register reference is required to access the data.am3

Example: MOV AX,CX
(move the contents of CX register to AX register)

Register Indirect mode

In this addressing the operand’s offset is placed in any one of the registers BX,BP,SI,DI as specified in the instruction. The effective address of the data is in the base register or an index register that is specified by the instruction. Here two register reference is required to access the data.am5The 8086 CPUs let you access memory indirectly through a register using the register indirect addressing modes.

MOV AX, [BX]
(move the contents of memory location addressed by the register BX to the register AX)

Auto Indexed (increment mode)

Effective address of the operand is the contents of a register specified in the instruction. After accessing the operand, the contents of this register are automatically incremented to point to the next consecutive memory location.(R1)+. Here one register reference, one memory reference and one ALU operation is required to access the data. Example:

Add R1, (R2)+  // OR
R1 = R1 +M[R2]
R2 = R2 + d

Useful for stepping through arrays in a loop. R2 – start of array d – size of an element

Auto indexed ( decrement mode)

Effective address of the operand is the contents of a register specified in the instruction. Before accessing the operand, the contents of this register are automatically decremented to point to the previous consecutive memory location. –(R1)Here one register reference, one memory reference and one ALU operation is required to access the data. Example:

Add R1,-(R2)   //OR
R2 = R2-d
R1 = R1 + M[R2]

Auto decrement mode is same as  auto increment mode. Both can also be used to implement a stack as push and pop . Auto increment and Auto decrement modes are useful for implementing “Last-In-First-Out” data structures.

Direct addressing/ Absolute addressing Mode (symbol [ ])

The operand’s offset is given in the instruction as an 8 bit or 16 bit displacement element. In this addressing mode the 16 bit effective address of the data is the part of the instruction. Here only one memory reference operation is required to access the data.am6

Example: ADD AL,[0301]   //add the contents of offset address 0301 to AL

Indirect addressing Mode (symbol @ or () )

In this mode address field of instruction contains the address of effective address. Here two references are required. 1st reference to get effective address. 2nd reference to access the data. Based on the availability of Effective address, Indirect mode is of two kind:

  • Register Indirect: In this mode effective address is in the register, and corresponding register name will be maintained in the address field of an instruction. Here one register reference, one memory reference is required to access the data.

Example : MOV A, @R0   

  • Memory Indirect: In this mode effective address is in the memory, and corresponding memory address will be maintained in the address field of an instruction. Here two memory reference is required to access the data.

Example : MOV AX, [[5000H]]

Indexed addressing mode

The operand’s offset is the sum of the content of an index register SI or DI and an 8 bit or 16 bit displacement.

Example: MOV AX, [SI +05]

Based Indexed Addressing

The operand’s offset is sum of the content of a base register BX and an index register SI or DI.

Example: ADD AX, [BX+SI]

Based on Transfer of control, addressing modes are:

PC relative addressing mode

PC relative addressing mode is used to implement intra segment transfer of control, In this mode effective address is obtained by adding displacement to PC.

EA= PC + Address field value
PC= PC + Relative value.

Base register addressing mode

Base register addressing mode is used to implement inter segment transfer of control. In this mode effective address is obtained by adding base register value to address field value.

EA= Base register + Address field value.
PC= Base register + Relative value

Note :

  • PC relative and based register both addressing modes are suitable for program relocation at runtime.
  • Based register addressing mode is best suitable to write position independent codes.

Advantages of Addressing Modes

  • Enable advanced programming techniques like pointers and counters for loops.
  • Simplify memory access for arrays and complex data structures.
  • Allow program relocation during runtime.
  • Reduce the size of the instruction field, making the program more efficient.

Frequently Asked Question on Addressing Modes – FAQs

What are the addressing modes of 8085?

The addressing modes of the 8085 microprocessor are Immediate, Direct, Register, Register Indirect, and Implicit.

What is opcode and operand?

An opcode (operation code) is the part of an instruction that specifies the operation to be performed (e.g., ADD, SUB). An operand is the data or memory location on which the operation is executed. For example, in ADD A, B, “ADD” is the opcode, and “A” and “B” are the operands.

What is an effective address?

An effective address is the actual memory location from which data is accessed or to which data is stored during instruction execution. It is calculated using the addressing mode, combining base addresses, offsets, or other components specified in the instruction.

Advantages of Addressing Modes

  • By using different addressing modes, you can access data in registers or memory and as immediate values which makes CPU instructions more versatile.
  • The register-based and indexed mode make better use of memory, especially in the case of loop operations / arrays.
  • For example, modes such as register addressing will make the instructions run faster because they read data directly from registers rather than memory.

Disadvantages of Addressing Modes

  • Indirect or indexed addressing modes: here the program logic becomes harder to see and maintain as not all instructions are using them.
  • Like displacement or relative addressing modes, that could add possibly memory overhead which is near in the event of large value displacements.
  • Other addressing modes are more closely linked to the CPU architecture, making it less easy for assembly code to be ported across different hardware platforms.

"This Content Sponsored by Buymote Shopping app

BuyMote E-Shopping Application is One of the Online Shopping App

Now Available on Play Store & App Store (Buymote E-Shopping)

Click Below Link and Install Application: https://buymote.shop/links/0f5993744a9213079a6b53e8

Sponsor Content: #buymote #buymoteeshopping #buymoteonline #buymoteshopping #buymoteapplication" 

Sunday, March 2, 2025

Difference Between Register and Memory

 

Difference Between Register and Memory


  • Registers and memory are essential for the operation of a computer, each having its own advantages. 
  • Registers offer the CPU quick access to data it must process, thus ensuring fast operation. Memory, on the other hand, 
  • provides storage space needed for large amounts of data and instructions during program execution.
  •  Although registers are small and quick for working with data, memory is bigger but slower and equally necessary for handling heavy-duty tasks. 
  • A clear distinction between the two makes it easier to grasp the way in which a computer manages information effectively.

What is Register?


Registers are the smallest data-holding elements that are built into the processor itself. 

These are the memory locations that are directly accessible by the processor. 

It may hold an instruction, a storage address, or any data such as a bit sequence or individual characters. 

For example, an instruction may specify that the contents of two defined registers be multiplied together and then placed in a specific register.

Example: Accumulator register, Program counter, Instruction register, Address register, etc.


Advantages and Disadvantages of Registers

Advantages:

  • Speed: Registers are the fastest type of storage, providing instant access to data.
  • Efficiency: They allow the CPU to execute instructions faster by storing immediate data.
  • Proximity: Since they are placed within the CPU, they require less time to get data.

Disadvantages:

  • Storage Capacity:Registers have limited storage capacity.
  • Manufacture Cost: They are costly to manufacture due to their speed and integration into the CPU.
  • Volatility: Data in registers is lost when the machine is turned off.




  • What is Memory ?

    Memory is a hardware device used to store computer programs, instructions and data. The memory that is internal to the processor is a primary memory (RAM), and the memory that is external to the processor is a secondary memory (Hard Drive).

    Memory can also be categorized on the basis of volatile and non-volatile memory. Volatile memory is memory that loses its contents when the computer or hardware device loses power. RAM(Random Access Memory) is an example of volatile memory. Non-volatile memory is the memory that keeps its contents even if power gets lost. EPROM is an example of non-volatile memory.

    Example : RAM , EPROM etc.

    Advantages and Disadvantages of Memory

    Advantages:

    • Storage Capacity: Memory (RAM) provides large storage space for data and instructions.
    • Flexibility: It can hold any form of data that the CPU requires during execution.
    • Cost-Effective: Memory(RAM) is more cost-effective than registers since it has a bigger capacity and costs less per bit.

    Disadvantages:

    • Speed:Memory is slower than registers, therefore data retrieval takes longer.
    • Volatility: RAM, like registers, is volatile, meaning it loses data when the machine is turned off.
    • Latency: Accessing data from memory takes longer, potentially slowing down operations.
    • Difference Between Register and Memory

      RegisterMemory
      Registers hold the operands or instruction that CPU is currently processing.Memory holds the instructions and the data that the currently executing program in CPU requires.
      Register holds the small amount of data around 32-bits to 64-bits.Memory of the computer can range from some GB to TB.
      CPU can operate on register contents at the rate of more than one operation in one clock cycle.CPU accesses memory at the slower rate than register.
      Types are Accumulator register, Program counter, Instruction register, Address register, etc.Type of memory are RAM, etc.
      Registers can be control i.e. you can store and retrieve information from them.Memory is almost not controllable.
      Registers are faster than memory.RAM is much slower than registers.

    "This Content Sponsored by Buymote Shopping app

    BuyMote E-Shopping Application is One of the Online Shopping App

    Now Available on Play Store & App Store (Buymote E-Shopping)

    Click Below Link and Install Application: https://buymote.shop/links/0f5993744a9213079a6b53e8

    Sponsor Content: #buymote #buymoteeshopping #buymoteonline #buymoteshopping #buymoteapplication"

The 8086 microprocessor - instructions


  • The 8086 microprocessor supports 8 types of instructions
  • Data Transfer Instructions
  • Arithmetic Instructions
  • Bit Manipulation Instructions
  • String Instructions
  • Program Execution Transfer Instructions (Branch & Loop Instructions)
  • Processor Control Instructions
  • Iteration Control Instructions
  • Interrupt Instructions

The data transfer instructions are used to transfer data from one location to another. This transfer of data can be either from register to register, register to memory or memory to register.




It is important to note here that the memory to memory transfer of data directly is not possible.

Following are some instructions that are used for data transfer purpose:

  1. MOV
  2. PUSH
  3. POP
  4. XCHG
  5. LAHF
  6. SAHF
  7. IN
  8. OUT
  9. LDS
  10. LES


The table showing the list of data transfer instructions with Example 


OPCODEOPERANDEXPLANATIONEXAMPLE
MOVD, SD = SMOV AX, [SI]
PUSHDpushes D to the stackPUSH DX
POPDpops the stack to DPOP AS
PUSHAnoneput all the registers into the stackPUSHA
POPAnonegets words from the stack to all registersPOPA
XCHGD, Sexchanges contents of D and SXCHG [2050], AX
IND, Scopies a byte or word from S to DIN AX, DX
OUTD, Scopies a byte or word from D to SOUT 05, AL
XLATnonetranslates a byte in AL using a table in the memoryXLAT
LAHFnoneloads AH with the lower byte of the flag registerLAHF
SAHFnonestores AH register to lower byte of the flag registerSAHF
PUSHFnonecopies the flag register at the top of the stackPUSHF
POPFnonecopies a word at the top of the stack to the flag registerPOPF

                            


"This Content Sponsored by Buymote Shopping app
BuyMote E-Shopping Application is One of the Online Shopping App
Now Available on Play Store & App Store (Buymote E-Shopping)
  1. Click Below Link and Install Application: https://buymote.shop/links/0f5993744a9213079a6b53e8

    Sponsor Content: #buymote #buymoteeshopping #buymoteonline #buymoteshopping #buymoteapplication"




ECG, EEG, EMG, Holter Monitoring, Fetal ECG/Fetal Monitoring and Digital Patient Data Recorders

  PART A – TWO-MARK QUESTIONS AND ANSWERS 1. What is a biomedical recording system? A biomedical recording system is an electronic syste...