News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

OPTION LITERALS in 32 bits

Started by aw27, August 12, 2017, 01:28:35 AM

Previous topic - Next topic

aw27

It appears that OPTION LITERALS does not work properly in 32 bits.
In the code below if I remove the semicolon from "USELITERALS equ 1" the problems start. Strings are accepted in RtlInitAnsiString  but produce garbage. printf does not accept the literal.


.386

;USELITERALS equ 1

.model Flat, C
option Casemap :None
IFDEF USELITERALS
OPTION LITERALS:ON ; Allow string literals use in INVOKE
ENDIF

TRUE equ 1

includelib \masm32\lib\ntdll.lib
RtlCompareString PROTO STDCALL :ptr,:ptr,:BYTE
RtlInitAnsiString PROTO STDCALL :ptr, :ptr

includelib \masm32\lib\msvcrt.lib
printf PROTO :PTR, :vararg

includelib \masm32\lib\kernel32.lib
ExitProcess proto STDCALL :dword

_STRING struct
_Length word ?
_Maximumlength word ?
_Buffer dword ?
_STRING ends

.data
format db 'result: %d',13,10,0
s1 db "someStr",0 ;
s2 db "anotherStr",0 ;

.code

main proc
LOCAL str1 : _STRING
LOCAL str2 : _STRING
IFDEF USELITERALS
INVOKE RtlInitAnsiString, addr str1, "someStr"
INVOKE RtlInitAnsiString, addr str2, "anotherStr"
INVOKE RtlCompareString, addr str1, addr str2, TRUE
INVOKE printf, "result: %d", eax
ELSE
INVOKE RtlInitAnsiString, addr str1, addr s1
INVOKE RtlInitAnsiString, addr str2, addr s2
INVOKE RtlCompareString, addr str1, addr str2, TRUE
INVOKE printf, addr format, eax
ENDIF

INVOKE ExitProcess,0

main endp

end main

aw27

But if I define the prototype of printf as "printf PROTO :PTR, :PTR" it works.
In this case the variation:
      INVOKE RtlInitAnsiString, addr str1, "someStr"
      INVOKE RtlInitAnsiString, addr str2, "anotherStr"
      INVOKE RtlCompareString, addr str1, addr str2, TRUE      
      INVOKE printf, "result: %d", eax
will work.
But this will not:
      INVOKE RtlInitAnsiString, addr str1, "someStr"
      INVOKE RtlInitAnsiString, addr str2, "anotherStr"
      INVOKE RtlCompareString, addr str1, addr str2, TRUE      
      INVOKE printf, addr format, eax

That is, we will be forced to use always literals on INVOKE.
So, it appears there are 2 problems:
1) Once you use literals on one parameter it expects ptr arguments on the following parameters.
2) You can not decide when to use literals or not once you subscribe the LITERALS option.


habran

Hi aw27 :biggrin:
That is interesting find you've got there :shock:
At the moment I am busy with the SWITCH-CASE-ENDSWITCH and Johnsa is still on holidays, if he doesn't return soon I'll look at that issue as soon as I finish that new stuff that I am working on.
The fix will be included in next release together with the new stuff as soon as Johnsa returns.
Cod-Father

aw27

No worries, fortunately the default alternative OPTION LITERALS:OFF  works well :t

johnsa

Hey,

(Still on holiday.. sort of) :)

The decision for string literals to only work with type PTR was intentional.. There was a lot of code where one might find something like this:

aFunction PROTO :DWORD

which was being called with

invoke aFunction, "abcd"

Technically string immediates were already supported as long as it fitted in the corresponding type, "A", "AB", "ABCD" etc.. So to avoid a) confusion and b) breaking existing code I used a combination that would
never have existed previously, no one would have a called a function with a type declared as PTR with a string/character immediate value.

As for the other issues that shouldn't happen and I will investigate if Habran doesn't beat me to it :)

aw27

Quote from: johnsa on August 13, 2017, 05:24:31 AM
The decision for string literals to only work with type PTR was intentional
The real problem is not that, I tried to explain it with the printf case.  ;)

johnsa

Got it :)

Just wanted to make that clear for anyone who was trying to use them with existing prototypes.

Will get onto the other issues asap :)

habran

Hi aw27,
If you use :printf PROTO :PTR, :vararg
the INVOKE printf, "result: %d", eax will not assemble
but printf PROTO :PTR, :PTR works fine ( see example below)
That means that Johnsa prevented an purpose that to occur because vararg can contain anyting
I'll leave it to him to decide if he will change it or not.

--- strliterals.asm ------------------------------------------------------------
     1: .386
     2:
     3: USELITERALS equ 1
     4:
     5: .model Flat, C
     6: option Casemap :None
     7: IFDEF USELITERALS
     8: OPTION LITERALS:ON ; Allow string literals use in INVOKE
     9: ENDIF
    10:
    11: TRUE equ 1
    12:
    13: includelib \masm32\lib\ntdll.lib
    14: RtlCompareString PROTO STDCALL :ptr,:ptr,:BYTE
    15: RtlInitAnsiString PROTO STDCALL :ptr, :ptr
    16:
    17: includelib \masm32\lib\msvcrt.lib
    18: printf PROTO :PTR, :PTR
    19:
    20: includelib \masm32\lib\kernel32.lib
    21: ExitProcess proto STDCALL :dword
    22:
    23: _STRING struct
    24: _Length word ?
    25: _Maximumlength word ?
    26: _Buffer dword ?
    27: _STRING ends
    28:
    29: .data
    30: format db 'result: %d',13,10,0
    31: s1 db "someStr",0 ;
    32: s2 db "anotherStr",0 ;
    33:
    34: .code
    35:
    36: main proc
009B1010 55                   push        ebp 
009B1011 8B EC                mov         ebp,esp 
009B1013 83 EC 10             sub         esp,10h 
    37: LOCAL str1 : _STRING
    38: LOCAL str2 : _STRING
    39:       INVOKE RtlInitAnsiString, addr str1, "someStr"
009B1016 68 49 50 9B 00       push        9B5049h 
009B101B 8D 45 F8             lea         eax,[str1] 
009B101E 50                   push        eax 
009B101F E8 90 00 00 00       call        _RtlInitAnsiString@8 (09B10B4h) 
    40:       INVOKE RtlInitAnsiString, addr str2, "anotherStr"
009B1024 68 51 50 9B 00       push        9B5051h 
009B1029 8D 45 F0             lea         eax,[str2] 
009B102C 50                   push        eax 
009B102D E8 82 00 00 00       call        _RtlInitAnsiString@8 (09B10B4h) 
    41:       INVOKE RtlCompareString, addr str1, addr str2, TRUE     
009B1032 6A 01                push        1 
009B1034 8D 45 F0             lea         eax,[str2] 
009B1037 50                   push        eax 
009B1038 8D 45 F8             lea         eax,[str1] 
009B103B 50                   push        eax 
009B103C E8 6D 00 00 00       call        _RtlCompareString@12 (09B10AEh) 
    42:       INVOKE printf, "result: %d", eax
009B1041 50                   push        eax 
    42:       INVOKE printf, "result: %d", eax
009B1042 68 3E 50 9B 00       push        9B503Eh 
009B1047 E8 6E 00 00 00       call        _printf (09B10BAh) 
009B104C 83 C4 08             add         esp,8 
    43:
    44:       INVOKE RtlInitAnsiString, addr str1, "someStr"
009B104F 68 49 50 9B 00       push        9B5049h 
009B1054 8D 45 F8             lea         eax,[str1] 
009B1057 50                   push        eax 
009B1058 E8 57 00 00 00       call        _RtlInitAnsiString@8 (09B10B4h) 
    45:       INVOKE RtlInitAnsiString, addr str2, "anotherStr"
009B105D 68 51 50 9B 00       push        9B5051h 
009B1062 8D 45 F0             lea         eax,[str2] 
009B1065 50                   push        eax 
009B1066 E8 49 00 00 00       call        _RtlInitAnsiString@8 (09B10B4h) 
    46:       INVOKE RtlCompareString, addr str1, addr str2, TRUE     
009B106B 6A 01                push        1 
009B106D 8D 45 F0             lea         eax,[str2] 
009B1070 50                   push        eax 
009B1071 8D 45 F8             lea         eax,[str1] 
009B1074 50                   push        eax 
009B1075 E8 34 00 00 00       call        _RtlCompareString@12 (09B10AEh) 
    47:       INVOKE printf, addr format, eax
009B107A 50                   push        eax 
009B107B 68 00 50 9B 00       push        9B5000h 
009B1080 E8 35 00 00 00       call        _printf (09B10BAh) 
009B1085 83 C4 08             add         esp,8 
    48:
    49: INVOKE ExitProcess,0
009B1088 6A 00                push        0 
009B108A E8 35 10 00 00       call        _ExitProcess@4 (09B20C4h) 
--- No source file -------------------------------------------------------------

Cod-Father

habran

Here is a simple solution without changing UASM code: 8)
Quote
IFDEF USELITERALS
   OPTION LITERALS:ON ; Allow string literals use in INVOKE
    printf PROTO :PTR, :PTR
ELSE
   printf PROTO :PTR, :vararg
ENDIF



--- strliterals.asm ------------------------------------------------------------
     1: .386
     2:
     3: USELITERALS equ 1
     4:
     5: .model Flat, C
     6: option Casemap :None
     7: IFDEF USELITERALS
     8: OPTION LITERALS:ON ; Allow string literals use in INVOKE
     9:     printf PROTO :PTR, :PTR
    10: ELSE
    11:    printf PROTO :PTR, :vararg
    12: ENDIF
    13:
    14: TRUE equ 1
    15:
    16: includelib \masm32\lib\ntdll.lib
    17: RtlCompareString PROTO STDCALL :ptr,:ptr,:BYTE
    18: RtlInitAnsiString PROTO STDCALL :ptr, :ptr
    19:
    20: includelib \masm32\lib\msvcrt.lib
    21:
    22: includelib \masm32\lib\kernel32.lib
    23: ExitProcess proto STDCALL :dword
    24:
    25: _STRING struct
    26: _Length word ?
    27: _Maximumlength word ?
    28: _Buffer dword ?
    29: _STRING ends
    30:
    31: .data
    32: format db 'result: %d',13,10,0
    33: s1 db "someStr",0 ;
    34: s2 db "anotherStr",0 ;
    35:
    36: .code
    37:
    38: main proc
01291010 55                   push        ebp 
01291011 8B EC                mov         ebp,esp 
01291013 83 EC 10             sub         esp,10h 
    39: LOCAL str1 : _STRING
    40: LOCAL str2 : _STRING
    41: IFDEF USELITERALS
    42: INVOKE RtlInitAnsiString, addr str1, "someStr"
01291016 68 20 50 29 01       push        1295020h 
0129101B 8D 45 F8             lea         eax,[str1] 
0129101E 50                   push        eax 
0129101F E8 90 00 00 00       call        _RtlInitAnsiString@8 (012910B4h) 
    43: INVOKE RtlInitAnsiString, addr str2, "anotherStr"
01291024 68 28 50 29 01       push        1295028h 
01291029 8D 45 F0             lea         eax,[str2] 
0129102C 50                   push        eax 
0129102D E8 82 00 00 00       call        _RtlInitAnsiString@8 (012910B4h) 
    44: INVOKE RtlCompareString, addr str1, addr str2, TRUE
01291032 6A 01                push        1 
01291034 8D 45 F0             lea         eax,[str2] 
01291037 50                   push        eax 
01291038 8D 45 F8             lea         eax,[str1] 
0129103B 50                   push        eax 
0129103C E8 6D 00 00 00       call        _RtlCompareString@12 (012910AEh) 
    45: INVOKE printf, "result: %d", eax
01291041 50                   push        eax 
01291042 68 3E 50 29 01       push        129503Eh 
01291047 E8 6E 00 00 00       call        _printf (012910BAh) 
0129104C 83 C4 08             add         esp,8 
    46: ELSE
    47: INVOKE RtlInitAnsiString, addr str1, addr s1
    48: INVOKE RtlInitAnsiString, addr str2, addr s2
    49: INVOKE RtlCompareString, addr str1, addr str2, TRUE
    50: INVOKE printf, addr format, eax
    51: ENDIF
    52:
    53: INVOKE ExitProcess,0
0129104F 6A 00                push        0 
01291051 E8 6E 10 00 00       call        _ExitProcess@4 (012920C4h) 
--- No source file -------------------------------------------------------------
Cod-Father

aw27

Thank you for the hints and heads up, habran  :t

habran

 :biggrin:
New, exciting UASM2.39 is coming soon, with SWITCH-CASE-ENDSWITCH with all data stored in _DATA section
so that debugging makes easy, here is an example:

   mov eax,1003
.switch eax
    .case 300
    mov edx,300
    .case 1001
    mov edx,1
  .case 1002
    mov edx,2
  .case 1003
     mov edx,3
  .case 1004
    mov edx,5
  .case 1005
    mov edx,6
  .case 1006
    mov edx,7
  .case 1009
.case 1040
     mov  edx,1 
    .case 1041
    mov edx,1
  .case 1042
    mov edx,2
  .case 1043
     mov edx,3
  .case 1044
    mov edx,5
  .case 1045
    mov edx,6
  .case 1046
    mov edx,7
  .case 1049
.case 1099
     mov  edx,1 
    .case 1031
    mov edx,1
  .case 902
    mov edx,2
  .case 1083
     mov edx,3
  .case 1084
    mov edx,5
  .case 1085
    mov edx,6
  .case 1086
    mov edx,7
  .case 1089
.case 1090
     mov  edx,1 
    .case 1121
    mov edx,1
  .case 1092
    mov edx,2
  .case 1093
     mov edx,3
  .case 1094
    mov edx,5
  .case 1095
    mov edx,6
  .case 1056
    mov edx,7
  .case 1059
    .case 1011
    mov edx,1
  .case 1052
    mov edx,2
  .case 1053
     mov edx,3
  .case 1054
    mov edx,5
  .case 1055
    mov edx,6
  .case 1066
    mov edx,7
  .case 1069
.case 1070
     mov  edx,1 
    .case 1071
    mov edx,1
  .case 1102
    mov edx,2
  .case 1103
     mov edx,3
  .case 1104
    mov edx,5
  .case 1105
    mov edx,6
  .case 1106
    mov edx,7
  .case 1109
      mov edx,1109
.case 1100
     mov  edx,1 
    .case 1061
    mov edx,1
  .case 1012
    mov edx,2
  .case 1013
     mov edx,3
  .case 1014
    mov edx,5
  .case 1015
    mov edx,6
  .case 1016
    mov edx,7
  .case 1019
    mov edx,8
  .default
    mov edx,9
.endswitch


Debug:

   146:    mov eax,1003
011D11D6 B8 EB 03 00 00       mov         eax,3EBh 
   147: .switch eax
011D11DB E9 F4 01 00 00       jmp         WndProc+204h (011D13D4h) 
   148:     .case 300
   149:     mov edx,300
011D11E0 BA 2C 01 00 00       mov         edx,12Ch 
   150:     .case 1001
011D11E5 E9 17 02 00 00       jmp         WndProc+231h (011D1401h) 
   151:     mov edx,1
011D11EA BA 01 00 00 00       mov         edx,1 
   152:   .case 1002
011D11EF E9 0D 02 00 00       jmp         WndProc+231h (011D1401h) 
   153:     mov edx,2
011D11F4 BA 02 00 00 00       mov         edx,2 
   154:   .case 1003
011D11F9 E9 03 02 00 00       jmp         WndProc+231h (011D1401h) 
   155:      mov edx,3
011D11FE BA 03 00 00 00       mov         edx,3 
   156:   .case 1004
011D1203 E9 F9 01 00 00       jmp         WndProc+231h (011D1401h) 
   157:     mov edx,5
011D1208 BA 05 00 00 00       mov         edx,5 
   158:   .case 1005
011D120D E9 EF 01 00 00       jmp         WndProc+231h (011D1401h) 
   159:     mov edx,6
011D1212 BA 06 00 00 00       mov         edx,6 
   160:   .case 1006
011D1217 E9 E5 01 00 00       jmp         WndProc+231h (011D1401h) 
   161:     mov edx,7
011D121C BA 07 00 00 00       mov         edx,7 
   162:   .case 1009
011D1221 E9 DB 01 00 00       jmp         WndProc+231h (011D1401h) 
   163: .case 1040
011D1226 E9 D6 01 00 00       jmp         WndProc+231h (011D1401h) 
   164:      mov  edx,1 
011D122B BA 01 00 00 00       mov         edx,1 
   165:     .case 1041
011D1230 E9 CC 01 00 00       jmp         WndProc+231h (011D1401h) 
   166:     mov edx,1
011D1235 BA 01 00 00 00       mov         edx,1 
   167:   .case 1042
011D123A E9 C2 01 00 00       jmp         WndProc+231h (011D1401h) 
   168:     mov edx,2
011D123F BA 02 00 00 00       mov         edx,2 
   169:   .case 1043
011D1244 E9 B8 01 00 00       jmp         WndProc+231h (011D1401h) 
   170:      mov edx,3
011D1249 BA 03 00 00 00       mov         edx,3 
   171:   .case 1044
011D124E E9 AE 01 00 00       jmp         WndProc+231h (011D1401h) 
   172:     mov edx,5
011D1253 BA 05 00 00 00       mov         edx,5 
   173:   .case 1045
011D1258 E9 A4 01 00 00       jmp         WndProc+231h (011D1401h) 
   174:     mov edx,6
011D125D BA 06 00 00 00       mov         edx,6 
   175:   .case 1046
011D1262 E9 9A 01 00 00       jmp         WndProc+231h (011D1401h) 
   176:     mov edx,7
011D1267 BA 07 00 00 00       mov         edx,7 
   177:   .case 1049
011D126C E9 90 01 00 00       jmp         WndProc+231h (011D1401h) 
   178: .case 1099
011D1271 E9 8B 01 00 00       jmp         WndProc+231h (011D1401h) 
   179:      mov  edx,1 
011D1276 BA 01 00 00 00       mov         edx,1 
   180:     .case 1031
011D127B E9 81 01 00 00       jmp         WndProc+231h (011D1401h) 
   181:     mov edx,1
011D1280 BA 01 00 00 00       mov         edx,1 
   182:   .case 902
011D1285 E9 77 01 00 00       jmp         WndProc+231h (011D1401h) 
   183:     mov edx,2
011D128A BA 02 00 00 00       mov         edx,2 
   184:   .case 1083
011D128F E9 6D 01 00 00       jmp         WndProc+231h (011D1401h) 
   185:      mov edx,3
011D1294 BA 03 00 00 00       mov         edx,3 
   186:   .case 1084
011D1299 E9 63 01 00 00       jmp         WndProc+231h (011D1401h) 
   187:     mov edx,5
011D129E BA 05 00 00 00       mov         edx,5 
   188:   .case 1085
011D12A3 E9 59 01 00 00       jmp         WndProc+231h (011D1401h) 
   189:     mov edx,6
011D12A8 BA 06 00 00 00       mov         edx,6 
   190:   .case 1086
011D12AD E9 4F 01 00 00       jmp         WndProc+231h (011D1401h) 
   191:     mov edx,7
011D12B2 BA 07 00 00 00       mov         edx,7 
   192:   .case 1089
011D12B7 E9 45 01 00 00       jmp         WndProc+231h (011D1401h) 
   193: .case 1090
011D12BC E9 40 01 00 00       jmp         WndProc+231h (011D1401h) 
   194:      mov  edx,1 
011D12C1 BA 01 00 00 00       mov         edx,1 
   195:     .case 1121
011D12C6 E9 36 01 00 00       jmp         WndProc+231h (011D1401h) 
   196:     mov edx,1
011D12CB BA 01 00 00 00       mov         edx,1 
   197:   .case 1092
011D12D0 E9 2C 01 00 00       jmp         WndProc+231h (011D1401h) 
   198:     mov edx,2
011D12D5 BA 02 00 00 00       mov         edx,2 
   199:   .case 1093
011D12DA E9 22 01 00 00       jmp         WndProc+231h (011D1401h) 
   200:      mov edx,3
011D12DF BA 03 00 00 00       mov         edx,3 
   201:   .case 1094
011D12E4 E9 18 01 00 00       jmp         WndProc+231h (011D1401h) 
   202:     mov edx,5
011D12E9 BA 05 00 00 00       mov         edx,5 
   203:   .case 1095
011D12EE E9 0E 01 00 00       jmp         WndProc+231h (011D1401h) 
   204:     mov edx,6
011D12F3 BA 06 00 00 00       mov         edx,6 
   205:   .case 1056
011D12F8 E9 04 01 00 00       jmp         WndProc+231h (011D1401h) 
   206:     mov edx,7
011D12FD BA 07 00 00 00       mov         edx,7 
   207:   .case 1059
011D1302 E9 FA 00 00 00       jmp         WndProc+231h (011D1401h) 
   208:     .case 1011
011D1307 E9 F5 00 00 00       jmp         WndProc+231h (011D1401h) 
   209:     mov edx,1
011D130C BA 01 00 00 00       mov         edx,1 
   210:   .case 1052
011D1311 E9 EB 00 00 00       jmp         WndProc+231h (011D1401h) 
   211:     mov edx,2
011D1316 BA 02 00 00 00       mov         edx,2 
   212:   .case 1053
011D131B E9 E1 00 00 00       jmp         WndProc+231h (011D1401h) 
   213:      mov edx,3
011D1320 BA 03 00 00 00       mov         edx,3 
   214:   .case 1054
011D1325 E9 D7 00 00 00       jmp         WndProc+231h (011D1401h) 
   215:     mov edx,5
011D132A BA 05 00 00 00       mov         edx,5 
   216:   .case 1055
011D132F E9 CD 00 00 00       jmp         WndProc+231h (011D1401h) 
   217:     mov edx,6
011D1334 BA 06 00 00 00       mov         edx,6 
   218:   .case 1066
011D1339 E9 C3 00 00 00       jmp         WndProc+231h (011D1401h) 
   219:     mov edx,7
011D133E BA 07 00 00 00       mov         edx,7 
   220:   .case 1069
011D1343 E9 B9 00 00 00       jmp         WndProc+231h (011D1401h) 
   221: .case 1070
011D1348 E9 B4 00 00 00       jmp         WndProc+231h (011D1401h) 
   222:      mov  edx,1 
011D134D BA 01 00 00 00       mov         edx,1 
   223:     .case 1071
011D1352 E9 AA 00 00 00       jmp         WndProc+231h (011D1401h) 
   224:     mov edx,1
011D1357 BA 01 00 00 00       mov         edx,1 
   225:   .case 1102
011D135C E9 A0 00 00 00       jmp         WndProc+231h (011D1401h) 
   226:     mov edx,2
011D1361 BA 02 00 00 00       mov         edx,2 
   227:   .case 1103
011D1366 E9 96 00 00 00       jmp         WndProc+231h (011D1401h) 
   228:      mov edx,3
011D136B BA 03 00 00 00       mov         edx,3 
   229:   .case 1104
011D1370 E9 8C 00 00 00       jmp         WndProc+231h (011D1401h) 
   230:     mov edx,5
011D1375 BA 05 00 00 00       mov         edx,5 
   231:   .case 1105
011D137A E9 82 00 00 00       jmp         WndProc+231h (011D1401h) 
   232:     mov edx,6
011D137F BA 06 00 00 00       mov         edx,6 
   233:   .case 1106
011D1384 EB 7B                jmp         WndProc+231h (011D1401h) 
   234:     mov edx,7
011D1386 BA 07 00 00 00       mov         edx,7 
   235:   .case 1109
011D138B EB 74                jmp         WndProc+231h (011D1401h) 
   236:       mov edx,1109
011D138D BA 55 04 00 00       mov         edx,455h 
   237: .case 1100
011D1392 EB 6D                jmp         WndProc+231h (011D1401h) 
   238:      mov  edx,1 
011D1394 BA 01 00 00 00       mov         edx,1 
   239:     .case 1061
011D1399 EB 66                jmp         WndProc+231h (011D1401h) 
   240:     mov edx,1
011D139B BA 01 00 00 00       mov         edx,1 
   241:   .case 1012
011D13A0 EB 5F                jmp         WndProc+231h (011D1401h) 
   242:     mov edx,2
011D13A2 BA 02 00 00 00       mov         edx,2 
   243:   .case 1013
011D13A7 EB 58                jmp         WndProc+231h (011D1401h) 
   244:      mov edx,3
011D13A9 BA 03 00 00 00       mov         edx,3 
   245:   .case 1014
011D13AE EB 51                jmp         WndProc+231h (011D1401h) 
   246:     mov edx,5
011D13B0 BA 05 00 00 00       mov         edx,5 
   247:   .case 1015
011D13B5 EB 4A                jmp         WndProc+231h (011D1401h) 
   248:     mov edx,6
011D13B7 BA 06 00 00 00       mov         edx,6 
   249:   .case 1016
011D13BC EB 43                jmp         WndProc+231h (011D1401h) 
   250:     mov edx,7
011D13BE BA 07 00 00 00       mov         edx,7 
   251:   .case 1019
011D13C3 EB 3C                jmp         WndProc+231h (011D1401h) 
   252:     mov edx,8
011D13C5 BA 08 00 00 00       mov         edx,8 
   253:   .default
011D13CA EB 35                jmp         WndProc+231h (011D1401h) 
   254:     mov edx,9
011D13CC BA 09 00 00 00       mov         edx,9 
   255: .endswitch
011D13D1 EB 2E                jmp         WndProc+231h (011D1401h) 
011D13D3 90                   nop 
011D13D4 3D 2C 01 00 00       cmp         eax,12Ch 
011D13D9 7C F1                jl          WndProc+1FCh (011D13CCh) 
011D13DB 3D 61 04 00 00       cmp         eax,461h 
011D13E0 77 EA                ja          WndProc+1FCh (011D13CCh) 
011D13E2 50                   push        eax 
011D13E3 52                   push        edx 
011D13E4 8D 15 18 51 1D 01    lea         edx,ds:[11D5118h] 
011D13EA 2D 2C 01 00 00       sub         eax,12Ch 
011D13EF 0F B7 14 42          movzx       edx,word ptr [edx+eax*2] 
011D13F3 8D 05 3A 50 1D 01    lea         eax,ds:[11D503Ah] 
011D13F9 8B 04 90             mov         eax,dword ptr [eax+edx*4] 
011D13FC 5A                   pop         edx 
011D13FD 87 04 24             xchg        eax,dword ptr [esp] 
011D1400 C3                   ret 
   256:

The actual mechanic to calculate the jump is this:

   255: .endswitch
011D13D1 EB 2E                jmp         WndProc+231h (011D1401h) 
011D13D3 90                   nop 
011D13D4 3D 2C 01 00 00       cmp         eax,12Ch 
011D13D9 7C F1                jl          WndProc+1FCh (011D13CCh) 
011D13DB 3D 61 04 00 00       cmp         eax,461h 
011D13E0 77 EA                ja          WndProc+1FCh (011D13CCh) 
011D13E2 50                   push        eax 
011D13E3 52                   push        edx 
011D13E4 8D 15 18 51 1D 01    lea         edx,ds:[11D5118h] 
011D13EA 2D 2C 01 00 00       sub         eax,12Ch 
011D13EF 0F B7 14 42          movzx       edx,word ptr [edx+eax*2] 
011D13F3 8D 05 3A 50 1D 01    lea         eax,ds:[11D503Ah] 
011D13F9 8B 04 90             mov         eax,dword ptr [eax+edx*4] 
011D13FC 5A                   pop         edx 
011D13FD 87 04 24             xchg        eax,dword ptr [esp] 
011D1400 C3                   ret 
   256:

I have on purpose used a big gap between the lowest and highest case to show that there is no data in the  _CODE section
here is the listing which shows actual data used to calculate the jump:

00000000                    *    .data
00000354                    *   _TEXT ends
0000003A                    *   _DATA segment
                            *   assume cs:ERROR
0000003A  000000000000000000*   @C0006 dd @C000B, @C001D, @C000C, @C000D, @C000E, @C000F, @C0010, @C0011, @C0012, @C002B, @C003C, @C003D, @C003E, @C003F, @C0040, @C0041, @C001C, @C0013, @C0014, @C0015
0000008A  000000000000000000*    dd @C0016, @C0017, @C0018, @C0019, @C001A, @C002C, @C002D, @C002E, @C002F, @C0029, @C002A, @C003B, @C0030, @C0031, @C0032, @C0033, @C001E, @C001F, @C0020, @C0021
000000DA  000000000000000000*    dd @C0022, @C0023, @C0025, @C0026, @C0027, @C0028, @C001B, @C003A, @C0034, @C0035, @C0036, @C0037, @C0038, @C0039, @C0024
00000116  0000              *   ALIGN 4
00000118  000037003700370037*   @C0008 dw 0,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55
0000017C  370037003700370037*    dw 55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55
000001E0  370037003700370037*    dw 55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55
00000244  370037003700370037*    dw 55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55
000002A8  370037003700370037*    dw 55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55
0000030C  370037003700370037*    dw 55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55
00000370  370037003700370037*    dw 55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55
000003D4  370037003700370037*    dw 55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55
00000438  370037003700370037*    dw 55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55
0000049C  370037003700370037*    dw 55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55
00000500  370037003700370037*    dw 55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55
00000564  370037003700370037*    dw 55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55
000005C8  370037000100370037*    dw 55,55,1,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55
0000062C  370037003700370037*    dw 55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55
00000690  370002000300040005*    dw 55,2,3,4,5,6,7,55,55,8,55,9,10,11,12,13,14,55,55,15,55,55,55,55,55,55,55,55,55,55,55,16,55,55,55,55,55,55,55,55,17,18,19,20,21,22,23,55,55,24
000006F4  3700370019001A001B*    dw 55,55,25,26,27,28,29,55,55,30,55,31,55,55,55,55,32,55,55,33,34,35,55,55,55,55,55,55,55,55,55,55,55,36,37,38,39,55,55,40,41,55,42,43,44,45,55,55,55,46
00000758  2F0037003000310032*    dw  47,55,48,49,50,51,52,55,55,53,55,55,55,55,55,55,55,55,55,55,55,54
00000000                    *   .code
00000784                    *   _DATA ends
Cod-Father

habran

This is now not any more Ferrari but Tesla Model S P100D ;)
Cod-Father

aw27

Quote from: habran on August 15, 2017, 08:38:23 PM
This is now not any more Ferrari but Tesla Model S P100D ;)
Thank you for the clarification.  :exclaim:

habran

#13
It was my pleasure :biggrin:
I was always disappointed with the garbage which that HLL creates in the code section, even MSV$ does the same, now UASM jumped  far, far ahead, as AUDI says:"vorsprung durch technik" :t
The advantage of that is not only clear debug code but we can put more data there to make it faster and it will not bloat the code section.
I have increased span between lowest and highest case from 512 to 2048 and it can be all executed with a few instructions from the above post.
So, if you need a speed for big amount of cases it can span from 0 to 2048
UASM has a smart logic to use different kind of solution for different types of cases to keep data as small as possible without affecting the speed, however, smart programmer will chose wisely what cases to put together to create optimal code.
In my opinion every programmer is smart, stupid can not be programmer, they can only think that they are ;)
Cod-Father

habran

Johnsa is still on holidays so I decided to post a new UASM here for testing SWITCH hll
here is a 64 bit
Cod-Father