C++ Learning Community Forum
August 01, 2010, 02:36:56 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hello. Smiley
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Difference on how to manipulate identifiers  (Read 690 times)
Vitdom
N00b!!1
*
Posts: 11



View Profile
« on: February 16, 2009, 11:45:22 AM »

Hi, I recently started ASM programming, I am using the TASM assembler.

Can someone tell me what the difference are here?(also tell me if i'm correct):

message db "Hello there!"

mov eax, seg message ; copies the message's segment's adress into eax
mov eax, offset message ; copies the message's offset in the segment into eax
lea eax, message ; copies the message's offset in the segment into eax
mov eax, message ; copies ?? into eax
mov eax, [message] ; copies the first dword into eax
« Last Edit: February 16, 2009, 03:57:28 PM by Vitdom » Logged
FrozenKnight
ASM Freak
Global Moderator
Dr. of C++ology
*****
Posts: 546


Do it yourself it's the only way to learn.


View Profile
« Reply #1 on: February 22, 2009, 08:35:17 AM »

i think the first thing i need to explain is that i am unfamiliar with the SEG keyword, When dealing with segments i am used to seeing things like ss:eax for using segments.

as for the others i believe that offset is the same as RVA in FASM. If this is the case then Offset is location of your string relative to the start of your file (or address segment in memory)

Quote
lea eax, message ; copies the message's offset in the segment into eax
mov eax, message ; copies ?? into eax
these two are essentially the same except that lea was created more for memory operations than mov.

such as the case
Code
GeSHi (asm):
lea eax, [ebx + ecx*4]
Created by GeSHI 1.0.7.18
also by my understanding
Quote
lea eax, message
is improper syntax too message should be in brackets because it's a supposed to be a pointer
i can also note that lea is simply an add this to that and multiply by this command. ex: it can e used to perform some simple math relatively fast (since all memory calculations are done in one cycle on modern processors. which make mul slow by comparison for some math)
ex: multiply eax by 5
Code
GeSHi (asm):
lea eax, [eax + eax*4]
Created by GeSHI 1.0.7.18
also note though i left it out you can also add a constant value in there.

by comparison the mov command is different mov just "copy's" the one value to another.
in your example translated to "copy value of 'message' to eax register" which is the same as copying the address of your "Hello there!" string into eax.

the main difference is that lea is meant for obtaining dynamic or relative addresses, it is most useful when working with structures that have pointers in them. or when you need to pass a pointer to a value that is on the stack to a function.


the last one mov eax does just as you said. a little note: x86 asm code usually uses little edian format what this means is that you are copying the first dword but in reverse order, this usually doesnt matter since it gets reversed again when you move it back but if you manipulate it in eax just remember that al contains the value of 'H' not 'l'.

as a last note ASM does not assume a null terminator at leas not on any assembler I have used. so you might want to add a ',0' after your string just to be safe.
Logged


Imagine the impossible, then make it happen.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!