Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 24th, 2012, 08:29 AM
jakotheshadows's Avatar
jakotheshadows jakotheshadows is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 149 jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 12 h 1 m 16 sec
Reputation Power: 35
Homework: Jump Tables and Switch Cases x86 64

I'm stuck on a problem where I have to provide x86 code for a switch statement given in C. My instructor gives an example in one of his lectures, but I am having difficulty understanding this example. We use Red Hat Linux for this course.



In the first section (which is red)
The code checks if a is less than 1, and jumps to the default if it is which makes sense.

In the second section (which is green)
The code checks if a is greater than 4, and jumps to the default if it is which makes sense.

In the third section (which is red)
.T gets put into register %rbx
1 is subtracted from the register, %eax, which has a (why?)
8 is put into %ecx
the product 8 * (a - 1) is stored into %eax (why?)

The instruction "movslq" is used, but I do not know what it does. I've used movl and the conditional move instructions, but I'm not quite sure what movslq is and am having a hard time finding this out with google.

And everything after that point is uncertain to me because I do not understand why some things are being done, for the most part, or what movslq does.
Attached Images
File Type: png jumpTable.png (45.6 KB, 143 views)

Reply With Quote
  #2  
Old October 24th, 2012, 08:51 AM
OmegaZero OmegaZero is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2007
Posts: 737 OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 57 m 45 sec
Reputation Power: 928
Quote:
Originally Posted by jakotheshadows
1 is subtracted from the register, %eax, which has a (why?)
.T is an array and EAX will be used to index that array. But EAX contains a value in 1..4 instead of starting at 0.

Quote:
Originally Posted by jakotheshadows
8 is put into %ecx
the product 8 * (a - 1) is stored into %eax (why?)
The elements of .T are quads (8 bytes long). Presumably your instructor wants to show you explicitly how you index an array rather than using the indexing constructs.

Quote:
Originally Posted by jakotheshadows
The instruction "movslq" is used, but I do not know what it does.
EAX is a 32-bit register, RAX is a 64-bit register. So you need an instruction that extends a 32-bit value to a 64-bit one for this operation. MOVSLQ is move and sign-extend a value from a 32-bit source to a 64-bit destination.
Comments on this post
jakotheshadows agrees: Thanks for the quick reply!
__________________
sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Homework: Jump Tables and Switch Cases x86 64

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap