Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9319723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:27:20+00:00 2026-06-19T03:27:20+00:00

// Code I’ll be working with int shift_left2_rightn(int x, int n) { x <<=

  • 0
// Code I'll be working with
int shift_left2_rightn(int x, int n)
{
    x <<= 2;
    x >>= n;
    return x;
}

Question 1. Left shift = SAL and SHL. My book says they have the same effect. Then why are there two shift operations?

For example:

movl    8(%ebp), %eax    //Get x
_______                  //x <<= 2 

My book gives an answer of

sall    $2, %eax

would

shll    $2, %eax 

also been the correct answer?

Question 2:

In layman’s terms what is the difference between SHR and SAR? My book says one is a logical shift (fills with zeroes) and other is arithmetic shift (fills with copies of the sign bit).

Fills what with 0’s/sign bits?

For example:

How would I know which one to use with the following assembly instructions?

movl   12(%ebp), %ecx   //Get n
______                  //x >>=n

Back of the book has the answer

sarl   %cl, %eax 

Please explain to me what would happen if we used shrl.

Thanks for your help with understanding this!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T03:27:22+00:00Added an answer on June 19, 2026 at 3:27 am

    sal and shl are synonymous, they have identical opcodes.

    As sar does signed division by 2 rounding numbers towards negative infinity (-Inf), and shr does unsigned division by 2, probably engineers at Intel have decided to incorporate also both sal and shl even if they are synonymous.

    Here’s an example what shr and sar do:

    mov al,0b10001000 ; 0b10001000 = 136d = -120d (2's complement)
    
    shr al,1          ; 0b01000100 =  68d =   68d (2's complement)
    
    mov al,0b10001000 ; 0b10001000 = 136d = -120d (2's complement)
    
    sar al,1          ; 0b11000100 = 196d =  -60d (2's complement)
    

    So shr fills with zeroes, and sar fills with the sign bit.

    shr is for unsigned divisions or bit shifts in general, and sar for signed divisions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code: public IList<T> GetByMultipleIds(int[] ids) { List<T> result = _session.Linq<T>() .Where(x => ids.Contains(x.Id)).ToList(); return
Code: NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; BOOL initial = YES; [invocation setArgument:&initial atIndex:2]; Question:
Code sample for my question: IList<TestDataAnimal> testDataFromDb = this.db.TestDataAnimals.Include(t => t.TestType).Include(t => t.Visit).Include(t =>
Code looks like public void option() { seeTasks = tasks.getTasks(); for (int i =
Code: <%=#{time_ago_in_words(comment.created_at)} ago %> What i'd like is for it not to have ABOUT
I have this code to decode numeric html entities to the UTF8 equivalent character.
Code coverage is propably the most controversial code metric. Some say, you have to
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
Code in C: typedef struct{ int a; int b; }NODE; NODE *node; NODE* add(int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.