Fundamentals 11 min read

Understanding x86 Assembly Direct and Indirect Addressing and the LOOP Instruction

This article explains x86 assembly direct and indirect memory addressing, the meaning of address length, how to use registers like BX for indexed access, and demonstrates loop‑based multiplication with detailed code examples and execution analysis.

IT Services Circle
IT Services Circle
IT Services Circle
Understanding x86 Assembly Direct and Indirect Addressing and the LOOP Instruction

The author updates an ongoing series on assembly language, noting the slow publishing pace due to a busy schedule but promising continued tutorials.

In x86 assembly, the operand mov ax,[0] loads a 2‑byte word from the memory location whose offset is 0 in the DS segment, illustrating direct addressing.

Similarly, mov al,[0] loads a single byte from the same offset, showing that the address and the size of the memory unit (word vs. byte) are both required to describe a complete memory operand.

To read data at a specific segment:offset, one can set DS to the segment base and use an offset of 0, e.g., mov bx,10000H<br/>mov ds,bx<br/>mov al,[0], which loads the byte at 10000H into AL.

Indirect (register‑based) addressing uses brackets around a register, such as mov ax,[bx], which reads a word from the address DS:BX. If DS=1000H and BX=1, the CPU fetches the word at 1000H:0001H.

The article introduces a notation using parentheses to denote the contents of a register or memory location, e.g., (ax), (ds), ((ds)*16+(bx)).

It then details the BX addressing mode, showing how to move data between registers and memory with instructions like mov [bx],ax and a sequence of inc bx and mov [bx],ax operations, accompanied by illustrative memory diagrams.

After mastering BX indirect addressing, the author presents a simple multiplication example: computing 2 × 2 by loading 2 into AX and repeatedly adding AX to itself.

To avoid writing many add ax,ax statements for larger repetitions, the LOOP instruction is introduced. By loading the loop count into CX and placing a label before the repeated code, e.g., mov cx,8<br/>s: add ax,ax<br/>loop s, the CPU decrements CX and jumps back to the label until CX reaches zero.

The article explains the three‑step execution of LOOP, the importance of placing the label before the loop body, and provides a full example that multiplies 123 by 456 using CX as the counter.

Throughout, code snippets are presented within ... tags and images illustrating memory states are retained.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Assemblylow‑level programmingx86addressing/loop
IT Services Circle
Written by

IT Services Circle

Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.