-1

what does this command do in assambly ?

mov ebx, [eax+ecx*4+12] 

does it do the same of the following ?

MOV EBX,ECX
ADD EBX,EBX ; *2
ADD EBX,EBX ; *4
ADD EBX,EAX
ADD EBX,12
MOV EBX,[EBX]

if yes why do they don't give the same result in Jasmin when eax = 100h, ebx = 0, ecx = 100h

end.

Ilmari Karonen
  • 49,047
  • 9
  • 93
  • 153
Elteroooo
  • 2,913
  • 3
  • 33
  • 40
  • This seems unrelated to Jasmin, the JVM assembler, because `mov` and `add` are not the proper mnemonics for any instruction for JVM. –  Dec 28 '12 at 17:01
  • 1
    @Tinctorius: I believe the question is referring to [this Jasmin](http://www.lrr.in.tum.de/~jasmin/), not [the other one](http://jasmin.sourceforge.net/). I wonder if it should have a separate tag. Maybe [tag:jasmin-x86]? – Ilmari Karonen Dec 28 '12 at 20:28

1 Answers1

0

lets say we have these commands

mov eax, 0x1234 ; 1234h
mov ebx, 0
mov ecx, 0x1234 ; 1234h
MOV EBX,ECX ; ebx = 0x1234
ADD EBX,EBX ; *2
ADD EBX,EBX ; *4
ADD EBX,EAX ; ebx = 0x5B04
ADD EBX,12  ; ebx = 0x5B10
MOV EBX, [EBX] ; Error out of range

; Or
mov ebx, [eax+ecx*4+12] ; => mov ebx, [0x1234+0x1234*4+12]

=> its actually mov ebx, [0x5B10] where 0x5B10 is the address number in the memory, but in my case the maximal address is 0xFFC < 0x5B10, so its out of range so the appeared result is the result of the before last command

so by using smaller values like 0x14 we get the same result

mov eax, 0x14 ; eax = 0x14
mov ebx, 0    ; ebx = 0
mov ecx, 0x14 ; ecx = 0x14
MOV EBX,ECX   ; ebx = 0x14
ADD EBX,EBX   ; *2
ADD EBX,EBX   ; *4
ADD EBX,EAX   ; ebx = 0x64
ADD EBX,12    ; ebx = 0x70
MOV EBX, [EBX] ; => mov ebx, [0x70]

; Or
mov ebx, [eax+ecx*4+12] ; => mov ebx, [0x14+0x14*4+12] => mov ebx, [0x70]

we get in both cases or methode:

eax = 0x14
ebx = 0   => its 0 because the address 0x70 in the memory is empty = 0x0000
ecx = 0x14

BUT if we add before the last line something like

mov [0x70], 0x111

we will get in ebx 0x111

Elteroooo
  • 2,913
  • 3
  • 33
  • 40