Recent Posts

Pages: [1] 2 3 ... 10
1
MasmBasic & the RichMasm IDE / Re: MasmBasic
« Last post by jj2007 on Today at 05:32:39 PM »
There are no MMX instructions in MasmBasic (MMX code is inefficient, and there are conflicts with the FPU).

For calculations, the FPU is generally being used; it's not faster (and not slower) than the corresponding SSE* instructions, but internally it gives REAL10 precision, while SSE* offers only double precision, i.e. REAL8.

SSE* code is generally not shorter than ordinary x86 (but there are exceptions). However, it's often a lot faster. Take a simple example, getting the length of a zero-delimited string. There is a little thread here showing how the Masm32 team developed the current MasmBasic Len() macro. The thread has 149 replies, meaning it took a while to find the fastest option. Check yourself how fast it is, compared to the strlen function of the C runtime library (remember C is the fastest language on Earth :P):

Code: [Select]
include \masm32\MasmBasic\MasmBasic.inc
  Init
  Recall "\Masm32\include\Windows.inc", L$() ; get a string array
  push eax ; #elements
  xor ebx, ebx
  xor edi, edi
  NanoTimer()
  .Repeat
invoke crt_strlen, L$(ebx)
add edi, eax ; calculate total len
inc ebx
  .Until ebx>=stack
  Print "The CRT needs ", NanoTimer$(), Str$(" for calculating the length of %i strings", ebx), Str$(", a total of %i bytes\n", edi)
  xor ebx, ebx
  xor edi, edi
  NanoTimer()
  .Repeat
add edi, Len(L$(ebx)) ; calculate total len
inc ebx
  .Until ebx>=stack
  pop edx
  Inkey " MB Len needs ", NanoTimer$(), Str$(" for calculating the length of %i strings", ebx), Str$(", a total of %i bytes\n", edi)
EndOfCode

Note that Windows.inc has relatively short strings. The difference between the speed of Len vs crt_strlen is much bigger for long strings. For example, if you apply the code above to a bible.txt file, with longer strings, the difference is twice as much. I won't tell you how much because there a C/C++ coders here in the forum, and they might fall into a deep depression if they see the results :icon_cool: 

Attached a full example, comparing also the Instr() performances of MasmBasic and the CRT (if that sounds interesting, see Benchmark 2: Alice in Wonderland for a CRT strstr vs Boyer-Moore comparison)
2
The Laboratory / Re: on-chip random numbers
« Last post by hutch-- on Today at 05:11:18 PM »
Rudi,

Thanks for the link, its an interesting read and gives you every good reason to avoid anything that is well known in the field of encryption as it is probably compromised before it hits the market. Its the normal response, if the good guys (sic) can use it, the bad guys can as well. Any of the big players already know this and I imagine that any of them already have very big computer grunt for breaking anything that relies on the key bit size.

The stupid part is that anyone who seriously needs to encrypt data is not using crap like this, they are using their own techniques and this goes for fruitcakes like the Islamic State, spies of any of the government agencies, truly big business and folks doing secret research on some massive range of subjects. Security agencies grabbing at information are not doing it for security reasons, they are doing it for control and clandestine theft of technology.
3
MasmBasic & the RichMasm IDE / Re: MasmBasic
« Last post by 2B||!2B on Today at 04:51:57 PM »
I have a question. Why do you use FPU/MMX/SSE instructions set so often? are there any advantages by using them rather than using the standard x86 instructions set? like faster execution, smaller code size maybe?
4
Game Development / Re: Directx 9 last shot (at least for now)
« Last post by felipe on Today at 03:25:07 PM »
    push    FLT4(1.0)

Remember felipe is allergic against macros :eusa_naughty:

 :biggrin: This macro code actually helped me to see that i can't move directly a float to a register, i mean like an immediate operand. I didn't knew that. Seems like we need to initialize all of them.

Siekmanski thanks again very much, this has been actually, i think, a great contribution to the masm32 sdk. I have to go to sleep now  (i was too excited to wait until tomorrow to try to code with this great help). From tomorrow i will start to learn more about directx9. Here is the same "idea" that i posted here (the first reply) but without c code:
Code: [Select]
.686
.model      flat,stdcall
option      casemap:none
include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc
include     \masm32\include\gdi32.inc
includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\gdi32.lib

include     \masm32\include\DX9Includes\d3d9.inc

 
SCREEN_WIDTH    equ 1024                     ; Kind of old standard
SCREEN_HEIGHT   equ 768                             ;   resolution.

.data
align 1
class_name      byte        "main window class",0
wnd_name        byte        "DIRECTX9 TEST",0
d3d9_lib        byte        "d3d9.dll",0
dx9func0        byte        "Direct3DCreate9",0

align 4
float4          dword       1.0

.data?
align 4
hinstance       dword       ?
hwindow         dword       ?
bye           dword     ?
hdll            dword       ?
proc_add        dword       ?
inter_add       dword       ?
d3dpp           D3DPRESENT_PARAMETERS <?>
d3ddev          dword       ?





.code
align 4
start:
            push        ebp
            mov         ebp,esp

            push        NULL                                                ; Get a handle for the program instance.
            call        GetModuleHandle
           
            mov         hinstance,eax
           
            sub         esp,76                                              ; WNDCLASSEX and MSG.
                                           
            mov         dword ptr[ebp-48],48                                ; The size of the structure.
            mov         dword ptr[ebp-44],CS_HREDRAW or CS_VREDRAW          ; The style of the class.
            mov         [ebp-40],wndproc
            mov         dword ptr[ebp-36],0                                 ; No extra
            mov         dword ptr[ebp-32],0                                 ;   bytes.
            mov         eax,hinstance
            mov         [ebp-28],eax

            mov         dword ptr[ebp-24],NULL                              ; No icon.

            push        IDC_ARROW                                           ; The system cursor.
            push        NULL                                             
            call        LoadCursor

            mov         [ebp-20],eax                                        ; hCursor.

            push        WHITE_BRUSH                                         ; Typical background color for a window.
            call        GetStockObject                                      ; Get the handle of the brush.

            mov         [ebp-16],eax                                        ; hBrush.
            mov         dword ptr[ebp-12],NULL                              ; No menu.
            mov         [ebp-8],offset class_name
            mov         dword ptr[ebp-4],NULL                               ; Use the same app icon for the small one.

            lea         eax,[ebp-48]                                        ; WNDCLASSEX.

            push        eax
            call        RegisterClassEx

            push        NULL                                                ; No value passed to the window.
            push        hinstance
            push        NULL                                                ; No menu.
            push        NULL                                                ; No parent of the window.
            push        SCREEN_HEIGHT                                       ; Old standar
            push        SCREEN_WIDTH                                        ;   resolution.
            push        CW_USEDEFAULT                                       ; Default position
            push        CW_USEDEFAULT                                       ;  of the window.
            push        WS_EX_TOPMOST or WS_VISIBLE or WS_POPUP             ; Game window style.
            push        offset wnd_name                                     ; Name of the game window.   
            push        offset class_name
            push        WS_EX_TOPMOST     ; Some extension of the style.
            call CreateWindowEx

            mov         hwindow,eax

            push        SW_SHOWNORMAL                                       ; Displaying the window for the first time.
            push        eax
            call        ShowWindow                                         

            push        hwindow
            call        UpdateWindow                                        ; Update the client area.

            push        offset d3d9_lib
            call        LoadLibrary                                         ; Load d3d9.dll to the address space of this program.

            mov         hdll,eax                                            ; Handle to the module loaded.

            push        offset dx9func0                                     ; Direct3DCreate9.
            push        eax                                                 ; hdll.
            call        GetProcAddress                                      ; Get the address of the dx9 function.

            mov         proc_add,eax                                        ; Save the address of the funtion Direct3DCreate9.

            push        D3D_SDK_VERSION
            call        eax                                                 ; Call the function Direct3DCreate9.
           
            mov         inter_add,eax                                       ; Safe the com interface address.                                 

            mov         esi,offset d3dpp
            mov         ecx,14                                              ; There are 14 dword members in this structure.

align 4
fill_struc:
            mov        dword ptr[esi],0
            add        esi,4                                                ; Next field.
            loop       fill_struc                                           ; Fill the structure with 0.

            mov        esi,offset d3dpp
   
    mov        dword ptr[esi+0],SCREEN_WIDTH                        ; Backbuffer width.
    mov        dword ptr[esi+4],SCREEN_HEIGHT                       ; Backbuffer height.
            mov        dword ptr[esi+8],D3DFMT_X8R8G8B8                     ; Backbuffer format.
            mov        dword ptr[esi+12],1                                  ; Backbuffer count.
            mov        dword ptr[esi+24],D3DSWAPEFFECT_DISCARD              ; Swap effect.
            mov        eax,hwindow
            mov        dword ptr[esi+28],eax                                ; device window.
            mov        dword ptr[esi+32],FALSE                              ; Not windowe, we want fullscreen.
     
            push        offset d3ddev
            push        offset d3dpp
            push        D3DCREATE_SOFTWARE_VERTEXPROCESSING
            push        eax                                                 ; hwindow
            push        D3DDEVTYPE_HAL
            push        D3DADAPTER_DEFAULT

            mov         eax,inter_add                                       ; Com interface address.
            push        eax
            mov         eax,[eax]                                           
            call        dword ptr[eax+IDirect3D9_CreateDevice]              ; Call com interface method CreateDevice.       

    lea         esi,[ebp-76]             ; MSG.
    mov bye,0     ; Flag to stop the game loop.

                   
align 4
msgloop:           
    push        PM_REMOVE                                           ; Pull out messages.
            push        0                                                   ; Retrieve all
            push        0                                                   ;  available messages.
            push        NULL                                                ; Messages of any window of this thread.
            push        esi                     ; MSG.
            call        PeekMessage       

    cmp eax,0
    je no_msg     ; No messages yet. Give the game the resources.

    push        esi
            call        TranslateMessage                                    ; Translate keyboard to messages.

            push        esi
            call        DispatchMessage                                     ; Dispatch messages to wndproc.

            cmp         bye,1
    je end_program             ; Check if the game is over.

align 4
no_msg:
            push        0
            push        float4
            push        00ff0000h                                           ; Color.
            push        D3DCLEAR_TARGET
            push        NULL
            push        0

            mov         eax,d3ddev                                          ; Com interface address.
            push        eax
            mov         eax,[eax]
            call        dword ptr[eax+IDirect3DDevice9_Clear]               ; Call the com interface method.
           
            mov         eax,d3ddev
            push        eax
            mov         eax,[eax]
            call        dword ptr[eax+IDirect3DDevice9_BeginScene]

            mov         eax,d3ddev
            push        eax
            mov         eax,[eax]
            call        dword ptr[eax+IDirect3DDevice9_EndScene]

            push        NULL               
            push        NULL
            push        NULL
            push        NULL
            mov         eax,d3ddev
            push        eax               
            mov         eax,[eax]         
            call        dword ptr[eax+IDirect3DDevice9_Present]     

    push VK_ESCAPE
    call GetAsyncKeySt            ; The esc key turns off the game.

     test eax,80000000h
     jz keep_rolling                 ; If is not pressed keep playing.

     push 0
     push 0
     push WM_DESTROY
     push hwindow
     call PostMessage            ; If pressed let start to shutdown the game.

align 4
keep_rolling:
    jmp msgloop                                    ; All again.


align 4
end_program:
            mov         eax,[ebp-68]                                        ; wParam (exit code).

            mov         esp,ebp
            pop         ebp
 
            push        eax                                 
            call        ExitProcess                                         ; End the program.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

align 4
wndproc:                                                                    ; The window procedure for the main window class.
            push        ebp
            mov         ebp,esp

            cmp         dword ptr[ebp+12],WM_DESTROY            ; Game over.
            jne do_the_default


            cmp         d3ddev,NULL
            je          skip_cleaning
           
            mov         eax,d3ddev
            push        eax               
            mov         eax,[eax]         
            call        dword ptr[eax+IUnknown_Release]

            cmp         inter_add,NULL
            je          skip_cleaning

            mov         eax,inter_add
            push        eax               
            mov         eax,[eax]         
            call        dword ptr[eax+IUnknown_Release]


align 4
skip_cleaning:
            push        0                                                   ; Exit code (wParam in WM_QUIT).
            call        PostQuitMessage                                     ; Notify to windows that is the end of the application.   

            mov bye,1     ; To stop the game loop.


            xor         eax,eax
           
            mov         esp,ebp
            pop         ebp
           
            ret         16



align 4
do_the_default:
    push        dword ptr[ebp+20]                                   ; lParam.
            push        dword ptr[ebp+16]                                   ; wParam.
            push        dword ptr[ebp+12]                                   ; The message.
            push        dword ptr[ebp+8]                                    ; Handle of the window.
            call        DefWindowProc                                       ; Default processing for all the other messages.

            mov         esp,ebp
            pop         ebp

            ret         16
           
            end         start

 The .exe is attached. Remember to escape the fullscreen with the esc key.

 :icon_mrgreen: I'm very happy.

Afterall, we all have our own coding styles, I like mine the most.  :bgrin:

Is true. Your coding style is very clear. I'm trying to improve mine. But in the code above i didn't do too much effort to refine it because i was very hurry trying to probe it. I have a lot to learn. What i couldn't understand yet is why we need to push the address of the com interface always, before we get the value of the first method (i think?). Well tomorrow more research now to the bed... :icon_mrgreen:
 :greenclp:  :icon14:
5
Game Development / Re: Directx 9 last shot (at least for now)
« Last post by aw27 on Today at 03:18:28 PM »
Nice job!
A couple of years ago I was studying a way to use the Desktop Duplication API to transfer changed screen rectangles to a remote computer. It requires DirectX 11/DXGI 1.2. I have also made an article about that. Although I know how to save rectangles to bitmaps and send them across the network, of course, I ended up not pursuing the project because my current implementation is already very fast and at the time I could not figure out a good way to handle it on the receiver side.
6
The Laboratory / Re: on-chip random numbers
« Last post by Raistlin on Today at 02:59:15 PM »
D@mn!t  - oh well. That is strange though, TSX/HLE has been around since 2014 (Haswell).
 
7
The Campus / Re: New to MASM32, where to start?
« Last post by LoGiCaL__ on Today at 02:48:02 PM »
Just be careful, they are 20 years old and some of them have mistakes in them. There is later and better thought out examples available so don'r be afraid to ask questions on bits that you may not understand.

Will do, thanks for the tip!
8
The Campus / Re: New to MASM32, where to start?
« Last post by hutch-- on Today at 02:46:47 PM »
Just be careful, they are 20 years old and some of them have mistakes in them. There is later and better thought out examples available so don'r be afraid to ask questions on bits that you may not understand.
9
The Campus / Re: New to MASM32, where to start?
« Last post by zedd151 on Today at 02:28:16 PM »
Awesome, thanks!!!

No problem. A lot of new members find Iczelions Tutorials invaluable.
10
The Campus / Re: New to MASM32, where to start?
« Last post by LoGiCaL__ on Today at 02:25:11 PM »
Awesome, thanks!!!
Pages: [1] 2 3 ... 10