Foundationপ্রথম নীতি থেকে
LEVEL 3 · Assembly Language

Addressing Mode (x86)

x86 অ্যাড্রেসিং মোড

x86-64-এর memory operand সিনট্যাক্স — displacement(base, index, scale), যেখান থেকে effective address = base + index×scale + displacement। এক instruction-এ array indexing, pointer arithmetic, ও struct field access একসাথে এনকোড হয়।

also: base+index+scale, SIB byte, effective address (x86)

AT&T syntax: disp(base,index,scale)। Intel syntax: [base + index*scale + disp]। চারটা field, সবই ঐচ্ছিক:

fieldকীসীমা
baseঠিকানার শুরু ধরে রাখা registerযেকোনো ৬৪-বিট register
indexকোন element, গুণ হবে scale দিয়েযেকোনো register, %rsp বাদে
scaleindex-কে কত দিয়ে গুণশুধু ১,২,৪,৮ — SIB byte-এর ২-বিট সীমা
displacementconstant যোগফলstruct field offset বা array base offset
movl (%rdi,%rax,4), %eax     ; arr[i], int array — scale=4
movl 4(%rdi,%rax,8), %eax    ; arr[i].y — scale=sizeof(struct), disp=offsetof(y)

sizeof/element size যদি ১,২,৪,৮-এর কোনোটা না হয় (যেমন ২৪ byte struct), scale field-এ সরাসরি বসে না — কম্পাইলার lea-trick ব্যবহার করে (24=3×8, তাই leaq (%rax,%rax,2),%rax দিয়ে ×3, তারপর scale=8)।

lea শুধু ঠিকানা লোড না — এই addressing সার্কিটটাই একটা ৩-input adder+shifter, কম্পাইলাররা এটা সাধারণ multiply-by-constant arithmetic (×3, ×5, ×9)-এর জন্যও ব্যবহার করে, memory access ছাড়াই।

RISC-V-এর একমাত্র addressing mode (base+displacement)-এর তুলনায় x86-64 বেশি কাজ এক instruction-এ ধরতে পারে — বিনিময়ে decoder-এ বেশি জটিলতা (SIB byte-এর নিজস্ব sub-encoding)।