flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > how count bits in macro ?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 07 May 2025, 07:29
fasmw 1.73
I want get last set-up bit.
For example 01001 last bit number is 3

Code:
;analog asm command bsr
macro getBtNum v { ... }

;in code
getBtNum 32 ;must get 5 bit
getBtNum 1 ;must get 0 bit
getBtNum 8 ;must get 3 bit
    


Last edited by Roman on 07 May 2025, 08:09; edited 1 time in total
Post 07 May 2025, 07:29
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20625
Location: In your JS exploiting you and your system
revolution 07 May 2025, 07:42
bsr
Code:
display bsr 01001b + '0'

flat assembler  version 1.73.31  (16384 kilobytes memory)
3
1 passes, 0 bytes.    
Post 07 May 2025, 07:42
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 07 May 2025, 08:10
fasmw supported bsr ! wow ! Its cool.
Thanks.
Post 07 May 2025, 08:10
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 07 May 2025, 08:51
How about ror in fasmw macro?
Or how implement ror in fasmw macro?
Post 07 May 2025, 08:51
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 07 May 2025, 08:57
Roman wrote:
How about ror in fasmw macro?
Code:
a = 7 shl 3
n = 3
a = 0xFFFFFFFF and (a shl (32-n)) and (a shr n) ; 32-bit ror
display a + '0', 13, 10

b = 1048576
k = 10
b = 0xFFFFFFFFFFFFFFFF and (b shr (64-k)) and (b shl k) ; 64-bit rol

c = 1 shl 32
i = 24
if i < 38
  c = 0x7FFFFFFFFF and (c shl (39-i)) and (c shr i) ; 39-bit ror
end if    
Post 07 May 2025, 08:57
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 07 May 2025, 09:15
I get zero.
Code:
n = 3
v = 6025
__@v1 = 0xFFFFFFFF and (v shl (32-n)) and (v shr n)
mov ecx,__@v1 ; get zero    


must be 0x78900001
Post 07 May 2025, 09:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20625
Location: In your JS exploiting you and your system
revolution 07 May 2025, 09:20
The shr and shl parts need to be ored together, then and with the 0xffffffff mask.
Post 07 May 2025, 09:20
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 07 May 2025, 09:27
Code:
macro display_int x { local ..u, ..v
  ..v = x
  ..u = 1
  while ..u < ..v
    ..u = ..u * 10
  end while
  if ..v = 0
    display '0'
  else
    while ..u > 1
      ..u = ..u / 10
      display '0' + ..v / ..u
      ..v = ..v - ..u * ( ..v / ..u )
    end while
  end if
  display ' '
}

a = 6020
n = 3
BIT_MASK = 0xFFFFFFFF
BIT_LENGTH = 32
a = ( BIT_MASK AND ( a shr ( BIT_LENGHT - n + 1 ))) OR ( BIT_MASK AND ( a shl n ))
display_int a
mov ecx, a    
Code:
48160    


Last edited by macomics on 07 May 2025, 10:08; edited 1 time in total
Post 07 May 2025, 09:27
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 07 May 2025, 09:32
Thanks.
How about rol ?


Last edited by Roman on 07 May 2025, 09:35; edited 1 time in total
Post 07 May 2025, 09:32
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 07 May 2025, 09:34
Roman wrote:
must be 0x78900001
n=3 ; bits => must be 0x1784 shl 3 = 0xBC20
Post 07 May 2025, 09:34
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 07 May 2025, 09:36
macomics
How about rol ?
Post 07 May 2025, 09:36
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 07 May 2025, 09:39
Code:
use64
macro display_int x { local ..u, ..v
  ..v = x
  ..u = 1
  while ..u < ..v
    ..u = ..u * 10
  end while
  if ..v = 0
    display '0'
  else
    while ..u > 1
      ..u = ..u / 10
      display '0' + ..v / ..u
      ..v = ..v - ..u * ( ..v / ..u )
    end while
  end if
  display ' '
}

a = 6025
n = 12
BIT_MASK   = 0x7FFFFFFFFF
BIT_LENGTH = 1 + bsr BIT_MASK
a = ( BIT_MASK AND ( a shl ( BIT_LENGTH - n + 1 ))) OR ( BIT_MASK AND ( a shr n ))
display_int a
mov rcx, a    

Code:
517811994625    
or 0x7890000001


Last edited by macomics on 07 May 2025, 10:08; edited 1 time in total
Post 07 May 2025, 09:39
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 07 May 2025, 09:45
Roman wrote:
How about rol ?
rol and ror
Post 07 May 2025, 09:45
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 07 May 2025, 09:47
ror wrong result.
Code:
n = 12
v = 6025
__@v1 = ( 0xFFFFFFFF AND ( v shr ( 32 - n ))) OR ( 0xFFFFFFFF AND ( v shl n ))
  
    

I get 1789000h but must be 7890001h
Post 07 May 2025, 09:47
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 07 May 2025, 09:50
Roman wrote:
ror wrong result.
correct


Last edited by macomics on 07 May 2025, 10:14; edited 2 times in total
Post 07 May 2025, 09:50
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 07 May 2025, 09:51
macomics
Try for ror
n = 12
a = 6025
Post 07 May 2025, 09:51
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 07 May 2025, 10:02
Roman wrote:
Try
n = 12
v = 6025
correct


Last edited by macomics on 07 May 2025, 10:14; edited 1 time in total
Post 07 May 2025, 10:02
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 07 May 2025, 10:03
It is 39-bit ror. Use BIT_MASK = 0xFFFFFFFF for 32-bit and BIT_MASK = 0xFFFFF for 20-bit
Post 07 May 2025, 10:03
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 07 May 2025, 10:12
Code:
use64
macro display_int x { local ..u, ..v
  ..v = x
  ..u = 1
  while ..u < ..v
    ..u = ..u * 10
  end while
  if ..v = 0
    display '0'
  else
    while ..u > 1
      ..u = ..u / 10
      display '0' + ..v / ..u
      ..v = ..v - ..u * ( ..v / ..u )
    end while
  end if
  display ' '
}

a = 6025
n = 12
BIT_MASK   = 0x7FFFFFFFFF
BIT_LENGTH = 1 + bsr BIT_MASK
a = ( BIT_MASK AND ( a shl ( BIT_LENGTH - n + 1 ))) OR ( BIT_MASK AND ( a shr n ))
display_int a
mov rcx, a     
Code:
517811994625    
That's not how I count the bits in the calculator. That's right


Description:
Filesize: 124.23 KB
Viewed: 652 Time(s)

Снимок экрана_20250507_141037.png


Post 07 May 2025, 10:12
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 07 May 2025, 10:14
I do this for ror:

Code:
use32
n = 12
v = 6025
BIT_MASK = 0xFFFFFFFF 
__@v1 = ( BIT_MASK AND ( v shr ( 1 + bsr BIT_MASK - n ))) OR ( BIT_MASK AND ( v shl n ))
mov eax,__@v1 ;IDA Pro show 1789000h
    

I get 1789000h but must be 78900001h
Code:
mov eax,6025
ror eax,12 ;IDA Pro show 78900001h
    
Post 07 May 2025, 10:14
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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.