LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-19-2011, 03:37 AM   #1
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Rep: Reputation: 15
Question assembly language! please help me! thanks in advance!


what is the difference between this two instructions? thanks
Code:
array WORD 1,2,3,4,5
mov esi,OFFSET array+4
mov esi,array+4
 
Old 03-19-2011, 04:08 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,289

Rep: Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322
Get real, please.
You have multiple queries with the same subject and no details. What assembler? What CPU? Business or Pleasure?
Quote:
mov esi,OFFSET array+4
mov esi,array+4
In many assemblers, OFFSET would be taken as a variable. So your instruction would be seen as
mov esi $OFFSET
and array+4 on that line would produce a syntax error about an extra operand. I would expect every assembler I have used to barf on mov esi,array+4 as a syntax error.
 
Old 03-19-2011, 04:26 AM   #3
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by business_kid View Post
Get real, please.
You have multiple queries with the same subject and no details. What assembler? What CPU? Business or Pleasure?


In many assemblers, OFFSET would be taken as a variable. So your instruction would be seen as
mov esi $OFFSET
and array+4 on that line would produce a syntax error about an extra operand. I would expect every assembler I have used to barf on mov esi,array+4 as a syntax error.
oh sorry! my assembler is nasm(intel syntax).and yours is GAS(AT&T syntax),right? for pleaseure.thanks
 
Old 03-19-2011, 10:24 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
This is one of those quirky x86-isms. Its been a while since I've done any assembler coding there, but here goes. The OFFSET assembler directive tells the assembler to use the specified address as an OFFSET (duh..) for the start of the default segment. This is distinct from the actual address, since the segment may get loaded such that its segment register is not zero-based. It is one of those things that seems to have turned a lot of people off of the whole x86 family.

--- rod.
 
Old 03-19-2011, 10:48 AM   #5
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by theNbomr View Post
This is one of those quirky x86-isms. Its been a while since I've done any assembler coding there, but here goes. The OFFSET assembler directive tells the assembler to use the specified address as an OFFSET (duh..) for the start of the default segment. This is distinct from the actual address, since the segment may get loaded such that its segment register is not zero-based. It is one of those things that seems to have turned a lot of people off of the whole x86 family.

--- rod.
thanks,but i am not quite understand what you are saying,could you say it more in detail?thanks very much!
 
Old 03-19-2011, 02:21 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I might be able to, but it sounds like you lack some of the background knowledge to understand it. To write enough to build all of that would be beyond the scope of this forum. Do you understand the relationship between the segment registers, the pointer registers, and the linker in building assembly language object code? With a thorough understanding of these concepts, you should be able to understand my original answer. Having said that, in practical terms, there are few cases where the use of the OFFSET directive adds anything.
The OFFSET directive is only used in the Microsoft Assembler to disambiguate between specification of an address and the content of an address. Since you are using NASM, this is already done by the assembler enforcing the use of the [square_bracket] notation to specify an address content. Example:
Code:
   mov   esi, myLabel      ; makes esi point to address 'myLabel'
                           ; (but, in MASM, it might do like below)
   mov   esi, [myLabel]    ; loads the word stored at ds:myLabel into register esi
See 2.2.2 NASM Requires Square Brackets For Memory References for more details.

--- rod.

Last edited by theNbomr; 03-19-2011 at 02:25 PM.
 
Old 03-19-2011, 08:15 PM   #7
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by theNbomr View Post
It is one of those things that seems to have turned a lot of people off of the whole x86 family.

--- rod.
But its still better then the backwards syntax and useless % of at&t syntax.
-
I could be wrong since ASM is not my specialty but I think that the second one copies the value and the first copies the offset of the segmentffset pair.

Last edited by smeezekitty; 03-19-2011 at 08:19 PM. Reason: Stupid error on my part
 
  


Reply

Tags
nasm



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
assembly language! please help me! thanks in advance! topheraholic Programming 6 03-21-2011 02:35 PM
Is Assembly Language considered a Structured Language? theKbStockpiler Programming 4 01-30-2011 09:09 AM
assembly language: ret>>=10 ashlesha Programming 2 09-13-2006 04:11 AM
Assembly Language, and networks grizzly Programming 5 12-11-2003 09:50 PM
SPARC assembly language jclark00001 Programming 3 02-26-2003 08:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration