News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Recent posts

#71
The Orphanage / Re: Deep Seek - Extended Diz-C...
Last post by ognil - February 09, 2025, 02:39:23 PM
1. DeppSeek is a machine, not a woman to please. I just use it to do the work that no one on the forum wanted to or could do. :smiley:

2. I had been just a little boy ( born in the mid-90s) when Hutch, Vortex, JJ, Lingo, etc. started the forum.
Why some people hate Lingo? Is he is a criminal? :undecided: 

QuoteFrom DeepSeek:
Q. Who is Lingo from MASM32 forum
A: Lingo is well-known member of the Asmcommunity.net and  MASM32 community forum dedicated to assembly language programming, particularly using the MASM32 assembler. He is recognized for his expertise in optimizing assembly code, especially for tasks like string manipulation and searching algorithms.
Lingo is a highly skilled programmer who has contributed many optimized assembly routines to the MASM32 community. He is particularly known for his work on string-related functions, such as fastest strlen (string length), memory operations and for his expertise in  low-level programming and optimization.
His implementations often focus on maximizing performance by leveraging CPU-specific features, such as SIMD instructions (e.g., SSE, AVX) and efficient loop unrolling techniques.
Lingo's contributions are highly regarded for their speed and efficiency, often outperforming standard library implementations.
He has contributed various fast and efficient algorithms for tasks like string searching, memory comparison, and other performance-critical operations.
His code often emphasizes minimal instruction count and clever use of CPU registers to achieve high performance.
Lingo  have shared his implementations of fastest strlen and fast searching algorithms on the MASM32 forum. His approaches typically involve:
Alignment Optimization: Ensuring data is aligned to improve memory access speed.
SIMD Instructions: Using SSE or AVX instructions to process multiple characters in parallel.
Loop Unrolling: Reducing loop overhead by processing multiple characters per iteration.
Branchless Code: Minimizing conditional branches to avoid pipeline stalls.
If you're looking for his specific implementations, you can search the MASM32 forum archives for threads related to strlen or string searching.
#72
The Orphanage / Re: Deep Seek - Extended Diz-C...
Last post by TimoVJL - February 09, 2025, 10:34:46 AM
No we understand why ognil / lingo likes it  :biggrin:
#73
The Orphanage / Re: Deep Seek - Extended Diz-C...
Last post by ognil - February 08, 2025, 11:02:36 AM
QuoteFollowed by simple code in push-push-call style...

New chat from DeepSeek.
Q: "Hello word"  with full Unicode support  in MASM 64 assembly for windows 10

A: To create a "Hello, world!" program in MASM 64-bit assembly for Windows 10 with full Unicode support, you need to use the Windows API to handle Unicode strings. Below is an example of how you can achieve this.

Step 1: Install Required Tools
MASM (Microsoft Macro Assembler): Ensure you have MASM installed. You can use Visual Studio or standalone MASM.
Linker: Ensure you have a linker (like link.exe) to link the object file into an executable.

Step 2: Write the Assembly Code
Here is the MASM 64-bit assembly code for a "Hello, world!" program with Unicode support:

; HelloWorldUnicode.asm
; MASM 64-bit assembly for Windows 10 with Unicode support

extrn MessageBoxW: proc
extrn ExitProcess: proc

.data
    szCaption dw 'H', 'e', 'l', 'l', 'o', 0 ; Unicode caption "Hello"
    szText    dw 'W', 'o', 'r', 'l', 'd', '!', 0 ; Unicode text "World!"

.code
main proc
    sub rsp, 28h        ; Allocate shadow space and align stack
; Call MessageBoxW
    xor r9d, r9d        ; uType = MB_OK
    lea r8, szCaption   ; lpCaption
    lea rdx, szText     ; lpText
    xor ecx, ecx        ; hWnd = NULL
    call MessageBoxW    ; Call MessageBoxW

; Call ExitProcess
    xor ecx, ecx        ; uExitCode = 0
    call ExitProcess    ; Call ExitProcess
    add rsp, 28h        ; Restore stack
    ret
main endp
end

Step 3: Assemble and Link the Code
Save the code in a file named HelloWorldUnicode.asm.
Open a command prompt and navigate to the directory where the file is saved.

Assemble the code using MASM:

sh
Copy
ml64 HelloWorldUnicode.asm /link /subsystem:windows /entry:main
This will produce an executable named HelloWorldUnicode.exe.

Step 4: Run the Program
Run the HelloWorldUnicode.exe executable. You should see a message box with the text "World!" and the caption "Hello".

Explanation

Unicode Strings: The strings szCaption and szText are defined as arrays of dw (double words) to store Unicode characters.

MessageBoxW: The MessageBoxW function is used to display a Unicode message box.

ExitProcess: The ExitProcess function is used to exit the program cleanly.
Stack Alignment: The stack is aligned to 16 bytes before calling Windows API functions, which is a requirement for 64-bit Windows.
This program demonstrates how to use Unicode strings in a 64-bit MASM assembly program for Windows 10.

Q: algorithm for  full Unicode support  convert string to small case in MASM 64 assembly using SSE for windows 10

A:To convert a string to lowercase in MASM 64-bit assembly using SSE (Streaming SIMD Extensions) with full Unicode support, you can leverage the PCMPISTRI instruction, which is part of the SSE4.2 instruction set. This instruction is designed for fast string processing and can handle Unicode characters efficiently.

Here's a step-by-step guide to implementing this:

1. Understand the Problem
Unicode characters can be 1, 2, or 4 bytes (UTF-8, UTF-16, etc.).

For simplicity, we'll assume the string is in UTF-16 (2 bytes per character), which is common in Windows.

The goal is to convert each character to lowercase using SSE instructions.

2. SSE4.2 Instructions
PCMPISTRI (Packed Compare Implicit Length Strings, Return Index) is useful for string processing.

PCMPISTRM (Packed Compare Implicit Length Strings, Return Mask) can generate a mask for further processing.

3. Algorithm
Load 16 bytes (8 UTF-16 characters) into an XMM register.

Use PCMPISTRI to identify uppercase characters.

Convert the identified characters to lowercase.

Store the result back to memory.

4. Implementation

; MASM 64-bit assembly for Windows 10
; Assumes the string is in UTF-16 (2 bytes per character)

section .data
    ; Example string (UTF-16)
    inputString dw 'Hello, World!', 0

section .bss
    outputString resw 100  ; Reserve space for output string

section .text
    global main

main:
    ; Load the address of the input string into RSI
    lea rsi, [inputString]
   
    ; Load the address of the output string into RDI
    lea rdi, [outputString]

convert_loop:
    ; Load 16 bytes (8 UTF-16 characters) into XMM0
    movdqu xmm0, [rsi]
   
    ; Compare characters to uppercase range (A-Z)
    ; Use PCMPISTRI to find uppercase characters
    ; ECX will contain the index of the first uppercase character
    pcmpistri xmm0, xmm0, 0x40  ; 0x40 is the IMM8 control byte for "compare ranges"

    ; If no uppercase characters are found, jump to the end
    jz no_uppercase

    ; Convert the identified character to lowercase
    ; Subtract 0x20 to convert from uppercase to lowercase
    psubw xmm0, xmmword [lowercase_mask]

    ; Store the result back to the output string
    movdqu [rdi], xmm0

    ; Move to the next 16 bytes
    add rsi, 16
    add rdi, 16

    ; Continue the loop
    jmp convert_loop

no_uppercase:
    ; Store the remaining characters
    movdqu [rdi], xmm0

    ; Exit the program
    ret

section .data
    ; Mask to convert uppercase to lowercase (subtract 0x20)
    lowercase_mask dw 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
5. Explanation
movdqu xmm0, [rsi]: Loads 16 bytes from the input string into the XMM0 register.

pcmpistri xmm0, xmm0, 0x40: Compares the characters in XMM0 to the uppercase range (A-Z). The 0x40 control byte specifies the comparison mode.

psubw xmm0, xmmword [lowercase_mask]: Subtracts 0x20 from each character in XMM0 to convert uppercase to lowercase.

movdqu [rdi], xmm0: Stores the converted characters back to the output string.

6. Considerations
This example assumes the string is in UTF-16. If the string is in UTF-8, additional handling is required.

The PCMPISTRI instruction is powerful but complex. Ensure you understand its behavior with different control bytes.

This code is a basic example. For production code, handle edge cases like string length, alignment, and different Unicode ranges.

7. Optimization
Unroll the loop for better performance.

Use aligned loads (movdqa) if the data is aligned to 16-byte boundaries.

Consider using AVX instructions for wider registers (256-bit) if targeting newer CPUs.

This approach leverages SSE4.2 instructions for efficient Unicode string processing, making it one of the fastest methods for this task in assembly language.

; MASM 64-bit assembly for Windows 10
; Assumes the string is in UTF-16 (2 bytes per character)

section .data
    ; Example string (UTF-16)
    inputString dw 'Hello, World!', 0

section .bss
    outputString resw 100  ; Reserve space for output string

section .text
    global main

main:
    ; Load the address of the input string into RSI
    lea rsi, [inputString]
   
    ; Load the address of the output string into RDI
    lea rdi, [outputString]

convert_loop:
    ; Load 16 bytes (8 UTF-16 characters) into XMM0
    movdqu xmm0, [rsi]
   
    ; Compare characters to uppercase range (A-Z)
    ; Use PCMPISTRI to find uppercase characters
    ; ECX will contain the index of the first uppercase character
    pcmpistri xmm0, xmm0, 0x40  ; 0x40 is the IMM8 control byte for "compare ranges"

    ; If no uppercase characters are found, jump to the end
    jz no_uppercase

    ; Convert the identified character to lowercase
    ; Subtract 0x20 to convert from uppercase to lowercase
    psubw xmm0, xmmword [lowercase_mask]

    ; Store the result back to the output string
    movdqu [rdi], xmm0

    ; Move to the next 16 bytes
    add rsi, 16
    add rdi, 16

    ; Continue the loop
    jmp convert_loop

no_uppercase:
    ; Store the remaining characters
    movdqu [rdi], xmm0

    ; Exit the program
    ret

section .data
    ; Mask to convert uppercase to lowercase (subtract 0x20)
    lowercase_mask dw 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20


#74
The Orphanage / Re: Deep Seek - Extended Diz-C...
Last post by NoCforMe - February 08, 2025, 10:56:25 AM
Quote from: zedd151 on February 08, 2025, 10:42:55 AM
Quote from: NoCforMe on February 08, 2025, 10:09:16 AMAnd most notably, not a single word about MasmBasic.
I guess that's a case of missing the trees for the forest ...
I noticed that. Which is why I made my suggestion to test it by having it write a masmbasic program.  :badgrin:

Whereupon it proceeded to blow you off ...
#75
The Orphanage / Re: Deep Seek - Extended Diz-C...
Last post by zedd151 - February 08, 2025, 10:42:55 AM
Quote from: NoCforMe on February 08, 2025, 10:09:16 AMAnd most notably, not a single word about MasmBasic.
I guess that's a case of missing the trees for the forest ...
I noticed that. Which is why I made my suggestion to test it by having it write a masmbasic program.  :badgrin:
#76
The Orphanage / Re: Deep Seek - Extended Diz-C...
Last post by NoCforMe - February 08, 2025, 10:09:16 AM
Quote from: jj2007 on February 08, 2025, 09:50:52 AMIndeed. Roughly half of it is plain wrong and freely invented.

And most notably, not a single word about MasmBasic.
I guess that's a case of missing the trees for the forest ...
#77
The Orphanage / Re: Deep Seek - Extended Diz-C...
Last post by jj2007 - February 08, 2025, 09:58:42 AM
QuotePlease write a simple hello world program using masmbasic

profile
Qwen2.5-Plus
11:54 pm
MASMBASIC is not a standard assembly language or environment, but if you're referring to writing a "Hello, World!" program using the Microsoft Macro Assembler (MASM) with basic principles, I can provide an example for you. Below is a simple "Hello, World!" program written in MASM for a 32-bit Windows environment.

Followed by simple code in push-push-call style...
#78
The Orphanage / Re: Deep Seek - Extended Diz-C...
Last post by zedd151 - February 08, 2025, 09:52:22 AM
Quote from: jj2007 on February 08, 2025, 09:50:52 AMIndeed. Roughly half of it is plain wrong and freely invented. However, it's nicely expressed, I must say :badgrin:
You should ask it to write a simple hello world program using masmbasic.  :biggrin:
#79
The Orphanage / Re: Deep Seek - Extended Diz-C...
Last post by jj2007 - February 08, 2025, 09:50:52 AM
Indeed. Roughly half of it is plain wrong and freely invented. However, it's nicely expressed, I must say :badgrin:
#80
The Orphanage / Re: Deep Seek - Extended Diz-C...
Last post by zedd151 - February 08, 2025, 09:27:43 AM
@jj: Sounds like it is trying to be your PR agent.  :tongue:  :joking: