LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 11-15-2004, 10:19 PM   #1
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
SIB byte question


Hello.

I'm going through the NASM x86 assembly. My question is this:
Is it true that the command MOV EAX,[ESP] would be longer than MOV EAX,[EBX] after each is converted to machine language? The reason I believe that it is the case is that the first would have to make use of the SIB byte (since there are restrictions on the ESP register in indirect addressing) while the second does not make use of SIB. I just want to make sure I understand.
 
Old 11-16-2004, 10:30 PM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
It has been a long time since I did this sort of thing, but I don't believe MOV EAX,[ESP] is supported by the x86 instruction set at all... at least, there's nothing listed in the Pentium manual for [ESP] that I can see.

If anything, this would have to be coded as POP EAX, PUSH EAX instead (2 bytes).
 
Old 11-17-2004, 11:32 AM   #3
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Original Poster
Rep: Reputation: 165Reputation: 165
Thank you for your comment, CroMagnon. I was able to check the machine code for those statements. MOV EAX,[ESP] translates to 8B 04 24, while MOV EAX,[EBX] translates to the shorter 8B 03.
 
Old 11-17-2004, 04:11 PM   #4
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Sorry, I see my mistake now... you are correct, it does work but needs the SIB byte because the [ESP] addressing isn't supported alone, only in the form [ESP+reg*index]. The 24 byte says that there is no register or index to add on.
 
  


Reply



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
IA-32 Architecture - Addressing - Question to ModR/M and SIB-Byte Yoko Programming 0 10-16-2004 08:08 AM
Byte Benchmarks kiwi_bloke Linux - Software 1 08-17-2004 12:07 AM
0 byte logs dsieme01 Linux - Security 5 07-22-2004 10:13 AM
C++ byte type exodist Programming 3 05-11-2004 05:02 PM
backup byte-for-byte axion0917 Linux - Software 2 12-11-2003 05:01 PM

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

All times are GMT -5. The time now is 05:18 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