flat assembler
Message board for the users of flat assembler.

Index > Windows > sar vs shr

Author
Thread Post new topic Reply to topic
yq8



Joined: 08 May 2015
Posts: 15
yq8
Yo,
I am trying to convert thsi line from masm to fasm syntax:

Code:
sar     DWORD PTR [ebp-48]    


I tried :

Code:
shr DWORD [ebp-48]    


but that won't do the job, how can I write this correctly?
Post 02 Jul 2015, 17:21
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
Where is # of bits to shift?
Should it be:
Code:
sar dword [ebp-48], #ofbits
    
Post 02 Jul 2015, 17:59
View user's profile Send private message Send e-mail Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
AsmGuru62 wrote:
Where is # of bits to shift?
Should it be:
Code:
sar dword [ebp-48], #ofbits
    
Probably defaults to the constant encoding so:
Code:
sar dword [ebp-48],1    
Question
Post 02 Jul 2015, 23:25
View user's profile Send private message Reply with quote
sunnysigil



Joined: 18 Jun 2014
Posts: 6
sunnysigil
yq8 wrote:
Yo,
I am trying to convert thsi line from masm to fasm syntax:

Code:
sar     DWORD PTR [ebp-48]    


I tried :

Code:
shr DWORD [ebp-48]    


but that won't do the job, how can I write this correctly?


sar and shr are not the same instruction since shr only shifts in 0s. sar is used when dealing with signed numbers as it will shift from the right side in 1's if negative or 0's if it's positive.
Post 21 Aug 2015, 11:20
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
There are differences between "shift logical right" (shr) and "shift arithmetical right" (sar). See manual.
Post 21 Aug 2015, 17:32
View user's profile Send private message Send e-mail Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 120
catafest
The sar instruction shifts all the bits in the destination operand to the right one bit.
I think you need to know that:
sar ax, 1 ;Signed division by 2
sar ax, 2 ;Signed division by 4
sar ax, 3 ;Signed division by 8
sar ax, 4 ;Signed division by 16
sar ax, 5 ;Signed division by 32
sar ax, 6 ;Signed division by 64
sar ax, 7 ;Signed division by 128
sar ax, 8 ;Signed division by 256
- sar truncates results toward the smaller result and idiv instruction always truncates towards zero!
- sar instruction lets you sign extend one register into another register of the same size, see this example:
mov cx, bx
sar cx, 15

I think your answer is this:

sar eax,10h
mov dword ptr [ebp-8],eax

tell me if I wrong ...
Post 27 Aug 2015, 20:20
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.