News:

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

Main Menu

Masm32 switch macro: unexpected behaviour

Started by jj2007, May 06, 2016, 04:27:10 AM

Previous topic - Next topic

jj2007

include \masm32\include\masm32rt.inc

.code
start:
  m2m ebx, -5
  print chr$(13, 10, "Masm32 switch, good example:", 13, 10)
  .Repeat
print str$(ebx), 9
switch ebx
case -5
print "case -5", 13, 10
case 5
print "case +5", 13, 10
case -3 .. -2
print "case -3 .. -2", 13, 10
case 0
print "case NULL", 13, 10
case 2 .. 3
print "case +2 .. +3", 13, 10
default
print "...", 13, 10
endsw
inc ebx
  .Until sdword ptr ebx>5

  m2m ebx, -5
  print chr$(13, 10, "failing example:", 13, 10)
  .Repeat
print str$(ebx), 9
switch ebx
case -5
print "case -5", 13, 10
case 5
print "case +5", 13, 10
case -3 .. 3
print "case -3 .. 3", 13, 10
default
print "...", 13, 10
endsw
inc ebx
  .Until sdword ptr ebx>5
  inkey "--- hit any key ---"
  exit
end start


Output:
Masm32 switch, good example:
-5      case -5
-4      ...
-3      case -3 .. -2
-2      case -3 .. -2
-1      ...
0       case NULL
1       ...
2       case +2 .. +3
3       case +2 .. +3
4       ...
5       case +5

failing example:
-5      case -5
-4      ...
-3      ...
-2      ...
-1      ...
0       ...
1       ...
2       ...
3       ...
4       ...
5       case +5

jj2007

While working on 64-bit includes, I saw many functions in \Masm32\include\msvcrt.inc that look somewhat abandoned, and for which neither Google nor the Visual Studio help provide any clues. For example, _Getmonths.

include \Masm32\MasmBasic\Res\JBasic.inc      ; OPT_64 1
Init
  MsgBox 0, rv(crt__Getmonths, 0), Chr$("This code was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format"), MB_OK
EndOfCode


To my surprise, this works like a charm ::) (see attachment; ML64 version 10 or WatCom fork needed, ML64 14 yields only gibberish).

Question: What happened to these old functions, and why is there no documentation?

hutch--

This,

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    LOCAL buffer[260]:BYTE

    invoke vc__Getmonths,0

    conout rax,lf

    waitkey

    invoke ExitProcess,0

    ret

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end

Produces,

:Jan:January:Feb:February:Mar:March:Apr:April:May:May:Jun:June:Jul:July:Aug:August:Sep:September:Oct:October:Nov:November:Dec:December
Press any key to continue...

jj2007

Indeed, same as mine, but it doesn't answer my question.

hutch--

This is done with ML64 version 14 ALA vs2015.

Here is a variant on the last one.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    LOCAL pbuf  :QWORD
    LOCAL buffer[512]:BYTE
    LOCAL pmnth :QWORD
    LOCAL parr  :QWORD
    LOCAL shtnm :QWORD

    mov pbuf, ptr$(buffer)

    mov pbuf, rv(MonthNames,pbuf)   ; get raw month list
    invoke ltok,pbuf,ADDR parr      ; tokenise it

    mov shtnm, 1                    ; 1 for short name, 0 for long nme

    mov rcx, 12                     ; month number here (1 to 12)

    mov rax, parr                   ; array address into RAX
    add rcx, rcx                    ; double it
    .if shtnm == 1
      sub rcx, 2                      ; sub 2 for zero based index
    .else
      sub rcx, 1                      ; sub 1 for zero based index
    .endif

    mov r11, [rax+rcx*8]            ; load address into r11

    conout r11,lf

    waitkey

    mfree parr              ; free memory from "ltok"

    invoke ExitProcess,0

    ret

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

MonthNames proc obuf:QWORD

    LOCAL ibuf :QWORD

    mov ibuf, rv(vc__Getmonths,0)
    invoke szRep,ibuf,obuf,":",chr$(13,10)

    mov rax, obuf

    ret

MonthNames endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end

hutch--

Better done in assembler.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

MonthByNumber proc number:QWORD

    LOCAL rval :QWORD

    .switch number
      .case 1
        mrm rval, chr$("January")
      .case 2
        mrm rval, chr$("February")
      .case 3
        mrm rval, chr$("March")
      .case 4
        mrm rval, chr$("April")
      .case 5
        mrm rval, chr$("May")
      .case 6
        mrm rval, chr$("June")
      .case 7
        mrm rval, chr$("July")
      .case 8
        mrm rval, chr$("August")
      .case 9
        mrm rval, chr$("September")
      .case 10
        mrm rval, chr$("October")
      .case 11
        mrm rval, chr$("November")
      .case 12
        mrm rval, chr$("December")
      .default
        mrm rval, chr$("Month number out of range")
    .endsw

    mov rax, rval

    ret

MonthByNumber endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

TWell

Quote from: jj2007 on September 30, 2016, 09:46:08 AM
Question: What happened to these old functions, and why is there no documentation?
Maybe those are useless support routines without locale.
look at strftime.c

LiaoMi

Quote from: jj2007 on September 30, 2016, 09:46:08 AM
While working on 64-bit includes, I saw many functions in \Masm32\include\msvcrt.inc that look somewhat abandoned, and for which neither Google nor the Visual Studio help provide any clues. For example, _Getmonths.

include \Masm32\MasmBasic\Res\JBasic.inc      ; OPT_64 1
Init
  MsgBox 0, rv(crt__Getmonths, 0), Chr$("This code was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format"), MB_OK
EndOfCode


To my surprise, this works like a charm ::) (see attachment; ML64 version 10 or WatCom fork needed, ML64 14 yields only gibberish).

Question: What happened to these old functions, and why is there no documentation?

This api is used only in Standard Template Library, probably need to look for pointers of classes in order to go to this api ...


/* xlocinfo.h internal header for Microsoft */

_C_LIB_DECL
_Success_(return != 0)
_Ret_z_
_ACRTIMP char *__cdecl _Getdays(void);

_Success_(return != 0)
_Ret_z_
_ACRTIMP char *__cdecl _Getmonths(void);

_ACRTIMP void *__cdecl _Gettnames(void);

_Success_(return > 0)
_ACRTIMP size_t __cdecl _Strftime(_Out_writes_z_(_Maxsize) char *,
_In_ size_t _Maxsize, _In_z_ const char *, _In_ const struct tm *,
_In_opt_ void *);

_Success_(return != 0)
_Ret_z_
_ACRTIMP wchar_t *__cdecl _W_Getdays(void);

_Success_(return != 0)
_Ret_z_
_ACRTIMP wchar_t *__cdecl _W_Getmonths(void);

_ACRTIMP void *__cdecl _W_Gettnames(void);

_Success_(return > 0)
_ACRTIMP size_t __cdecl _Wcsftime(_Out_writes_z_(_Maxsize) wchar_t *,
_In_ size_t _Maxsize, _In_z_ const wchar_t *, _In_ const struct tm *,
_In_opt_ void *);
_END_C_LIB_DECL

#ifdef _M_CEE_PURE
[System::Runtime::InteropServices::DllImport(_CRT_MSVCP_CURRENT,
EntryPoint = "_GetLocaleForCP",
CallingConvention =
System::Runtime::InteropServices::CallingConvention::Cdecl)]
extern "C" _locale_t _GetLocaleForCP(unsigned int);

#else /* _M_CEE_PURE */
_MRTIMP2 _locale_t __cdecl _GetLocaleForCP(unsigned int);
#endif /* _M_CEE_PURE */


It is now in - libcpmt.lib

LIBCPMT.LIB Multithreaded, static link /MT _MT
C++ Standard Library - https://msdn.microsoft.com/en-us/library/abx4dbyh.aspx
so that there is no Getmonths function in C Run-time Library (CRT)

::)

TWell

Those functions still exists in ucrtbase.dll in Windows 10.

LiaoMi

msvcr*.dll no longer exists. It has been split into the compiler version dependent vcruntime140.dll and the compiler version independent ucrtbase.dll. Starting with Win10 ucrtbase.dll is also a OS component and will be updated together with the OS.

See these blog posts for details:

http://blogs.msdn.com/b/vcblog/archive/2015/03/03/introducing-the-universal-crt.aspx

http://blogs.msdn.com/b/vcblog/archive/2014/06/10/the-great-crt-refactoring.aspx

http://blogs.msdn.com/b/vcblog/archive/2014/06/18/crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1.aspx

"Will it be more complex to deploy an application that built from VS2015 ?"

Not really. Unless you statically link the VC libraries you still have to distribute some VC dlls with your applications. Even on Win10 where the ucrtbase.dll is part of the OS. Originally app local deployment of ucrtbase wasn't supported but they reverted that decision.


From - https://social.msdn.microsoft.com/Forums/en-US/a5194720-b019-4e60-bd2f-e1ed03e1a951/about-vs2015-crt-what-is-ucrtbasedll-and-where-is-its-symbol?forum=vcgeneral

hutch--

I hate to tell you this but msvcrt.dll is alive and well in my Win10 Professional system32 directory.

msvcrt.dll 773,168 10/30/2015

jj2007

> Maybe those are useless support routines without locale

Indeed, I get English months on my Italian OS. Very old stuff. I wonder if anybody uses them.