News:

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

Main Menu

Miscellaneous snippets

Started by jj2007, August 20, 2017, 08:02:31 AM

Previous topic - Next topic

jj2007

Could be useful for testing sort algos etc:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  Dll "RandomStrings"                   ; the DLL must be in the same folder
  Declare RandomString
  .Repeat
        For_ ecx=0 To 5
                Print RandomString(), " "
        Next
        Inkey cfm$("- more (no=n)?\n")
  .Until eax=="n" || eax==VK_ESCAPE
EndOfCode


Output:
imprisoning barked channel superstitious practical spectre - more (no=n)?
currants shower agitation lions motherly forces - more (no=n)?
negus proofs devil chose observation individuals - more (no=n)?
quarrelled whistled place commanded stipulation cannot - more (no=n)?
deeds settled taught verdict unsocial goeth - more (no=n)?
nefarious herald extinguishes accounted system military - more (no=n)?
worse colouring attacks transfixed hearts binding - more (no=n)?
instruments rally singly sword until profit - more (no=n)?
tranquilly luring convinced unchecked trade hears - more (no=n)?
violent packet sternly tearing kneeled crumbled - more (no=n)?
... etc ...

anunitu

i am thinking JJ is the REAL MASM Wizard for sure.

jj2007

Thanks - too much honour :icon_redface:

Here is version 2, with pseudo and real random modes (and 20,000 words for choice):

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  Dll "RandomStrings"                   ; the DLL must be in the same folder
  Declare RandomString, 1
  .Repeat
        For_ ecx=0 To 5
                Print RandomString(0), " "      ; 0=pseudo, 1=real random
        Next
        Inkey cfm$("- more (no=n)?\n")
  .Until eax=="n" || eax==VK_ESCAPE
EndOfCode


In mode 0, the sequence is always identical. It looks random, and is random according to some popular measures of randomness, but you'll always see the same strings. This is particular useful if, for example, your sort algo stumbles over a specific word, and you want to debug that event. It's also a bit faster - in "real" mode, one Million strings need almost one second on my i5. The pseudo mode is 70 times faster.

jj2007

Little demo for image rotation (strangely enough, this GdiPlus function has never been used in this forum ::)):

GuiParas equ "Image rotation demo", w400, h440
include \masm32\MasmBasic\Res\MbGui.asm
  GuiImageCallback Rotate       ; user-defined function
  SetGlobals halfWidth, halfHeight, REAL4:rotateAngle, movX, movY
Event Paint
  imul eax, GuiWidth, 100       ; width*100/128
  sar eax, 8
  add eax, 20
  mov halfWidth, eax
  imul eax, GuiHeight, 100      ; height*100/128
  sar eax, 8
  mov halfHeight, eax
  GuiImage 99, 0, 0, halfWidth, halfHeight      ; res ID, x, y, w, h 
  GuiCls                               ; trigger next paint event
EndOfEvents
Rotate:
  fild halfWidth                        ; an integer
  fadd FP4(35.0)                        ; add a fixed x offset
  fstp movX                             ; Gdi+ needs a float
  fild halfHeight
  fadd FP4(32.0)
  fstp movY
  gdi+ GdipTranslateWorldTransform, giGraphics, movX, movY, MatrixOrderPrepend  ; move to the middle
  gdi+ GdipRotateWorldTransform, giGraphics, rotateAngle, MatrixOrderPrepend    ; rotate
  fld rotateAngle                       ; add one degree for next paint event
  fadd FP4(1.0)
  fstp rotateAngle
  ret
GuiEnd

jj2007

include \masm32\MasmBasic\MasmBasic.inc         ; download
include Geo.inc
  Init
  PrintLine "GEO_LCID:   ", Tb$, Geo$(GEO_LCID)
  PrintLine "GEO_RFC1766:", Tb$, Geo$(GEO_RFC1766), CrLf$
  Inkey "I live in ", Geo$(), " (aka ", Geo$(GEO_OFFICIALNAME), ") at ", Geo$(GEO_LATITUDE), " North, ", Geo$(GEO_LONGITUDE), " East"
EndOfCode


Output:GEO_LCID:       00000809
GEO_RFC1766:    en-it

I live in Italia (aka Repubblica italiana) at 42.768 North, 12.492 East

jj2007

Inspired by the Campus post PUSH & POP question by DayDreamer:

include \Masm32\MasmBasic\Res\JBasic.inc        ; ## builds in 32- or 64-bit mode with ML and UAsm
include PushPopXmm.inc
.code
xvalue0         OWORD 11111111222222223333333344444444h
xvalue1         OWORD 55555555666666667777777788888888h
Init           ; OPT_64 1      ; put 0 for 32 bit, 1 for 64 bit assembly
  PrintLine Chr$("This code was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format")
  movups xmm0, xvalue0
  movups xmm7, xvalue1
  usedeb=1
  deb 4, "before", x:xmm0, x:xmm7
  ppxInit
  PushX xmm0
  PushX xmm7
  PopX xmm0                     ; note the order: we
  PopX xmm7                     ; are swapping values
  deb 4, "popped & swapped", x:xmm0, x:xmm7
  ; PopX xmm0                           ; uncomment to see the error handling
  MsgBox 0, "Wow, it works!!!!", "Hi", MB_OK or MB_SETFOREGROUND
EndOfCode


Output:
This code was assembled with UAsm64 in 64-bit format
before
x:xmm0  3333333344444444h
x:xmm7  7777777788888888h
popped & swapped
x:xmm0  7777777788888888h
x:xmm7  3333333344444444h


Attached the macro and a standard MasmBasic example.

daydreamer

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

HSE

Quote from: jj2007 on May 03, 2018, 09:39:29 AM

Output:GEO_LCID:       00000809
GEO_RFC1766:    en-it

I live in Italia (aka Repubblica italiana) at 42.768 North, 12.492 East

Are tou sure?

:biggrin:
GEO_LCID:       00000C0A
GEO_RFC1766:    es-es

I live in España (aka Reino de España) at 40.396 North, -3.551 East

Equations in Assembly: SmplMath

jj2007

Well, I do live in Italy, but I haven't check how exact the LatLong figures are. Any idea how the OS determines a user's position?

HSE

Quote from: jj2007 on May 07, 2018, 08:08:04 AM
Any idea how the OS determines a user's position?

OS don't know user's position. I think it's just a point in country center. You declare country when setting language and location. In spanish language España it's default country. In italian language... let me think... mmh  ::)
Equations in Assembly: SmplMath

daydreamer

Quote from: jj2007 on May 07, 2018, 08:08:04 AM
Well, I do live in Italy, but I haven't check how exact the LatLong figures are. Any idea how the OS determines a user's position?
Same as timezone= the capital of your country?cant you check Rome in google maps and see if its same long and latitude?
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

jj2007

Quote from: daydreamer on May 07, 2018, 02:47:29 PMSame as timezone= the capital of your country?cant you check Rome in google maps and see if its same long and latitude?

Yes, you can: Enter the result as e.g. 42.768, 12.492 into Google Maps. It seems that the Geo$() function returns the middle of the country. In theory, you can fine-tune your location, but it's a per user setting in the Control Panel, be careful.

LordAdef

QuoteGEO_LCID:       00000416
GEO_RFC1766:    pt-us

I live in Estados Unidos (aka Estados Unidos da América) at 39.450 North, -98.908 East

Hey, the little guy placed me in the US!

daydreamer

Curious if masm or masm basic also supports print in hexadecimal like c++  cout has?
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

jj2007

Quote from: daydreamer on May 11, 2018, 04:17:15 AM
Curious if masm or masm basic also supports print in hexadecimal like c++  cout has?

Sure:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  mov ecx, 123456789
  Print Str$("Decimal:\t%i\n", ecx)
  mov esi, 12345678h
  PrintLine "Hexadecimal:", Tb$, Hex$(esi)
  movd xmm0, esi
  pshufd xmm0, xmm0, 0
  deb 4, "for debugging", ecx, x:esi, x:xmm0
  Inkey "-- hit any key --"
EndOfCode


Decimal:        123456789
Hexadecimal:    12345678

for debugging
ecx             123456789
x:esi           12345678
x:xmm0          12345678 12345678 12345678 12345678


The Masm32 SDK has the hex$() macro, e.g. as print hex$(esi), 13, 10