News:

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

Main Menu

Recent posts

#1
Windows API / Re: Using DLGTEMPLATEEX struct...
Last post by NoCforMe - Today at 10:31:22 AM
Quote from: zedd151 on Today at 03:17:22 AMI wanted to eliminate the .rc file altogether, but in memory dialogs seem more trouble than they are worth. (without using macros to do it)
Thinking about this some more, you could create memory dialog templates without using macros, using a function or two.

I'm not suggesting this in my usual anti-macro mode: clearly this is a case where you either need to use a macro (or two), or else some code to construct the memory template. And I honestly don't know which one would be easier.

Actually, once you write either the macro or the template-constructing code, it'd probably be equally easy. (But I think the macro would be more complex to write. JJ's 500 lines sounds about right.)

Anyhow, a function would need to take all the info necessary to create the memory template and lay it out in memory. Rather than a function with a zillion parameters, probably best to put the info in a structure, then pass that structure to the function.

I could probably cobble something like this together, if there's any interest.
#2
The Campus / MOVED: Using DLGTEMPLATEEX str...
Last post by stoo23 - Today at 10:16:39 AM
#3
Windows API / Re: Using DLGTEMPLATEEX struct...
Last post by Vortex - Today at 06:56:03 AM
Hello,

I propose a very pracical method to use binary resource templates : extract the binary data from compiled resource scripts ( .res files ) with a tool. Employing this technique, you don't even need to know about the layout of the structure DLGTEMPLATEEX.

I modified the resource script below to remove the line referring to the menu defined with MENU IDR_MENU

#include "\masm32\include\resource.h"
#define IDR_MENU 10000
#define IDM_ABOUT 10
#define IDM_MNMIZE 20
#define IDM_EXIT 30

MYDIALOG DIALOGEX DISCARDABLE 20, 10, 186, 100, 18481280
STYLE DS_3DLOOK|DS_CENTER|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE
CAPTION "Dialog box"
FONT 12, "System", 700, 0, 1
{
  CONTROL "&About", 110, "Button", WS_TABSTOP, 116, 8, 50, 20, 0, 1234049503
  CONTROL "&Minimize",120, "Button", WS_TABSTOP, 116, 36, 50, 20, 0, 1234049503
  CONTROL "&Exit",130, "Button", WS_TABSTOP, 116, 64, 50, 20
  CONTROL "   Masm Dialog Box", 4000, "Edit", ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 16, 8, 72, 20
}

IDR_MENU MENU
{
  POPUP "&File"
  {
    MENUITEM "&About", IDM_ABOUT
    MENUITEM "&Minimize", IDM_MNMIZE
    MENUITEM "&Exit", IDM_EXIT
  }
}

Running Resource Hacker, load the .res file and save the two components ( the dialog box and the menu ) to .bin files. Convert the bin files to text files with Hutch's Bin2db tool.

You can obtain Resource Hacker from this address :

https://www.angusj.com/resourcehacker/

Here is how the code should look :

.data
include     Dialog.inc
include     Menu.inc

   invoke  GetModuleHandle,0
    xor     ecx,ecx
    invoke  DialogBoxIndirectParam,eax,ADDR Dialog,\
            ecx,ADDR DlgProc,ecx
           
    invoke  ExitProcess,eax

DlgProc PROC USES ebx hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

       .IF uMsg==WM_INITDIALOG

        invoke  LoadMenuIndirect,ADDR Menu
        invoke  SetMenu,hWnd,eax



#4
Windows API / Re: Using DLGTEMPLATEEX struct...
Last post by zedd151 - Today at 05:54:09 AM
Quote from: NoCforMe on Today at 05:44:27 AMA dialog is a window.
Of course.

I have decided not to use 'in memory' dialog boxes after all.
I opted for keeping the simple resource dialog box.  :smiley:  at least for now.

#5
Windows API / Re: Using DLGTEMPLATEEX struct...
Last post by NoCforMe - Today at 05:44:27 AM
Quote from: zedd151 on Today at 12:18:55 AMAny controls can then be added the usual way using CreateWindowEx (as if we were working with a 'window')
A dialog is a window.

But yeah, once you have a dialog you can add whatever you want to it using CreateWindowEx(). But if you know what controls you want to add at the get-go, probably easier to put them into the memory template and let the dialog manager populate the dialog. That way you need zero code to add them, just some data.
#6
Game Development / Re: 4x4 Game version 2
Last post by zedd151 - Today at 05:28:04 AM
New version of the 4x4 game.
This version uses a dialog box as program interface, it also does not use any bitmaps.

The only keyboard functions...
Keyboard Mappings:
Left Arrow = move left
Up Arrow = move up
Right Arrow = move right
Down Arrow = move down

Upon game completion a message box is displayed indicating that the game has been won. All generated games guaranteed to be winnable.

After clicking 'OK' or closing the message box a new game will start immediately.
To close the program click on the red X in upper right corner at any time.



First draft of the new version of the code:
    include \masm32\include\masm32rt.inc

        DlgProc    proto :dword, :dword, :dword, :dword
        randb      proto :dword
        set_board  proto
        scramble    proto :dword, :dword, :dword, :dword, :dword
        painting    proto :dword
       
        cwidth      equ 512    ; desired client area width
        cheight    equ 512    ; desired clien area height
        vpad        equ 16      ; vertical padding for DrawText
        hpad        equ -1      ; horizontal padding for DrawText
        reps        equ  800    ; number of times the initial game board is randomly scrambled

    .data?
    align 16
        board      label byte
        a1          db ?
        a2          db ?
        a3          db ?
        a4          db ?
        b1          db ?
        b2          db ?
        b3          db ?
        b4          db ?
        c1          db ?
        c2          db ?
        c3          db ?
        c4          db ?
        d1          db ?
        d2          db ?
        d3          db ?
        d4          db ?
       
        hInstance  dd ?
        hFont1      dd ?
        GrayPen    dd ?
        WhitePen    dd ?
        GrayBrush  dd ?
       
    .const
        gover  db "Game Over!", 0
        finito  db "Finished!", 0
        align 16
        x1      dd  0 ; board x coordinates
        x2      dd 128
        x3      dd 256
        x4      dd 384
        y1      dd  0 ; board y coordinates
        y2      dd 128
        y3      dd 256
        y4      dd 384
       
    .code

    ;; revised version of dwtoa from masm32.lib - returns string length
    dwtoa_revised proc dwValue:DWORD, lpBuffer:DWORD
        push ebx
        push esi
        push edi
        mov eax, dwValue
        mov edi, [lpBuffer]
        test eax,eax
        jnz sign
      zero:
        mov word ptr [edi],30h
        jmp dtaexit
      sign:
        jns pos
        mov byte ptr [edi],'-'
        neg eax
        add edi, 1
      pos:
        mov ecx, 3435973837
        mov esi, edi
      .while (eax > 0)
        mov ebx,eax
        mul ecx
        shr edx, 3
        mov eax,edx
        lea edx,[edx*4+edx]
        add edx,edx
        sub ebx,edx
        add bl,'0'
        mov [edi],bl
        add edi, 1
      .endw
        mov byte ptr [edi], 0
        mov eax, edi
        sub eax, lpBuffer
        push eax
      .while (esi < edi)
        sub edi, 1
        mov al, [esi]
        mov ah, [edi]
        mov [edi], al
        mov [esi], ah
        add esi, 1
      .endw
        pop eax  ;; string length returned in eax
      dtaexit:
        pop edi
        pop esi
        pop ebx
        ret
    dwtoa_revised endp

    ;; draws the game pieces
    drawcell proc mDC:dword, x:dword, y:dword, lptext:dword, count:dword
    local rcta1:RECT
        push esi
        push edi
        push ebx
        push edx
        push ecx
        mov eax, x
        mov rcta1.left, eax
        add eax, 128
        mov rcta1.right, eax
        mov eax, y
        mov rcta1.top, eax
        add eax, 128
        mov rcta1.bottom, eax
        invoke FillRect, mDC, addr rcta1, GrayBrush
        mov esi, x
        add esi, 0
        mov edi, y
        add edi, 126
        invoke SelectObject, mDC, WhitePen
        invoke MoveToEx, mDC,  esi, edi, 0
        sub edi, 126
        invoke LineTo,  mDC,  esi,  edi
        add esi, 126
        invoke LineTo,  mDC, esi,  edi
        mov esi, x
        add esi, 1
        mov edi, y
        add edi, 127
        invoke SelectObject, mDC, GrayPen
        invoke MoveToEx, mDC,  esi, edi, 0
        add esi, 126
        invoke LineTo,  mDC, esi, edi
        sub edi, 126
        invoke LineTo,  mDC, esi,  1
        invoke SelectObject, mDC, hFont1
        mov eax, x
        add eax, hpad
        mov rcta1.left, eax
        add eax, 128
        mov rcta1.right, eax
        mov eax, y
        add eax, vpad
        mov rcta1.top, eax
        add eax, 128
        mov rcta1.bottom, eax
        xor edx, edx
        mov dl, a1
        invoke SetBkMode, mDC, TRANSPARENT
        invoke DrawText, mDC, lptext, count, addr rcta1, DT_CENTER or DT_VCENTER
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    drawcell endp

    ;; draw the game pieces in a loop
    painting proc hDC:dword
    local rcta1:RECT, numstring[8]:byte, cnt:dword, xx:dword, yy:dword
        lea edi, board
        lea esi, y1
        mov yy, 0
      top1:
        lea ebx, x1
        mov xx, 0
      @@:
        movzx edx, byte ptr [edi]
      .if edx > 0
        invoke dwtoa_revised, edx, addr numstring
        mov cnt, eax
        mov ecx, [ebx]
        mov edx, [esi]
        invoke drawcell, hDC, [ebx], [esi],  addr numstring, cnt
      .endif
        inc edi
        add ebx, 4
        inc xx
        cmp xx, 4
        jnz @b
        add esi, 4
        inc yy
        cmp yy, 4
        jnz top1
        ret
    painting endp
   
    start proc
        invoke GetModuleHandle, NULL
        mov hInstance, eax
        invoke DialogBoxParam, hInstance, 100, 0, addr DlgProc, 0
        invoke ExitProcess, eax
    start endp

    DlgProc proc hWin:dword, uMsg:dword, wParam:dword, lParam:dword
    local hDC:dword, ps:PAINTSTRUCT, rct:RECT, hBrush:dword, hBrush_old:dword
    local mDC:dword, hBmp:dword, hBmp_old:dword, tmp1:dword
    local x:dword, y:dword, wwid:dword, whgt:dword, cwid:dword, chgt:dword
        .if uMsg == WM_INITDIALOG
          invoke GetWindowRect, hWin, addr rct
          mov eax, rct.right
          sub eax, rct.left
          mov wwid, eax
          mov eax, rct.bottom
          sub eax, rct.top
          mov whgt, eax
          invoke GetClientRect, hWin, addr rct
          mov eax, rct.right
          sub eax, rct.left
          mov cwid, eax
          mov eax, rct.bottom
          sub eax, rct.top
          mov chgt, eax
          mov eax, cwidth
          sub eax, cwid
          add wwid, eax
          mov eax, cheight
          sub eax, chgt
          add whgt, eax
          invoke SystemParametersInfoA, SPI_GETWORKAREA, 0, addr rct, 0
          mov eax, rct.right
          sub eax, wwid
          sar eax, 1
          mov x, eax
          mov eax, rct.bottom
          sub eax, whgt
          sar eax, 1
          mov y, eax
          invoke MoveWindow, hWin, x, y, wwid, whgt, TRUE
          fn RetFontHandle, "Tahoma", 90, 400
          mov hFont1, eax
         
          invoke CreatePen, PS_SOLID, 1, 003F3F73h
          mov GrayPen, eax
          invoke GetStockObject, WHITE_PEN
          mov WhitePen, eax
          invoke GetStockObject, LTGRAY_BRUSH
          mov GrayBrush, eax
         
          invoke set_board
          invoke InvalidateRect, hWin, 0, 0
        .elseif uMsg == WM_KEYUP
          .if wParam == VK_LEFT
            .if      a1 == 0
              mov al, a2
              mov    a1, al
              mov    a2, 0
            .elseif  a2 == 0
              mov al, a3
              mov    a2, al
              mov    a3, 0
            .elseif  a3 == 0
              mov al, a4
              mov    a3, al
              mov    a4, 0
            .elseif  b1 == 0
              mov al, b2
              mov    b1, al
              mov    b2, 0
            .elseif  b2 == 0
              mov al, b3
              mov    b2, al
              mov    b3, 0
            .elseif  b3 == 0
              mov al, b4
              mov    b3, al
              mov    b4, 0
            .elseif  c1 == 0
              mov al, c2
              mov    c1, al
              mov    c2, 0
            .elseif  c2 == 0
              mov al, c3
              mov    c2, al
              mov    c3, 0
            .elseif  c3 == 0
              mov al, c4
              mov    c3, al
              mov    c4, 0
            .elseif  d1 == 0
              mov al, d2
              mov    d1, al
              mov    d2, 0
            .elseif  d2 == 0
              mov al, d3
              mov    d2, al
              mov    d3, 0
            .elseif  d3 == 0
              mov al, d4
              mov    d3, al
              mov    d4, 0
            .endif
            invoke InvalidateRect, hWin, 0, 0
          .elseif wParam == VK_UP
            .if      a1 == 0
              mov al, b1
              mov    a1, al
              mov    b1, 0
            .elseif  a2 == 0
              mov al, b2
              mov    a2, al
              mov    b2, 0
            .elseif  a3 == 0
              mov al, b3
              mov    a3, al
              mov    b3, 0
            .elseif  a4 == 0
              mov al, b4
              mov    a4, al
              mov    b4, 0
            .elseif  b1 == 0
              mov al, c1
              mov    b1, al
              mov    c1, 0
            .elseif  b2 == 0
              mov al, c2
              mov    b2, al
              mov    c2, 0
            .elseif  b3 == 0
              mov al, c3
              mov    b3, al
              mov    c3, 0
            .elseif  b4 == 0
              mov al, c4
              mov    b4, al
              mov    c4, 0
            .elseif  c1 == 0
              mov al, d1
              mov    c1, al
              mov    d1, 0
            .elseif  c2 == 0
              mov al, d2
              mov    c2, al
              mov    d2, 0
            .elseif  c3 == 0
              mov al, d3
              mov    c3, al
              mov    d3, 0
            .elseif  c4 == 0
              mov al, d4
              mov    c4, al
              mov    d4, 0
            .endif
            invoke InvalidateRect, hWin, 0, 0
          .elseif wParam == VK_RIGHT
            .if      a2 == 0
              mov al, a1
              mov    a2, al
              mov    a1, 0
            .elseif  a3 == 0
              mov al, a2
              mov    a3, al
              mov    a2, 0
            .elseif  a4 == 0
              mov al, a3
              mov    a4, al
              mov    a3, 0
            .elseif  b2 == 0
              mov al, b1
              mov    b2, al
              mov    b1, 0
            .elseif  b3 == 0
              mov al, b2
              mov    b3, al
              mov    b2, 0
            .elseif  b4 == 0
              mov al, b3
              mov    b4, al
              mov    b3, 0
            .elseif  c2 == 0
              mov al, c1
              mov    c2, al
              mov    c1, 0
            .elseif  c3 == 0
              mov al, c2
              mov    c3, al
              mov    c2, 0
            .elseif  c4 == 0
              mov al, c3
              mov    c4, al
              mov    c3, 0
            .elseif  d2 == 0
              mov al, d1
              mov    d2, al
              mov    d1, 0
            .elseif  d3 == 0
              mov al, d2
              mov    d3, al
              mov    d2, 0
            .elseif  d4 == 0
              mov al, d3
              mov    d4, al
              mov    d3, 0
            .endif
            invoke InvalidateRect, hWin, 0, 0
          .elseif wParam == VK_DOWN
            .if      b1 == 0
              mov al, a1
              mov    b1, al
              mov    a1, 0
            .elseif  b2 == 0
              mov al, a2
              mov    b2, al
              mov    a2, 0
            .elseif  b3 == 0
              mov al, a3
              mov    b3, al
              mov    a3, 0
            .elseif  b4 == 0
              mov al, a4
              mov    b4, al
              mov    a4, 0
            .elseif  c1 == 0
              mov al, b1
              mov    c1, al
              mov    b1, 0
            .elseif  c2 == 0
              mov al, b2
              mov    c2, al
              mov    b2, 0
            .elseif  c3 == 0
              mov al, b3
              mov    c3, al
              mov    b3, 0
            .elseif  c4 == 0
              mov al, b4
              mov    c4, al
              mov    b4, 0
            .elseif  d1 == 0
              mov al, c1
              mov    d1, al
              mov    c1, 0
            .elseif  d2 == 0
              mov al, c2
              mov    d2, al
              mov    c2, 0
            .elseif  d3 == 0
              mov al, c3
              mov    d3, al
              mov    c3, 0
            .elseif  d4 == 0
              mov al, c4
              mov    d4, al
              mov    c4, 0
            .endif
          .endif
              invoke InvalidateRect, hWin, 0, 0
             
              ;; check for winning condition
              .if a1 ==  1 && a2 ==  2 && a3 ==  3 && a4 ==  4
              .if b1 ==  5 && b2 ==  6 && b3 ==  7 && b4 ==  8
              .if c1 ==  9 && c2 == 10 && c3 == 11 && c4 == 12
              .if d1 == 13 && d2 == 14 && d3 == 15 && d4 ==  0
             
                ;; if winner, display messagebox
                fn MessageBox, 0, addr gover, addr finito, 0
               
                ;; if winner, reset board
                invoke set_board
                invoke InvalidateRect, hWin, 0, 0
                xor eax, eax
                ret
              .endif
              .endif
              .endif
              .endif
        .elseif uMsg == WM_PAINT
          invoke BeginPaint, hWin, addr ps
          mov hDC, eax
          invoke GetClientRect, hWin, addr rct
          invoke CreateCompatibleDC, hDC
          mov mDC, eax
          invoke CreateCompatibleBitmap, hDC, rct.right, rct.bottom
          mov hBmp, eax
          invoke SelectObject, mDC, hBmp
          mov hBmp_old, eax
          invoke CreateSolidBrush, 003F3F3Fh
          mov hBrush, eax
          invoke FillRect, mDC, addr rct, hBrush

          invoke painting, mDC  ; paint the game pieces
         
          invoke BitBlt, hDC, 0, 0, rct.right, rct.bottom, mDC, 0, 0, SRCCOPY
          invoke SelectObject, mDC, hBmp_old
          invoke DeleteObject, hBmp
          invoke DeleteObject, hBrush
          invoke DeleteDC, mDC
          invoke EndPaint, hWin, addr ps
        .elseif uMsg == WM_CLOSE
          invoke EndDialog, hWin, 0
        .endif
        xor eax, eax
        ret
    DlgProc endp

    ;; prng based on nrandom in masm32.lib
    randb proc base:dword
    .data?
        randseed dd ?
    .code
        push esi
        push edi
        push ebx
        push edx
        push ecx
        invoke GetTickCount
        add randseed, eax
        mov eax, randseed
        xor edx, edx
        mov ecx, 127773
        div ecx
        mov ecx, eax
        mov eax, 16807
        mul edx
        mov edx, ecx
        mov ecx, eax
        mov eax, 2836
        mul edx
        sub ecx, eax
        xor edx, edx
        mov eax, ecx
        mov randseed, ecx
        div base
        mov eax, edx
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    randb endp

    ;; scrambles the game board somewhat randomly 1 iteration
    scramble proc dst:dword, Below:dword, Right:dword, Above:dword, Left:dword
        push esi
        push edi
        push ebx
        push edx
        push ecx
        mov ecx, dst
        mov edx, Below
        mov ebx, Right
        mov esi, Above
        mov edi, Left
        invoke randb, 4
      .if      byte ptr [ecx] == 0 && eax == 0
        mov al, byte ptr [edx]
        mov    byte ptr [ecx], al
        mov    byte ptr [edx], 0
      .elseif  byte ptr [ecx] == 0 && eax == 1
        mov al, byte ptr [ebx]
        mov    byte ptr [ecx], al
        mov    byte ptr [ebx], 0
      .elseif  byte ptr [ecx] == 0 && eax == 2
        mov al, byte ptr [esi]
        mov    byte ptr [ecx], al
        mov    byte ptr [esi], 0
      .elseif  byte ptr [ecx] == 0 && eax == 3
        mov al, byte ptr [edi]
        mov    byte ptr [ecx], al
        mov    byte ptr [edi], 0
      .endif
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    scramble endp
   
    ;; scrambles the game board somewhat randomly for 'reps' number of iterations
    set_board proc
    local ctr1:dword
        mov ctr1, 0
        mov a1, 1
        mov a2, 2
        mov a3, 3
        mov a4, 4
        mov b1, 5
        mov b2, 6
        mov b3, 7
        mov b4, 8
        mov c1, 9
        mov c2, 10
        mov c3, 11
        mov c4, 12
        mov d1, 13
        mov d2, 14
        mov d3, 15
        mov d4, 0
      top:
        inc ctr1
        invoke scramble, addr a1, addr b1, addr a2, addr a1, addr a1
        invoke scramble, addr a2, addr b2, addr a3, addr a2, addr a1
        invoke scramble, addr a3, addr b3, addr a4, addr a3, addr a2
        invoke scramble, addr a4, addr b4, addr a4, addr a4, addr a3
        invoke scramble, addr b1, addr c1, addr b2, addr a1, addr b1
        invoke scramble, addr b2, addr c2, addr b3, addr a2, addr b1
        invoke scramble, addr b3, addr c3, addr b4, addr a3, addr b2
        invoke scramble, addr b4, addr c4, addr b4, addr a4, addr b3
        invoke scramble, addr c1, addr d1, addr c2, addr b1, addr c1
        invoke scramble, addr c2, addr d2, addr c3, addr b2, addr c1
        invoke scramble, addr c3, addr d3, addr c4, addr b3, addr c2
        invoke scramble, addr c4, addr d4, addr c4, addr b4, addr c3
        invoke scramble, addr d1, addr d1, addr d2, addr c1, addr d1
        invoke scramble, addr d2, addr d2, addr d3, addr c2, addr d1
        invoke scramble, addr d3, addr d3, addr d4, addr c3, addr d2
        invoke scramble, addr d4, addr d4, addr d4, addr c4, addr d3
        cmp ctr1, reps
        jl top
        ret
    set_board endp

    end

Object of the game is to arrange the game pieces in ascending numerical order like this, using the keyboard arrow keys:

 1  2  3  4
 5  6  7  8
 9 10 11 12
13 14 15   


:smiley:

Edit: I noticed that I had not preserved the registers in the 'painting' procedure. That will be fixed in the release version.  :eusa_boohoo:
#7
Windows API / Re: Using DLGTEMPLATEEX struct...
Last post by zedd151 - Today at 03:25:34 AM
Anyway here are two versions of 4x4, that I am currently working on.

They both use a resource dialog box in place of a 'real' window.
One uses bitmaps, the other no bitmaps. The bitmaps look like crap. Originally they were 32x32 and looked okay, but I had doubled their size to display larger.  :rolleyes:

Changing from a window to dialog box only yielded a slight reduction in code size.
Removing the bitmaps was of course a much greater reduction in size.

I still have to clean up the code, use loops where possible to further reduce the code, other minor details, etc., and a couple of other changes still need to be made before I post the source code.
Once finished, I will post the source in the Game Development board.
#8
Windows API / Re: Using DLGTEMPLATEEX struct...
Last post by zedd151 - Today at 03:17:22 AM
Quote from: jj2007 on Today at 02:50:45 AMI prefer event-driven programming with "real" windows :cool:
I usually do use real windows too. But I have been working with dialog boxes recently, and am converting some old code, switching from using windows to dialog boxes, and eliminating butmaps. I wanted to eliminate the .rc file altogether, but in memory dialogs seem more trouble than they are worth. (without using macros to do it)
#9
The Orphanage / Re: 128-bit integer arithmetic...
Last post by zedd151 - Today at 03:09:03 AM
Quote from: jack on Today at 03:06:22 AMI had forgotten to zero out the sum for the second test, so it just kept adding, it's fixed now if you want to download the binary
:biggrin:

Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz  3.60 GHz

multiply n times d 100000000 times in a loop
a sum of the product is kept and printed out
in order to prevent gcc from eliminating the loop
and thereby making the timing meaningless

n = 340282366920938463447387429234553266722
d = 18446744073709551615
product = 45370982256125128475310893311622766046
sum of product = 113427455641665582386530236262442737152
assembler version
elapsed time seconds  0.338004100020044

n = 340282366920938463447387429234553266722
d = 18446744073709551615
product = 45370982256125128475310893311622766046
sum of product = 113427455641665582386530236262442737152
high level version
elapsed time seconds  0.0723988000536337

press return to end

perfect.  :azn:
Side note: A humongous difference between unoptimised C version and optimized C version. Biterider might have to tweak his code (or you may need to tweak your conversion) to be a contender.  :tongue:

These huge numbers remind me of my experiments with my 'ascii_adder' routine. It added two humongous ascii decimal strings of any length together, outputting an ascii string on return. May be good for working with the U.S. national debt?  :biggrin:
#10
The Orphanage / Re: 128-bit integer arithmetic...
Last post by jack - Today at 03:06:22 AM
Quote from: zedd151 on Today at 02:58:19 AMBut wait, something is amiss.
'sum of product = 226854911283331164773060472524885474304' - for the high level version in my test?

and 'sum of product = 113427455641665582386530236262442737152' - for the high level version in your test.
I had forgotten to zero out the sum for the second test, so it just kept adding, it's fixed now if you want to download the binary