It is currently Sat Jan 23, 2021 1:55 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: ROL with 2 variables
PostPosted: Thu Apr 21, 2016 3:45 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 673
Hi!

Question to the experts:

How can I use "ROL" with two variables?

Background: I saw this little piece of code (part) here:
viewtopic.php?p=258937

Code:
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : LightWeightEncryptString
; File : LightWeightEncryptString.pb
; File Version : 1.0.0
; Programmation : OK
; Programmed by : Hroudtwolf
; Modified by : Guimauve
; Date : 09-10-2008
; Last Update : 31-03-2009
; Coded for PureBasic V4.30
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Enumeration
 
  #LIGHTWEIGHT_ENCRYPT
  #LIGHTWEIGHT_DECRYPT
 
EndEnumeration

Procedure.c Private_RotateChar(Value.c, Direction.b)
 
  Select Direction
     
    Case #LIGHTWEIGHT_ENCRYPT
      CompilerIf #PB_Compiler_Unicode
        ! rol word [p.v_Value], 2
      CompilerElse
        ! rol byte [p.v_Value], 2
      CompilerEndIf
     
    Case #LIGHTWEIGHT_DECRYPT
      CompilerIf #PB_Compiler_Unicode
        ! ror word [p.v_Value], 2
      CompilerElse
        ! ror byte [p.v_Value], 2
      CompilerEndIf
     
  EndSelect
 
  ProcedureReturn Value
EndProcedure
;---- snip ----

This question
Quote:
is it possible, to change the fixed amount of roled bits (=1) to a dynamic value (e.g. in dependency of the character position)?

was answered
Quote:
2) Yes, of course. Just change the 2nd operand of ROL/ROR to a variable.

But how is this done?
I tried
"! rol byte [p.v_Value], byte [p.v_Bits]",
"! rol byte [p.v_Value], [p.v_Bits]" and
"! rol byte [p.v_Value], p.v_Bits"
with "Bits.b" as extra argument for calling the Procedure:
Quote:
Procedure.c Private_RotateChar(Value.c, Direction.b, Bits.b)

What is the correct way?

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: ROL with 2 variables
PostPosted: Thu Apr 21, 2016 3:56 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
You can either rotate by an immediate value or by cl (the low byte of the rcx/ecx register).
Code:
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : LightWeightEncryptString
; File : LightWeightEncryptString.pb
; File Version : 1.0.0
; Programmation : OK
; Programmed by : Hroudtwolf
; Modified by : Guimauve
; Date : 09-10-2008
; Last Update : 31-03-2009
; Coded for PureBasic V4.30
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Enumeration
 
  #LIGHTWEIGHT_ENCRYPT
  #LIGHTWEIGHT_DECRYPT
 
EndEnumeration

Procedure.c Private_RotateChar(Value.c, Direction.b, Bits.b)
 
  Select Direction
     
    Case #LIGHTWEIGHT_ENCRYPT
      !movzx ecx, byte [p.v_Bits]
      CompilerIf #PB_Compiler_Unicode
        ! rol word [p.v_Value], cl
      CompilerElse
        ! rol byte [p.v_Value], cl
      CompilerEndIf
     
    Case #LIGHTWEIGHT_DECRYPT
      !movzx ecx, byte [p.v_Bits]
      CompilerIf #PB_Compiler_Unicode
        ! ror word [p.v_Value], cl
      CompilerElse
        ! ror byte [p.v_Value], cl
      CompilerEndIf
     
  EndSelect
 
  ProcedureReturn Value
EndProcedure
;---- snip ----

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: ROL with 2 variables
PostPosted: Thu Apr 21, 2016 5:16 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 04, 2015 7:10 am
Posts: 1672
wilbert wrote:
You can either rotate by an immediate value or by cl (the low byte of the rcx/ecx register).

lol i hate ones like that!!! let you use ecx for example but not eax, so sometimes its led me to believe im trying to do the impossible when its perfectly possible if i just read the damn manual to use the correct register, lol. now though if eax fails to compile i just quickly try ecx/edx/esi/edi, whew... getting there! :)

_________________
Thankyou to all the coders who generously helped & encouraged me in the nearly 2yrs when i was welcome here,
it was a tremendous privilege. I learned a lot. I wish you and your families all the best and success for the future.


Top
 Profile  
Reply with quote  
 Post subject: Re: ROL with 2 variables
PostPosted: Thu Apr 21, 2016 7:14 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 673
Hello wilbert!

Thank you for showing me the right way (in the dark [of assembler])! :D
It works like a charme.

_________________
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye