flat assembler
Message board for the users of flat assembler.

Index > Main > MMX convert text to byte value.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 2132
Roman 08 Sep 2026, 16:38
I write code but its big code. I want three or 4 asm commands.
Code:
txtV db '16' ; i have many numbers
intV db 0

tt2 db 48,48,48,48
tt3 db 10,0,0,0 

;do some mmx operations and get intV=16

movd mm0,dword [txtV]
psubb mm0,qword [tt2]
movd ecx,mm0
pmullw mm0,qword[tt3]
movd eax,mm0
add al,ch 
mov [intV],al ;intV=16

    
Post 08 Sep 2026, 16:38
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2132
Roman 08 Sep 2026, 18:12
Code:
ttt db '16'
intV db 0

        sub word [ttt],0x3030
        movzx eax,byte [ttt]
        imul eax,10
        add al,[ttt+1]
        mov [intV],al
    
Post 08 Sep 2026, 18:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 21097
Location: In your JS exploiting you and your system
revolution 08 Sep 2026, 18:30
Dor the limited set of two digit bcd inputs.
Code:
mov ax,word[bcd]
sub ax,'00'
imul ax,0x10a
mov [result],ah

bcd db '16'
result db ?    
There ia also aad designed exactly for this task.
Post 08 Sep 2026, 18:30
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2132
Roman 08 Sep 2026, 18:50
Quote:

mov ax,word[bcd]
sub ax,'00'
imul ax,0x10a
mov [result],ah

Wrong result.
Post 08 Sep 2026, 18:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 21097
Location: In your JS exploiting you and your system
revolution 08 Sep 2026, 18:53
Wrong multiplier.
Code:
mov ax,word[bcd]
sub ax,'00'
imul ax,0xa01
mov [result],ah

bcd db '16'
result db ?    
Post 08 Sep 2026, 18:53
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2132
Roman 08 Sep 2026, 19:12
Intel was supposed to do it this way AAD
Code:
aad al,ah,0x30  ;= sub al,0x30 and sub ah,0x30 and p1*10+p2.  p1=al and p2=ah
    
Post 08 Sep 2026, 19:12
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2132
Roman 09 Sep 2026, 07:04
from 0 to 9999
Code:
ttt db '4687'
intVal dw 0

        movzx eax,word [ttt]
        sub ax,'00'
        imul ax,0xa01
        sub al,al
        imul eax,100

        movzx ecx,word [ttt+2]
        sub cx,'00'
        imul cx,0xa01
        sub cl,cl
        add eax,ecx     ;as integer value. EAX=0x00124F00
        shr eax,8
        mov [intVal],ax ;eax=4687
    
Post 09 Sep 2026, 07:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 21097
Location: In your JS exploiting you and your system
revolution 09 Sep 2026, 12:09
Now convert to MMX
Post 09 Sep 2026, 12:09
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2132
Roman 09 Sep 2026, 13:45
Quote:
Now convert to MMX

I not any idea how do this.
especially this imul ax,0xa01
Post 09 Sep 2026, 13:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 21097
Location: In your JS exploiting you and your system
revolution 09 Sep 2026, 14:15
Roman wrote:
... imul ax,0xa01
PMULLW
Post 09 Sep 2026, 14:15
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2132
Roman 09 Sep 2026, 16:24
I do this but code size as prevision
Code:
 tt db '4687'  ;this variant good for two numbers like as '4687' and '1635'
 tt2 db 48,48,48,48
 tt3 dw 0xa01,0xa01
 tt4 db 0,255,0,255,0,0,0,0
result dd 0,0


     movd mm0,dword [tt]
     psubb mm0,qword [tt2]
     pmullw mm0,qword[tt3]
     pand mm0,qword [tt4]
     movd ecx,mm0
     shr ecx,8
     movzx eax,cl
     imul eax,100
     shr ecx,16
     add ax,cx              ;eax=4687

;second variant
     movd   mm0,dword [tt]
     psubb  mm0,qword [tt2]
     pmullw mm0,qword[tt3]
     pand mm0,qword [tt4]
     movq qword [result],mm0
     movzx eax,byte [result+1]
     imul eax,100
     add ax,word [result+3]    ;eax=4687

;theerd variant
 tt db '96878687'
 tt2 db 48,48,48,48, 48,48,48,48
 tt3 dw 0xa01,0xa01,0xa01,0xa01         
 tt4 db 0,255,0,255,0,255,0,255

 
     movq mm0,qword [tt]
     psubb mm0,qword [tt2]
     pmullw mm0,qword[tt3]
     pand mm0,qword [tt4]
     movq qword [result],mm0
     movzx eax,byte [result+1]
     imul eax,100
     add ax,word [result+3]
     imul eax,10000

     movzx ecx,byte [result+5]
     imul ecx,100
     add cx,word [result+7]

     add eax,ecx ;eax=96878687 integer
    


Last edited by Roman on 11 Sep 2026, 05:37; edited 7 times in total
Post 09 Sep 2026, 16:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 21097
Location: In your JS exploiting you and your system
revolution 09 Sep 2026, 16:50
Multiplying the constant 100 can be done inside MMX.
Post 09 Sep 2026, 16:50
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-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.