NO

Recent Posts

Pages: 1 [2] 3 4 ... 10
11
Assembly discussions / Re: Trimming spaces and tabs inside a string
« Last post by Vortex on June 16, 2024, 03:39:40 PM »
Loop with shorter instructions :

Code: [Select]
.686
.model flat,stdcall
option casemap:none

ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG

includelib  \PellesC\lib\Win\kernel32.lib
includelib  \PellesC\lib\Win\user32.lib
includelib  msvcrt.lib

.data

mystr       db '    This    Is   A       Test String.',0
message     db 'Trimmed string = %s',13,10
            db 'Length of the string = %u',0

.data?

buffer      db 64 dup(?)

.code

RemoveSpaces PROC uses ebx str1:DWORD,buff:DWORD

    mov     ecx,str1
    mov     edx,buff
    xor     ebx,ebx
@@:
    movzx   eax,BYTE PTR [ecx]
    mov     BYTE PTR [edx],al
    add     ecx,1

    xor     al,32
    setnz   ah
    xor     al,41
    setnz   bl
    and     bl,ah
    add     edx,ebx

    cmp     al,9
    jnz     @b

finish:

    mov     eax,edx
    sub     eax,1
    sub     eax,buff
    ret

RemoveSpaces ENDP

start:

    invoke  RemoveSpaces,ADDR mystr,ADDR buffer
    invoke  printf,ADDR message,ADDR buffer,eax
    invoke  ExitProcess,0

END start
12
Beginner questions / Question about sqlite max AND min
« Last post by timharvey on June 16, 2024, 02:18:38 PM »
Hello, Normally Max and Min will be used like this SELECT MIN([C1]) AS Mini,MAX([C2)) AS Maxi FROM [MyTable]. But with many records, the output results take a long time.

Is there any use for faster retrieval? Thank
13
Assembly discussions / Re: Trimming spaces and tabs inside a string
« Last post by John Z on June 16, 2024, 11:32:24 AM »
Hi John,

You are welcome. I uploaded another version without the lookup table :

https://forum.pellesc.de/index.php?topic=11196.msg39303#msg39303

Vortex - That version is very innovative and showing brain power! 

John Z
14
Assembly discussions / Re: Trimming spaces and tabs inside a string
« Last post by Vortex on June 15, 2024, 04:48:20 PM »
Hi John,

You are welcome. I uploaded another version without the lookup table :

https://forum.pellesc.de/index.php?topic=11196.msg39303#msg39303
15
Assembly discussions / Re: Trimming spaces and tabs inside a string
« Last post by John Z on June 15, 2024, 10:04:46 AM »
Hi John,
Can you try the new version below?

great! Thanks Vortex for showing it and indulging my inexperience/out-of-date knowledge.

Advanced new processors are able to compute branch predictions to mitigate the problem, but the point remain substantially "avoid any branch" to speed-up execution.

Thanks frankie - great explanation

John Z
16
Assembly discussions / Re: Trimming spaces and tabs inside a string
« Last post by frankie on June 14, 2024, 01:37:16 PM »
Today Intel processors, operating with super-scalar and hyper-threading technologies, instructions are pipelined and executed in parallel when possible.
To speed-up memory access data and instructions are pre-loaded in the fast-speed caches, where are also stored intermediate computation.
The execution pipeline is filled fetching instructions from the address cache while the processor logic assemble the flow for parallel (scalar/super-scalar) execution in the ALU.
In this scenario the caches holds a snapshot of memory accesses and the instruction pipeline a snapshot of what would be the execution flow, with the advantage of fast exchange with ALU and CPU registers. The caches are loaded/stored to physical slower memory transparently to the execution (in burst mode with multiword simultaneous transfers). This whole process contributes to faster execution.
Then what happen to cache contents and especially to the pipelines when a branch, following a comparison, is encountered? We have 2 options, if the flow will follow the instructions already cached the CPU will continue processing at full speed, but in the other case the processor stops while the pipeline is flushed and reloaded after caches refresh with the new instructions flow.
In the last case we loose all the advantages we had using instructions and data caching (eventually pre-calculated data in the wrong branch).
Advanced new processors are able to compute branch predictions to mitigate the problem, but the point remain substantially "avoid any branch" to speed-up execution.

Now it should be evident that the use of table with only one comparison, hopefully expecting that the pipelining can define the compare address in advance storing the value in cache before its use, is the fastes way to do this job.
17
Assembly discussions / Re: Trimming spaces and tabs inside a string
« Last post by Vortex on June 13, 2024, 11:03:00 PM »
Hi John,

Quote
wouldn't you want to check first if the character was less than 33?

Can you try the new version below?

Code: [Select]
.386
.model flat,stdcall
option casemap:none

ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG

includelib  \PellesC\lib\Win\kernel32.lib
includelib  \PellesC\lib\Win\user32.lib
includelib  msvcrt.lib

.data

mystr       db '    This    Is   A       Test String.',0
message     db 'Trimmed string = %s',13,10
            db 'Length of the string = %u',0

.data?

buffer      db 64 dup(?)

.code

RemoveSpaces PROC uses ebx str1:DWORD,buff:DWORD

    mov     ecx,str1
    mov     edx,buff
    mov     ebx,33
@@:
    movzx   eax,BYTE PTR [ecx]
    mov     BYTE PTR [edx],al

    add     ecx,1
    cmp     ebx,eax
    adc     edx,0
    test    eax,eax
    jnz     @b

finish:

    mov     eax,edx
    sub     eax,buff
    ret

RemoveSpaces ENDP

start:

    invoke  RemoveSpaces,ADDR mystr,ADDR buffer
    invoke  printf,ADDR message,ADDR buffer,eax
    invoke  ExitProcess,0

END start
18
Assembly discussions / Re: Trimming spaces and tabs inside a string
« Last post by John Z on June 13, 2024, 10:47:52 AM »
frankie, Vortex

Thanks for clearing up the table usage.  I just thought a bit unusual for just two checks.  I used a similar method (table) in C to build my Base 64 encoder/decoder.  Wanted to ask to be sure I was understanding the assembly and not missing something.  It has been a while (pre 486  ;D )

Vortex,  in your versions w/o the table - wouldn't you want to check first if the character was less than 33? This should speed up the code because most of the 255 characters would only need one check while 32 need two checks, if I grok the code that is.

Thanks for the inputs.

John Z

19
Assembly discussions / Re: Trimming spaces and tabs inside a string
« Last post by Vortex on June 12, 2024, 09:04:42 PM »
Here is another version without the lookup table :

Code: [Select]
.686
.model flat,stdcall
option casemap:none

ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG

includelib  \PellesC\lib\Win\kernel32.lib
includelib  \PellesC\lib\Win\user32.lib
includelib  msvcrt.lib

.data

mystr       db '    This    Is   A       Test String.',0
message     db 'Trimmed string = %s',13,10
            db 'Length of the string = %u',0

.data?

buffer      db 64 dup(?)

.code

RemoveSpaces PROC uses ebx str1:DWORD,buff:DWORD

    mov     ecx,str1
    mov     edx,buff
@@:
    movzx   eax,BYTE PTR [ecx]
    mov     BYTE PTR [edx],al

    add     ecx,1

    mov     ebx,eax
    xor     ebx,32
    xor     eax,9
    and     ebx,eax
    add     ebx,0FFFFFFFFh
    adc     edx,0

    cmp     eax,9
    jnz     @b

finish:

    mov     eax,edx
    sub     eax,buff
    ret

RemoveSpaces ENDP

start:

    invoke  RemoveSpaces,ADDR mystr,ADDR buffer
    invoke  printf,ADDR message,ADDR buffer,eax
    invoke  ExitProcess,0

END start
20
Assembly discussions / Re: Trimming spaces and tabs inside a string
« Last post by Vortex on June 11, 2024, 08:07:37 PM »
Hello,

With today's hardware capacity, a lookup table of 256 bytes should not be an issue. The purpose of using assembly is to optimize code especially where execution speed matters. The lookup table avoids exta jumps and you need only one jmp instruction here. Notice that you can use the same code above with some small modifications in the lookup table to remove more unnecessary characters.
Pages: 1 [2] 3 4 ... 10