Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change
; --------------------------------------------------------------------------------------------------
; Procedure: WideToUTF8Size
; Purpose: Calculate the amount of memory needed to store the converted UTF8 stream from a
; WIDE string.
; Arguments: Arg1: -> Source WIDE string. Must be zero terminated.
; Return: eax = Number of BYTEs requred. Zero if failed.
; Notes: The ZTC is always included in size calculations.
; The returned value can only be zero if the procedure fails.
; Wide chars can only encode the Basic Multilingual Plane (BMP, or Plane 0),
; meaning that sequences of a maximum of three bytes can be generated.
.code
align ALIGN_CODE
WideToUTF8Size proc pSource:POINTER
xor eax, eax
?mov ecx, pSource
.if xcx == NULL
ret
.endif
@@NextChar:
movzx edx, CHRW ptr [xcx]
test edx, edx
.if ZERO?
inc eax ;Include this last ZTC
ret
.endif
.if edx <= 07Fh
inc eax
.elseif edx <= 07FFh
add eax, 2
.else
add eax, 3
.endif
add xcx, sizeof(CHRW)
jmp @@NextChar
WideToUTF8Size endp
Quote from: daydreamer on June 20, 2025, 04:42:14 PMCross platform, wrapper functions
Like proc with winapi function names,inside is invoke to Linux same function?
Or the other way around?
; --------------------------------------------------------------------------------------------------
; Procedure: UTF8ToWideSize
; Purpose: Calculate the amount of memory needed to store the converted WIDE string from a
; UTF8 stream.
; Arguments: Arg1: -> Source UTF8 BYTE stream. Must be zero terminated.
; Return: eax = Number of BYTEs requred. Zero if failed.
; Notes: The ZTC is always included in size calculations.
; The returned value can only be zero if the procedure fails.
.code
align ALIGN_CODE
UTF8ToWideSize proc pSource:POINTER
?mov ecx, pSource
xor eax, eax
@@NextChar:
movzx edx, BYTE ptr [xcx]
test edx, edx ;ZTC?
.if ZERO?
add eax, sizeof(WORD) ;ZTC
ret
.endif
test edx, 10000000y
.if ZERO?
;1 Byte encoding (0xxxxxxx)
add eax, sizeof(WORD)
inc xcx
jmp @@NextChar
.endif
and edx, 11111000y
.if edx == 11110000y ;11110xxx
;4 Byte encoding (11110xxx 10xxxxxx 10xxxxxx 10xxxxxx)
add eax, sizeof(WORD)
add xcx, 4*sizeof(BYTE)
jmp @@NextChar
.endif
and edx, 11110000y
.if edx == 11100000y ;1110xxxx
;3 Byte encoding (1110xxxx 10xxxxxx 10xxxxxx)
add eax, sizeof(WORD)
add xcx, 3*sizeof(BYTE)
jmp @@NextChar
.endif
and edx, 11100000y
.if edx == 11000000y ;110xxxxx
;2 Byte encoding (110xxxxx 10xxxxxx)
add eax, sizeof(WORD)
add xcx, 2*sizeof(BYTE)
jmp @@NextChar
.endif
xor eax, eax ;Conversion error
ret
UTF8ToWideSize endp
Quote from: NoCforMe on June 19, 2025, 09:37:21 AMI had never heard of that,
Quotebut yeah, like that. Except that it wasn't anything like a multi-user multitasking "environment", just an overlay on top of DOS programs. It sure looked like the screenshots of the IBM thing, though.
xor eax, eax
mov esi, offset strHW
loop_start:
inc eax
mov edi, offset strHW + 5
add esi, eax
xor ecx, ecx
add ecx, 11
cld
repe cmpsb
jz found
cmp eax, 10
jne loop_start
found:
mov ebx, -1
Is anything I'm doing wrong or unconventional?