flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Roman 17 Aug 2023, 09:17
Variant counter to 999_999_999
Code: ;data align 16 intTxt db 16 dup(0) tdigs db '000000000 ' hjj1 db '0000000000000000' ;hjj2 db 16 dup(1) this wrong hjj2 db 1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1 ;this right afft db '::::::::::::::::' ;code macro Msg a { invoke MessageBox,0,a,0,0 } Start: movups xmm3,dqword [tdigs] mov ebx,999_999_999 .ew: movups xmm1,xmm3 ;dqword [tdigs] pextrb eax,xmm1,4+3+1 inc al pinsrb xmm1,eax,4+3+1 ;if rept 1 and ebx=500 int text= 4:0. If ebx=501 int txt= 501 rept 6+1 { movups xmm2,dqword [afft] PCMPGTB xmm2,xmm1 pand xmm1,xmm2 pmaxub xmm1,dqword [hjj1] psrldq xmm2,1 pandn xmm2,dqword [hjj2] paddb xmm1,xmm2 } movaps xmm3,xmm1 dec ebx jnz .ew movups dqword [intTxt], xmm1 mov word [intTxt+9],0 Msg intTxt |
|||
![]() |
|
Roman 17 Aug 2023, 09:51
another variant
Code: align 16 tdigs db '000000000 ' endianSwitch db 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 wrapper db 0C6h, 0C6h, 0C6h, 0C6h, 0C6h, 0C6h, 0C6h, 0C6h, 0C6h, 0C6h, 0C6h, 0C6h, 0C6h, 0C6h, 0C6h, 0C6h spaceCorrector db 10h, 10h, 10h, 10h, 10h, 10h, 10h, 10h, 10h, 10h, 10h, 10h, 10h, 10h, 10h, 10h wrapper10 db 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 carryMask db 0FFh, 0FFh, 0FFh, 0FFh, 0FFh, 0FFh, 0FFh, 0FFh, 7, 7, 7, 7, 7, 7, 7, 7 spaceDecector db '!', '!', '!', '!', '!', '!', '!', '!', '!', '!', '!', '!', '!', '!', '!', '!' intTxt db 32 dup(0) Start: movups xmm0, dqword [tdigs] mov ebx,11 ;for test i do loop ; pshufb xmm0, dqword [endianSwitch] ; switch little/big-endian .uppp: paddb xmm0, dqword [wrapper] ; shift digits from ASCII to wrapping edge ('0'->0F6h .. '9'->0FFh) ; increment low qword mov eax, 1 xorps xmm1, xmm1 movd xmm1, eax paddq xmm0, xmm1 ;psubq xmm0,xmm1 ; carry to high qword xorps xmm1, xmm1 pcmpeqb xmm1, xmm0 ; byte == 0 ? pshufb xmm1, dqword [ carryMask] ; mask = 0XX_XX_XX_XX_XX_XX_XX_XX_00_00_00_00_00_00_00_00h, where XX = byte7 psubq xmm0, xmm1 ; sub (-1) equivalent add 1 ; correct wrapped digits xorps xmm1, xmm1 pcmpeqb xmm1, xmm0 ; byte == 0 ? andps xmm1, dqword [wrapper10] psubb xmm0, xmm1 psubb xmm0, dqword [wrapper] ; shift digits back to ASCII-codes ; detect spaces affected by carry movaps xmm1, dqword [spaceDecector] pcmpeqb xmm1, xmm0 ; check for spaces under carry andps xmm1, dqword [spaceCorrector] ; shift such spaces (actually '!') to '1' paddb xmm0, xmm1 dec ebx jnz .uppp movaps xmm1,xmm0 pshufb xmm1, dqword [endianSwitch] movups dqword [intTxt], xmm1 Msg intTxt Last edited by Roman on 18 Aug 2023, 06:26; edited 2 times in total |
|||
![]() |
|
Roman 17 Aug 2023, 12:18
My variant 32 bit program. 32 bits regs store max value 4294967295
Code: align 16 tdigs db '70000000000 ' hjj1 db '0000000000000000' hjj2 db 1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1 afft db '::::::::::::::::' intTxt db 16 dup(0) Start: movups xmm3,dqword [tdigs] xorps xmm0,xmm0 ;replaced pextrb\pinsrb +50% faster mov eax,1 movd xmm5,eax pslldq xmm5,9 mov ebx,1_000_999_591 .ew: movaps xmm1,xmm3 ;pextrb eax,xmm1,4+3+2 ;inc al ;pinsrb xmm1,eax,4+3+2 paddb xmm1,xmm5 ;replaced pextrb\pinsrb +50% faster mov al,2 .et: movaps xmm2,dqword [afft] PCMPGTB xmm2,xmm1 pand xmm1,xmm2 pmaxub xmm1,dqword [hjj1] psrldq xmm2,1 pandn xmm2,dqword [hjj2] paddb xmm1,xmm2 comiss xmm2,xmm0 ja .et dec al jnz .et movaps xmm3,xmm1 dec ebx jnz .ew movups dqword [intTxt], xmm1 ;intTxt = '8000999591' mov word [intTxt+10],0 Msg intTxt ;easy changed int text to float mov eax,dword [intTxt+7] mov byte [intTxt+7],'.' mov dword [intTxt+8],eax mov word [intTxt+11],0 ;intTxt = '8000999.591' |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.