flat assembler
Message board for the users of flat assembler.

Index > Main > [Solved]BEXTR crash

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 01 May 2023, 18:39
Fasmw 1.73
Windows 10
Ryzen 5 3500
Code:
;program 32 bit. Intel write BEXTR support in 32 and 64 bit
format PE GUI 4.0  

BEXTR eax,ebx,2 ;compiled but crash. IDA Pro show not BEXTR show garbage db
    


Ida show this,but not show BEXTR
db 8Fh
dd 0C31078EAh, 1, 401000A3h, 6A006A00h, 10006800h, 6A0040h
dd 208015FFh, 6A0040h, 7E8006Ah, 44000000h, 20656E6Fh


Last edited by Roman on 02 May 2023, 09:10; edited 2 times in total
Post 01 May 2023, 18:39
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 913
Location: Russia
macomics 01 May 2023, 18:53
Intel SDM 2a wrote:
Code:
Opcode/Instruction       Op/En  64/32    CPUID  Description
                                -bit    Feature
                                Mode     Flag
VEX.LZ.0F38.W0 F7 /r      RMV   V/V      BMI1   Contiguous bitwise extract from
BEXTR r32a, r/m32, r32b                         r/m32 using r32b as control;
                                                store result in r32a.
VEX.LZ.0F38.W1 F7 /r      RMV   V/N.E.   BMI1   Contiguous bitwise extract from
BEXTR r64a, r/m64, r64b                         r/m64 using r64b as control;
                                                store result in r64a.    

Code:
BEXTR eax,ebx,edx ; = BEXTR eax,ebx,2    


Last edited by macomics on 01 May 2023, 18:55; edited 1 time in total
Post 01 May 2023, 18:53
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 01 May 2023, 18:55
BEXTR eax,ebx,edx work !

But why compiled BEXTR eax,ebx,2 ?
Post 01 May 2023, 18:55
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 913
Location: Russia
macomics 01 May 2023, 19:07
This is not the instruction that fasm encoded
Code:
use32
BEXTR eax, ebx, 2

nop
nop
nop

BEXTR eax, ebx, edx    

Code:
$ fasm test.asm -m 1024
flat assembler  version 1.73.30  (1024 kilobytes memory)
1 passes, 17 bytes.    


Description:
Filesize: 14.33 KB
Viewed: 2072 Time(s)

Screenshot_20230501_220241.png


Post 01 May 2023, 19:07
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 01 May 2023, 19:15
Code:
mov       eax,0
mov       ebx,'tom1'
mov       edx,1024*8
BEXTR     eax,ebx,edx ;eax='tom1'

mov       eax,0
mov       ebx,'tom1'
mov       edx,1024*2
BEXTR     eax,ebx,edx ;eax='t',0,0,0
    

I not understand how get to eax='om1',0 ?
Post 01 May 2023, 19:15
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8344
Location: Kraków, Poland
Tomasz Grysztar 01 May 2023, 19:20
The immediate variant of BEXTR is part of the TBM extension, not supported by new CPUs.
Post 01 May 2023, 19:20
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 913
Location: Russia
macomics 01 May 2023, 19:22
Try
Code:
mov ebx, 'tom1'
mov edx, 8+24*256
bextr eax, ebx, edx    

or (simple)
Code:
mov ebx, 'tom1'
mov dl, 8 ; start
mov dh, 24; len
bextr eax, ebx, edx    
Post 01 May 2023, 19:22
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 01 May 2023, 19:27
Ha ! I do this !
Code:
mov       eax,0
mov       ebx,'tom1'
mov       edx,1024*7+8
BEXTR     eax,ebx,edx ;eax= "om1",0
    



Thanks. This is good explanation:
mov dl, 8 ; start
mov dh, 24; len. One char is 8. If we want get two chars dh=16
Post 01 May 2023, 19:27
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 01 May 2023, 19:35
Strange this.
Code:
mov       eax,'toke'
mov       ebx,'tom1'              
mov       dl,8 ;start
mov       dh,24-8 ;len
BEXTR     eax,ebx,edx ;eax='om' but not 'omke'. 
;BEXTR reset in eax,4 bytes and than copy.
or        eax,'  ke' ;eax='omke'
    
Post 01 May 2023, 19:35
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 913
Location: Russia
macomics 01 May 2023, 20:34
Code:
mov eax, 'toke'
mov ebx, 'tom1'
ror ebx, 8
shl eax, 16
shrd eax, ebx, 16 ; eax = 'omke'
rol ebx, 8    
Post 01 May 2023, 20:34
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 02 May 2023, 04:42
Replaced bextr variant
Code:
mov eax, 'toke'
mov ebx, 'tom1'
and eax, 0xffff0000
and ebx, 0x00ffff00
shr ebx, 8
or eax, ebx ;eax='omke' 

    
Post 02 May 2023, 04:42
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.