News:

Download Pelles C here: http://www.pellesc.se

Main Menu

Recent posts

#31
Assembly discussions / Re: Find characters inside a s...
Last post by Vortex - August 26, 2026, 07:07:38 PM
Another version assuming that the string to be searched contains only printable characters :

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

FindChar PROC src:DWORD,char:DWORD

    mov     eax,DWORD PTR [esp+4]
    mov     ecx,DWORD PTR [esp+8]
    dec     eax
@@:
    inc     eax
    mov     dl,BYTE PTR [eax]
    mov     dh,dl
    xor     dl,cl
    sub     dx,0101h
    or      dl,dh
    cmp     dl,255
    jnz     @b
    retn    8

FindChar ENDP

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef
#32
Assembly discussions / Re: Find characters inside a s...
Last post by jack - August 25, 2026, 02:26:56 AM
👍
#33
Assembly discussions / Re: Find characters inside a s...
Last post by Vortex - August 24, 2026, 10:07:48 PM
Here is the 64-bit version :

ExitProcess PROTO :QWORD
printf PROTO C :QWORD,:VARARG

.data

mystr   db 'This is a test.',0
f1      db 'Address of the string = %X',13,10
        db 'Address of the character a = %X',0

.code

FindChar PROC src:QWORD,char:QWORD

    mov     rax,rcx
    dec     rax
@@:
    inc     rax
    mov     cl,BYTE PTR [rax]
    mov     ch,cl
    xor     cl,dl
    dec     ch
    dec     cl
    or      cl,ch
    cmp     cl,255
    jnz     @b
    ret

FindChar ENDP

start PROC PARMAREA=4*SIZEOF(QWORD)

    invoke  FindChar,ADDR mystr,'a'
    invoke  printf,ADDR f1,ADDR mystr,rax

    invoke  ExitProcess,0

start ENDP

END start
#34
Expert questions / Re: _readdir() translates some...
Last post by John Z - August 24, 2026, 01:08:58 PM
Quote from: TimoVJL on August 24, 2026, 12:09:34 PME4 is Lower case n with acute

Yup, thanks, I did not remember if it was acute or grave (up, or down) so just general term diacritic.  Been a while since my French :)

John Z
#36
Expert questions / Re: _readdir() translates some...
Last post by John Z - August 23, 2026, 10:09:58 PM
Hi,

Well first I've never used these functions so a grain of salt with my comments.

Looking into the header there is no Unicode or wide character support for the functions.  So support will be limited to code pages.  If using ANSI code page ( I guess for the UK ?) for example then the 233 é  exists and can be shown.  However the ANSI code page does not include an n with diacritic in fact the only n is 241 ñ, so the closest substitution is made.

So try a different code page?  I was going to suggest trying to get the 8.3 filename but it seems the same issue would hinder that too.

John Z

For example codepage 852  E4 is n with diacritic
#37
Expert questions / Re: _readdir() translates some...
Last post by TimoVJL - August 23, 2026, 02:08:45 PM
Function fopen might be a problem too, as it works with ANSI filenames.
I did some tests, even i don't like those functions, as i rather use Win32 API.
#38
Expert questions / _readdir() translates some non...
Last post by RobertSteed - August 23, 2026, 11:19:49 AM
Dear forum,
My code includes the following:
#include <dirent.h>
#include <locale.h>
...
setlocale(LC_ALL, "");
...
_DIR *dir;
struct _dirent *dirent;
dir = _opendir(path); // Open the folder
...
dirent = _readdir(dir); // Read first entry in folder // Read first entry in folder
if (dirent == NULL)
{ perror(path);
return 1;
}
while (dirent != NULL) // While not at end of folder
{
printf("dirent->d_name = %s\n", dirent->d_name);
...

Which results in
dirent->d_name = Art of Beksinski 1978 (MHS) (2).jpgLater code tries to open the files found:
FILE *fh = fopen(fn, "rb");which of course results in an error message:
Couldn't open test data\Art of Beksinski 1978 (MHS) (2).jpg: No such file or directoryThe actual filename is "Art of Beksiński 1978 (MHS) (2).jpg" with a diacritic on the "n". _readdir() worked as expected for "00tést.jpg" which has a diacritic on the "e".
So how can I get _opendir to return all non-ASCII file names as they are, without translating some characters?
#39
Assembly discussions / Find characters inside a strin...
Last post by Vortex - August 20, 2026, 09:18:26 PM
FindChar function to find characters inside strings :

.386
.model flat,stdcall
option casemap:none

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

.data

mystr   db 'This is a test.',0
f1      db 'Address of the string = %X',13,10
        db 'Address of the character a = %X',0

.code

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

FindChar PROC src:DWORD,char:DWORD

    mov     eax,DWORD PTR [esp+4]
    mov     ecx,DWORD PTR [esp+8]
    dec     eax
@@:
    inc     eax
    mov     dl,BYTE PTR [eax]
    mov     dh,dl
    xor     dl,cl
    dec     dl
    dec     dh
    or      dl,dh
    cmp     dl,255
    jnz     @b
    retn    8

FindChar ENDP

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

start:

    invoke  FindChar,ADDR mystr,'a'
    invoke  printf,ADDR f1,ADDR mystr,eax

    invoke  ExitProcess,0

END start
#40
Assembly discussions / WriteFileToDisc function
Last post by Vortex - August 18, 2026, 08:16:05 PM
Simple function to write binary data to disc, 64-bit version :

include fileIO.inc

; Exit codes returned by WriteFileToDisc

; INVALID_HANDLE_VALUE equ -1 ; CreateFile API error
  WRITEFILE_ERROR      equ 0  ; WriteFile API error
  WRITEFILEDISC_OK     equ 1  ; Operation successfull

.code

WriteFileToDisc PROC pFileName:QWORD,pMemory:QWORD,nSize:QWORD PARMAREA=7*SIZEOF QWORD

;       pFileName       :   pointer to the file name
;       pMemory         :   address of the data block to write to disc
;       nSize           :   number of bytes to write

LOCAL hFile:QWORD
LOCAL BytesWritten:QWORD
LOCAL ExitCode:QWORD
LOCAL _pMemory:QWORD
LOCAL _nSize:QWORD


    mov     _pMemory,rdx
    mov     _nSize,r8
 
    invoke  CreateFile,pFileName,GENERIC_WRITE,0,0,\
            CREATE_ALWAYS,0,0

    cmp     eax,INVALID_HANDLE_VALUE
    je      _exitB
   
    mov     hFile,rax
    mov     rcx,rax
    mov     ExitCode,WRITEFILE_ERROR

    lea     r9,BytesWritten
    invoke  WriteFile,rcx,_pMemory,_nSize,r9,0
    test    rax,rax
    jz     _exitA
   
    mov     ExitCode,WRITEFILEDISC_OK

_exitA:
 
    invoke  CloseHandle,hFile
    mov     rax,ExitCode

_exitB:

    ret

WriteFileToDisc ENDP

END