Author Topic: Playing  (Read 835 times)

jj2007

  • Member
  • *****
  • Posts: 7650
  • Assembler is fun ;-)
    • MasmBasic
Playing
« on: August 04, 2017, 01:28:04 AM »
Playing with copying Unicode directly from RichMasm to the forum (in the current version, the ???? have to be replaced manually).

        Sound "大桥在混乱的水.mp3"   ; Unicode names are allowed

Could be worse :biggrin:
« Last Edit: August 04, 2017, 07:37:05 AM by jj2007 »

jj2007

  • Member
  • *****
  • Posts: 7650
  • Assembler is fun ;-)
    • MasmBasic
Re: Playing
« Reply #1 on: August 07, 2017, 11:22:07 PM »
QuadMath example:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  SetGlobals REAL16 oDest, Pi16, numInt:DWORD
  Init quad
  MovVal Pi16, "3.1415926535897932384626433832795028841971"
  ; int 3
  movups oDest, QuadMath(frexpq, Pi16, &numInt)
  nops 8
  PrintLine "QuadMath frexp: mantissa=", Tb$, Quad$(oDest), Str$(", expo=%i", numInt)
  Inkey Str$("expected mantissa (PI/4):\t%Je\n", PI/4)
EndOfCode


Output:
Code: [Select]
QuadMath frexp: mantissa=       7.85398163397448309615660845819876e-01, expo=2
expected mantissa (PI/4):       7.853981633974483097e-01

Source (*.asc - opens with WordPad or RichMasm) & exe attached, plus an exe with an int 3 inserted for easier debugging.

jj2007

  • Member
  • *****
  • Posts: 7650
  • Assembler is fun ;-)
    • MasmBasic
Re: Playing
« Reply #2 on: August 16, 2017, 06:53:13 AM »
Just for fun, a little test with the disassembled FreeBasic fbc.exe:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  SetGlobals ctEsp, ctPush, ctPop
  Init
  PrintCpu 0
  .if !Exist("DisAsFbc.txt")
        UnzipInit "http://www.webalice.it/jj2006/DisAsFbc.zip"  ; UnzipInit expects a filename or URL, returns a comment (if present); edx has records
       .if Sign?
                Print eax       ; print an error message
       .else
                UnzipFile(0, CurDir$())
                UnzipExit
        .endif
  .endif
  NanoTimer()
  Recall "DisAsFbc.txt", L$()
  Print Str$("%i ms to read the file into an array\n", NanoTimer(ms))
  Print Str$("Now checking %i lines for 'esp':\n", L$(?))
  NanoTimer()
  For_ ct=0 To L$(?)-1
        .if Instr_(L$(ct), "esp")
                inc ctEsp
        .endif
  Next
  Print Str$("%i ms to count 'esp'\n", NanoTimer(ms))
  Inkey Str$("There are %i matches for 'esp'", ctEsp)
EndOfCode


Code: [Select]
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
14 ms to read the file into an array
Now checking 250281 lines for 'esp':
24 ms to count 'esp'
There are 14399 matches for 'esp'

Source & exe (30.5k) attached.

jj2007

  • Member
  • *****
  • Posts: 7650
  • Assembler is fun ;-)
    • MasmBasic
Re: Playing
« Reply #3 on: August 16, 2017, 08:10:38 PM »
Generates a long string of lowercase characters and counts how often esp appears:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  totalsize=50000000
  mov ecx, totalsize
  Let edi=New$(ecx)
  .Repeat
        add Rand(26), 97        ; range 97... 122
        mov [edi+ecx], al
        dec ecx
  .Until Sign?
  PrintLine Left$(edi, 50)
  NanoTimer()
  Inkey Str$("Counting %i occurrences of 'esp' in the string", Count(edi, "esp")), Str$(" took %2f seconds", NanoTimer(ms)/1000)
EndOfCode

jj2007

  • Member
  • *****
  • Posts: 7650
  • Assembler is fun ;-)
    • MasmBasic
Re: Playing with Unicode
« Reply #4 on: August 18, 2017, 09:49:20 PM »
Docs: e.g. wLet, Recall - search inside the page for more.


include \masm32\MasmBasic\MasmBasic.inc
  SetGlobals lines, pos1, w$, break
  Init
  NanoTimer()
  Recall "mshtmlc.biUC", L$()   ; read a Unicode file (5,026,824 bytes)
  Print Str$("reading %i lines", L$(?)), Str$(" took %i ms\n", NanoTimer(ms))
  For_ ct=0 To L$(?)-1
        Let w$=wRec$(L$(ct))    ; translate Utf8$ to true Unicode
       .if wInstr(w$, "end type") && !break
                wMsgBox 0, eax, "Mark this line (no=delete):", MB_YESNOCANCEL
                .if eax==IDYES
                                wLet L$(ct)="** marked ** "+w$
                .elseif eax==IDCANCEL
                                or break, -1
                .else
                                Delete L$(ct)
                .endif
        .else
                wLet L$(ct)=w$
        .endif
  Next
  Open "O", 1, "modified_mshtmlc.biUC"
  Print 1, Chr$(0FFh, 0FEh)
  For_ ct=0 To L$(?)-1
        wPrintLine 1, wStr$("%i\t", ct), L$(ct)
  Next
  Close
  Inkey "bye"
EndOfCode

jj2007

  • Member
  • *****
  • Posts: 7650
  • Assembler is fun ;-)
    • MasmBasic
Re: Playing
« Reply #5 on: August 19, 2017, 04:46:02 AM »
include \masm32\MasmBasic\MasmBasic.inc
assCt=0
AssignCt MACRO arg
  xchg eax, arg
  mov tCount(assCt), eax
  assCt=assCt+1
ENDM

  Init
  PrintCpu 0                            ; for better comparisons ;-)

  Let esi=FileRead$("mshtmlc.bi")      ; 2,488,437 bytes

  $Data type sp case-sensitive, no sp cs, cs+full word, sp+case-insensitive, no sp cis, cis+fw, 1st char case-insensitive, 1st cis+fw
  $Data end type sp case-sensitive, end type sp cis, end type cs, end type cis
  Read Desc$()

  Dim tCount() As DWORD

  NanoTimer()
  AssignCt Count(esi, "type ", 0)      ; type<space>, 0=case-sensitive
  AssignCt Count(esi, "type", 0)       ; no space, case-sensitive
  AssignCt Count(esi, "type", 4)       ; 4=cs+full word
  AssignCt Count(esi, "type ", 1)      ; space, 1=case-insensitive
  AssignCt Count(esi, "type", 1)       ; no space, case-insensitive
  AssignCt Count(esi, "type", 1+4)     ; 1=case-insensitive, full word
  AssignCt Count(esi, "type", 2)       ; 2=first char case-insensitive
  AssignCt Count(esi, "type", 2+4)     ; 2=first char case-insensitive, full word
  AssignCt Count(esi, "end type ", 0)  ; type<space>, 0=case-sensitive
  AssignCt Count(esi, "end type ", 1)  ; type<space>, 1=case-insensitive
  AssignCt Count(esi, "end type", 0)   ; type, 0=case-sensitive
  AssignCt Count(esi, "end type", 1)   ; type, 1=case-sensitive
  Print Str$("counting took %2f seconds\n", NanoTimer(us)/1000000)
  For_ ct=0 To Desc$(?)-1
        PrintLine Str$(ct), Str$("\t%i matches\t", tCount(ct)), "[", Desc$(ct), "]"
  Next

  Inkey "for comparison: MS Word, case sensitive, full word: 2563-845=1718"
EndOfCode


Output:
Code: [Select]
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
counting took 0.027 seconds
0       1583 matches    [type sp case-sensitive]
1       2573 matches    [no sp cs]
2       2563 matches    [cs+full word]
3       1636 matches    [sp+case-insensitive]
4       5356 matches    [no sp cis]
5       2595 matches    [cis+fw]
6       5324 matches    [1st char case-insensitive]
7       2563 matches    [1st cis+fw]
8       0 matches       [end type sp case-sensitive]
9       0 matches       [end type sp cis]
10      845 matches     [end type cs]
11      845 matches     [end type cis]
for comparison: MS Word, case sensitive, full word: 2563-845=1718
« Last Edit: August 19, 2017, 06:02:10 AM by jj2007 »

jj2007

  • Member
  • *****
  • Posts: 7650
  • Assembler is fun ;-)
    • MasmBasic
RichMasm beta
« Reply #6 on: September 14, 2017, 10:56:48 AM »
The new menu looks certainly different :bgrin:

Beta attached, use at your own risk. Extract as
\Masm32\MasmBasic\Res\UserDef\RichMasm.ini
\Masm32\MasmBasic\RichMasm.exe

jj2007

  • Member
  • *****
  • Posts: 7650
  • Assembler is fun ;-)
    • MasmBasic
Re: Playing
« Reply #7 on: September 15, 2017, 04:34:35 AM »
New version - we are getting nearer  :t

Interesting that the screenshot taken with an aero theme shows the tooltip, while the "normal" theme doesn't allow to capture the tip. This stuff is really messy. For example, if you have Aero enabled, Dwmapi::DwmIsCompositionEnabled returns 1 but uxtheme::IsCompositionActive returns 0 ::)

MSDN Social has a How to detect if Aero is enabled thread:
Quote
VC6 is far too old and too rotten to support to find out if Aero is enabled or not

I like their sense of humour :P

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4880
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Playing
« Reply #8 on: September 17, 2017, 03:39:26 PM »
What I would really like is a decent 64 bit dis-assembler and so far I have not found one. The ARkDasm I have been using was very good for analysis during the development of 64 bit MASM but its asm output is too different to be useful for re-constructing asm code from a binary file. The best I have so far is the ordinary Microsoft Dumpbin with its results being able to be re-formatted back into MASM code with some massaging.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 7650
  • Assembler is fun ;-)
    • MasmBasic
Re: Playing
« Reply #9 on: September 17, 2017, 06:48:06 PM »
What's wrong with x64 except that they have ruthlessly stolen ideas from Olly?
Code: [Select]
include \Masm32\MasmBasic\Res\JBasic.inc
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")
  int 3 ; BREAK
  fldpi ; the FPU still exists!
  sub rsp, QWORD
  fld st
  fistp qword ptr [esp]
  movlps xmm0, qword ptr [esp]
  fst qword ptr [esp]
  movlps xmm1, qword ptr [esp]
  add rsp, QWORD
  MsgBox 0, "Wow, it works!!!!", "Hi", MB_OK or MB_SETFOREGROUND
EndOfCode

Code: [Select]
000000014000108D | CC                                | int3                                  |
000000014000108E | D9 EB                             | fldpi                                 |
0000000140001090 | 48 83 EC 08                       | sub rsp, 8                            |
0000000140001094 | D9 C0                             | fld st0                               |
0000000140001096 | 67 DF 3C 24                       | fistp qword ptr ds:[esp]              |
000000014000109A | 67 0F 12 04 24                    | movlps xmm0, qword ptr ds:[esp]       |
000000014000109F | 67 DD 14 24                       | fst qword ptr ds:[esp]                |
00000001400010A3 | 67 0F 12 0C 24                    | movlps xmm1, qword ptr ds:[esp]       |
00000001400010A8 | 48 83 C4 08                       | add rsp, 8                            |
00000001400010AC | 48 8D 15 C6 01 00 00              | lea rdx, qword ptr ds:[140001279]     | 140001279:"Wow, it works!!"
00000001400010B3 | 49 C7 C1 00 00 01 00              | mov r9, 10000                         |
00000001400010BA | 4C 8D 05 C8 01 00 00              | lea r8, qword ptr ds:[140001289]      | 140001289:"Hi"
00000001400010C1 | 33 C9                             | xor ecx, ecx                          |
00000001400010C3 | FF 15 27 03 00 00                 | call qword ptr ds:[<&MessageBoxA>]    |
00000001400010C9 | 33 C9                             | xor ecx, ecx                          |
00000001400010CB | FF 15 3F 03 00 00                 | call qword ptr ds:[<sub_140001410>]   |
00000001400010D1 | 48 8D 0D B4 01 00 00              | lea rcx, qword ptr ds:[<sub_14000128C | 14000128C:"user32"
00000001400010D8 | 48 8D 15 01 03 00 00              | lea rdx, qword ptr ds:[<sub_1400013E0 |
00000001400010DF | E8 27 00 00 00                    | call <sub_14000110B>                  |
00000001400010E4 | C3                                | ret                                   |

aw27

  • Member
  • ****
  • Posts: 794
Re: Playing
« Reply #10 on: September 17, 2017, 07:49:21 PM »
What I would really like is a decent 64 bit dis-assembler and so far I have not found one. The ARkDasm I have been using was very good for analysis during the development of 64 bit MASM but its asm output is too different to be useful for re-constructing asm code from a binary file. The best I have so far is the ordinary Microsoft Dumpbin with its results being able to be re-formatted back into MASM code with some massaging.
Visual Studio is passable.
1) Follow the instructions here.
2) Press F11 and you are right at your code startup.
3) If you don't see the disassembly window, open it with Ctrl-Alt-D

jj2007

  • Member
  • *****
  • Posts: 7650
  • Assembler is fun ;-)
    • MasmBasic
Re: Playing
« Reply #11 on: September 24, 2017, 11:06:30 AM »
include \masm32\MasmBasic\MasmBasic.inc         ; download
  SetGlobals My$="Text has many characters. Any chars that are available for removal?"
  Init
  PrintLine "Unicode:"
  For_ ecx=1 To wCL$(?)-1
        wPrintLine "[", wCL$(ecx), "]"
  Next
  PrintLine CrLf$, "Ansi:"
  For_ ecx=1 To CL$(?)-1
        PrintLine "[", CL$(ecx), "]"
  Next
  Print My$, Tb$, "the original", CrLf$  ; options as in Instr_()
  Print Replace$(My$, "a", "_"), Tb$, "'a' replaced with '_'", CrLf$
  Print Replace$(My$, "a", 0), Tb$, Tb$, "remove 'a', case-sensitive", CrLf$
  Print Replace$(My$, "any", 0), Tb$, "any, case-sensitive", CrLf$
  Print Replace$(My$, "any", 0, 1), Tb$, Tb$, "any, case-insensitive", CrLf$
  Print Replace$(My$, "any", 0, 5), Tb$, "any, case-insensitive, full word", CrLf$
  Print Replace$(My$, "any", 0, 2), Tb$, Tb$, "any, 1st char case-insensitive", CrLf$
EndOfCode

OPT_Arg1        Here are some arguments for you: Введите текст здесь    ; pass arguments to commandline


Code: [Select]
Unicode:
[Here]
[are]
[some]
[arguments]
[for]
[you:]
[Введите]
[текст]
[здесь]

Ansi:
[Here]
[are]
[some]
[arguments]
[for]
[you:]
[???????]
[?????]
[?????]
Text has many characters. Any chars that are available for removal?     the original
Text h_s m_ny ch_r_cters. Any ch_rs th_t _re _v_il_ble for remov_l?     'a' replaced with '_'
Text hs mny chrcters. Any chrs tht re vilble for removl?                remove 'a', case-sensitive
Text has m characters. Any chars that are available for removal?        any, case-sensitive
Text has m characters.  chars that are available for removal?           any, case-insensitive
Text has many characters.  chars that are available for removal?        any, case-insensitive, full word
Text has m characters.  chars that are available for removal?           any, 1st char case-insensitive

jj2007

  • Member
  • *****
  • Posts: 7650
  • Assembler is fun ;-)
    • MasmBasic
Java MessageBox
« Reply #12 on: September 27, 2017, 01:10:10 AM »
Code: [Select]
import javax.swing.JOptionPane;
class HelloWorldApp {
    public static void main(String[] args) {
System.out.println("Java sucks");
//JOptionPane.showMessageDialog(null,"message","title");
    }
}

The good news: It compiles and runs fine :t
The bad news: Removing the // before JOptionPane produces the usual cryptic error messages that one must expect from so-called "high level" languages:
Code: [Select]
HelloWorld.java:6: error: no suitable method found for showMessageDialog(<null>,String,String)
JOptionPane.showMessageDialog(null,"message","title");
           ^
    method JOptionPane.showMessageDialog(Component,Object) is not applicable
      (actual and formal argument lists differ in length)
    method JOptionPane.showMessageDialog(Component,Object,String,int) is not applicable
      (actual and formal argument lists differ in length)
    method JOptionPane.showMessageDialog(Component,Object,String,int,Icon) is not applicable
      (actual and formal argument lists differ in length)
1 error

This is a standard example found all over the web. There is a magic ingredient missing (and no, it's not the shitty little semicolons at the end of each line...) :icon_mrgreen:

Paul Kiddie: Creating a MessageBox in Java:
Quote
JOptionPane.showMessageDialog(null,"message","title"));

This creates and shows a message dialog with no parent with message “message and the title “title”.

alvin alexander: Java: JOptionPane showMessageDialog examples
Quote
JOptionPane.showMessageDialog(frame,
        "Problem writing to backup directory: '" + backupDir + "'.");

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4880
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Playing
« Reply #13 on: September 27, 2017, 04:37:33 AM »
 :biggrin:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 7650
  • Assembler is fun ;-)
    • MasmBasic
Integers vs floats vs doubles
« Reply #14 on: October 24, 2017, 10:21:18 AM »
Fixed point math benchmark at FreeBasic forum:
Code: [Select]
Dim As Double d1 = 299991, d2 = 299990, d3 = 1
Dim As Long i1 = 299991, i2 = 299990, i3 = 1
  For k = 1 To 1000
d3 *= d1
d3 /= d2
n += 1
  Next k

Code: [Select]
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz (SSE4)

Result=20669358
20784   cycles for 10 * integers
Result=16585998
16877   cycles for 10 * floats
Result=16585998
15576   cycles for 10 * doubles

14380   cycles for 10 * integers
11637   cycles for 10 * floats
11651   cycles for 10 * doubles

14389   cycles for 10 * integers
11671   cycles for 10 * floats
11678   cycles for 10 * doubles

14402   cycles for 10 * integers
11703   cycles for 10 * floats
11672   cycles for 10 * doubles

97      bytes for integers
109     bytes for floats
109     bytes for doubles