News:

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

Main Menu

Switch/Case/Endswitch macro for 64- and 32-bit code

Started by jj2007, July 16, 2023, 10:55:51 AM

Previous topic - Next topic

jj2007

The Switch_ macro is one of 28 macros that are identical in standard 32-bit MasmBasic and 64-/32-bit JBasic:

include \Masm32\MasmBasic\Res\JBasic.inc ; ## console demo, builds in 32- or 64-bit mode with UAsm, ML, AsmC ##
Init ; OPT_64 1 ; put 0 for 32 bit, 1 for 64 bit assembly; click here for an example with procs
  Cls 3
  PrintLine Chr$("This program was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format.")
  Print ComCtl32$("It uses common controls version %i.%i\n") ; see XP below
  or ebx, -1
@@: Print Str$("ebx=%i\t", rbx)
mov ecx, 7
Switch_ rbx
Case_ 0
PrintLine "Case zero"
Case_ 9
PrintLine "Case 9"
Case_ 3..5
PrintLine "Case three to five"
Case_ ecx
PrintLine "Case ecx"
Default_
PrintLine "Default"
Endsw_
inc ebx
cmp ebx, 10
jbe @B
  jinvoke MessageBox, 0, Chr$("JBasic is fantastic"), Chr$("Hello"), MB_OK or MB_SETFOREGROUND
EndOfCode


This program was assembled with ml64 in 64-bit format.
It uses common controls version 6.16
ebx=-1  Default
ebx=0   Case zero
ebx=1   Default
ebx=2   Default
ebx=3   Case three to five
ebx=4   Case three to five
ebx=5   Case three to five
ebx=6   Default
ebx=7   Case ecx
ebx=8   Default
ebx=9   Case 9
ebx=10  Default



This program was assembled with ML in 32-bit format.
It uses common controls version 6.16
ebx=-1  Default
ebx=0   Case zero
ebx=1   Default
ebx=2   Default
ebx=3   Case three to five
ebx=4   Case three to five
ebx=5   Case three to five
ebx=6   Default
ebx=7   Case ecx
ebx=8   Default
ebx=9   Case 9
ebx=10  Default


Note the complicated    cmp ebx, 10 ... jbe @B construct. It's to make ML64 happy (UAsm and AsmC do have .Repeat ... .Until) :cool: