flat assembler
Message board for the users of flat assembler.

Index > Main > Shift sequence of bytes.

Author
Thread Post new topic Reply to topic
Rubyko



Joined: 03 Mar 2017
Posts: 6
Rubyko 04 Mar 2017, 05:44
Hello. How to right or left shift a sequence of bytes by specified N bits effectively? Suggestions ?
Post 04 Mar 2017, 05:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20461
Location: In your JS exploiting you and your system
revolution 04 Mar 2017, 06:28
Have a look at shld and shrd. You can chain them together to make multiple {q|d}word shifts. If the shift amount is more than 32 bits (or 64 bits for 64-bit code) then shift by whole units and add the sh{l|r}d to the last few bits.
Post 04 Mar 2017, 06:28
View user's profile Send private message Visit poster's website Reply with quote
Rubyko



Joined: 03 Mar 2017
Posts: 6
Rubyko 04 Mar 2017, 09:25
Yes, it might work. Thank you.
Post 04 Mar 2017, 09:25
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4081
Location: vpcmpistri
bitRAKE 04 Mar 2017, 16:01
The FASMG source code has a routine to do multi-byte shift.

See EXPRESSIONS.INC, shift_term_value_left: and shift_term_value_right:

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 04 Mar 2017, 16:01
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 04 Mar 2017, 16:30
bitRAKE wrote:
The FASMG source code has a routine to do multi-byte shift.

See EXPRESSIONS.INC, shift_term_value_left: and shift_term_value_right:
These routines are sub-optimal for larger inputs, since they shift just a single byte per loop iteration. But I preferred to keep them simple, as optimizing them would have little effect on the overall performance of the assembler. For longer inputs SHLD/SHRD are probably a good recommendation. And fasm 1 uses SHLD/SHRD in its SHL/SHR operators implementation.
Post 04 Mar 2017, 16:30
View user's profile Send private message Visit poster's website 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.