Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

mov array[eax * 4], 0  /* when does multiply happen? */

Posted on 1998-11-17
2
Medium Priority
?
682 Views
Last Modified: 2012-06-27
I know this is not a C question, but maybe some assembly
guys look at this section.

In the assembly statement:

mov dword ptr array[eax * 4], 0

When does the eax register get multiplied by four?

Is the resulting index stored anywhere before it
is added to "array"?  I imagine that the result of
"eax * 4" must be stored somewhere, but where?

NOTE: If you want to see this for yourself, compile
this and look at the assembly that results:

int main()
{
      int array[50];
      int x = 5;

      array[x] = 0;

        return 0;
}
0
Comment
Question by:alfredj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 16

Accepted Solution

by:
heyhey_ earned 200 total points
ID: 1178136
mov dword ptr array[eax * 4], 0 is a standard 486 instruction using some of the more special types of addressing

you can look at some Assembler book for more details
(sorry if i'm wrong with terms - i'm just translating a Russian book)

mov eax, 123456h   - immediate addressing
mov eax, ecx  - registry addressing
mov eax, [123456h] - absolute addressing
mov eax, [ecx] + 123456h - indexed addressing with offset
mov eax, [esi*4] + 1234h - indexed addressing with scaling and offset
..
mov eax, [ebx][edi*2] + 12345h - base index with scaling and offset addressing

so you have ' indexed addressing with scaling and offset'. this is a standard addressing mode in 386+ (or 486+) processors.

hope this helps
  heyhey



0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1178137
you have the following algorithm for calculating the real addres (and maybe it works only in P-mode ?? )

address = offset + [data at base address] + value of index register * multiplier (+base of the segment :).
multiplier can be 1,2,4 or 8 (there are two bits in the instruction opcode reserved for it)

your example
 dword ptr array[eax * 4]
doesn't have a base addres - you have just indexed array
calculated address = offset +  value of index register * multiplier
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question