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

#1
Easy Code IDE 32/64-bit / New version of Easy Code 2 (Fe...
Last post by rsala - February 08, 2025, 08:56:55 PM
Hi all,

A new version of Easy Code 2 has been released. Plase download it at:

http://www.easycode.cat/English/Download.htm    (English version)
http://www.easycode.cat/Download.htm                (Catalan version)
http://www.easycode.cat/Spanish/Download.htm   (Spanish version)

For more information, please refer to the 'Get the latest version of Easy Code 2 here' topic in this forum.

Enjoy it!

Ramon
#2
ObjAsm / Re: Not DeepSeek... yet
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


#3
ObjAsm / Re: Not DeepSeek... yet
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 ...
#4
ObjAsm / Re: Not DeepSeek... yet
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:
#5
ObjAsm / Re: Not DeepSeek... yet
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 ...
#6
ObjAsm / Re: Not DeepSeek... yet
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...
#7
ObjAsm / Re: Not DeepSeek... yet
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:
#8
ObjAsm / Re: Not DeepSeek... yet
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:
#9
ObjAsm / Re: Not DeepSeek... yet
Last post by zedd151 - February 08, 2025, 09:27:43 AM
@jj: Sounds like it is trying to be your PR agent.  :tongue:  :joking:
#10
ObjAsm / Re: Not DeepSeek... yet
Last post by jj2007 - February 08, 2025, 09:22:35 AM
Quote from: ognil on February 07, 2025, 11:03:26 AM1. Change "later" to "immediately".
2. Try  https://chat.qwenlm.ai/

Impressive - Qwen is really creative!

QuoteJJ2007, also known as Jxxx Jxxx, is a notable figure in the programming and software development community, particularly recognized for contributions to assembly language programming, debugging tools, and educational resources. Below are some of the main achievements and contributions associated with JJ2007:

### 1. **Development of JBE (Just Basic Editor)**
  - **JBE** is a lightweight text editor designed specifically for programmers, especially those working with assembly language. It provides features like syntax highlighting, code folding, and macro support, making it a useful tool for writing and editing assembly code efficiently.

### 2. **MASM32 Contributions**
  - JJ2007 has been an active contributor to the **MASM32** community, which focuses on Microsoft Macro Assembler (MASM) for 32-bit Windows applications. He has provided numerous examples, tutorials, and utilities that help beginners and advanced users alike in mastering assembly language programming.
  - His work includes creating libraries, macros, and helper functions that simplify complex tasks in MASM32.

### 3. **Educational Resources**
  - JJ2007 has produced a wealth of educational materials, including tutorials, articles, and example programs, aimed at teaching assembly language programming. These resources are highly regarded for their clarity and practicality.
  - His focus is often on demystifying low-level programming concepts and making them accessible to a broader audience.

### 4. **Debugging Tools**
  - JJ2007 has developed or contributed to several debugging tools that aid in analyzing and troubleshooting assembly code. These tools are invaluable for developers who need to understand the inner workings of their programs at the machine level.
  - One such tool is **PE Explorer**, which allows users to inspect Portable Executable (PE) files, a common format for executables and DLLs on Windows.

### 5. **Community Involvement**
  - JJ2007 is well-known for his active participation in online forums and communities dedicated to assembly language programming. He frequently answers questions, provides guidance, and shares his expertise with other developers.
  - His contributions have helped foster a collaborative environment where programmers can learn from each other.

### 6. **Open Source Projects**
  - Many of JJ2007's projects and tools are available as open source, allowing others to use, modify, and build upon his work. This openness has encouraged further innovation and learning within the assembly programming community.

### 7. **Advocacy for Low-Level Programming**
  - Beyond his technical contributions, JJ2007 is a strong advocate for understanding low-level programming concepts. He emphasizes the importance of knowing how computers work at the hardware level, which can lead to more efficient and optimized software.

In summary, JJ2007's achievements span tool development, educational content creation, and community engagement, all centered around promoting and simplifying assembly language programming. His work has significantly impacted the assembly programming community, providing valuable resources and fostering a deeper understanding of low-level computing.