The MASM Forum

General => The Campus => Topic started by: zedd151 on May 19, 2018, 11:20:02 AM

Title: converting 32 bit code to 64 bit
Post by: zedd151 on May 19, 2018, 11:20:02 AM
What are the major differences, and most importantly obstacles for a newcomer to 64 bit asm programming?  I have looked some 64 bit code, and read some very confusing material regarding the subject. So any pointers from someone who successfully has already made such conversions are welcome.

Otherwise I'll probably stick to 32 bit until it becomes obsolete.   :P


My very first 64 bit program. It's a whopper!   :icon_mrgreen:

I don't think this 64 bit stuff will be too hard.   :icon_confused:

edit == add attachment   :biggrin:
Title: Re: converting 32 bit code to 64 bit
Post by: hutch-- on May 19, 2018, 02:27:53 PM
Z,

64 bit in Windows is a different animal under the hood, different calling convention, critical alignment or it won't run and with ML64, its a lower level assembler that is very terse as its not a consumer product. You can also have a look at UASM which is progressing in its capacity if you go to its sub forum.

With small apps, 32 bit code is fine, easily fast enough, well understood and a bit friendlier than 64 bit code. At the other end 64 bit assembler has more registers and is capable of bashing very large amounts of data into shape. The 64 bit version I have been writing where you have to obtain the Microsoft binaries yourself is already application capable and has a reasonable amount of macro support as well as an ever increasing library of its own.

I don't know enough about it to evaluate it but nidud also has another fork from JWASM which you may be interested in looking at.
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 19, 2018, 02:43:37 PM
Z,

64 bit in Windows is a different animal under the hood, different calling convention

I found that out while trying to convert one of my proggies to 64 bit, and it just wasn't working the way I thought it should. So I will be doing plenty of reading on 64 assembly. 

Quote
At the other end 64 bit assembler has more registers and is capable of bashing very large amounts of data into shape.
I'm mostly interested in keeping up with the times.

Quote
The 64 bit version I have been writing where you have to obtain the Microsoft binaries yourself is already application capable and has a reasonable amount of macro support as well as an ever increasing library of its own.

Yup, I've already got the 64 bit binaries as well as the masm64 SDK all set to try and make a run for it. I just have to figure a way to reconcile what I know about 32 bit programming with the differences in 64 bit. Thanks for the reply.
Title: Re: converting 32 bit code to 64 bit
Post by: hutch-- on May 19, 2018, 02:54:44 PM
Z,

Have a read of the technical data supplied with the 64 bit version as it has a reasonable amount of detail on how the win64 bit calling convention works. The combined STACKFRAME macros and "invoke" macros (its actually a wrapper for a more generic version) take most of the hack work out of it and you can certainly write no stack frame code once you understand how the calling convention works.

From your 32 bit experience the mnemonics work much the same way, they are just bigger. You have more registers which is a true joy but you must work with the Microsoft 64 bit ABI in terms of registers you must preserve. Also exercise great care with trying to use PUSH / POP as you can mess up the stack alignment and the exe just won't run. Within a stack frame procedure you are better off using locals for preserving registers as you don't risk messing up the stack. Generally a "mov" is faster than a PUSH or POP, it just looks different.
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 19, 2018, 02:56:51 PM
@hutch--

 :t

z
Title: Re: converting 32 bit code to 64 bit
Post by: daydreamer on May 19, 2018, 04:47:49 PM
So for coders that prefer fastcall c calling convention and old code style a plot proc designed to use 3 register as x,y,c it must be easier and faster
And once getting used to 64bit coding,you can concentrate on make your code run with newest os and don't worry about xp compatibility
Do you get some size penalty similar to 16/32bit gives you db 66h extra when using mov eax in 16bit mode,mov ax in 32bit mode?
Unicode support standard in 64bit windows? In textarea,messageboxes and other gui stuff?

I prefer 128bit/256bit/512bit coding,even if it's not needed

Title: Re: converting 32 bit code to 64 bit
Post by: AW on May 19, 2018, 04:56:17 PM
This is the only thing you need to get started and become a great 64-bit programmer.
https://software.intel.com/en-us/articles/introduction-to-x64-assembly

Alternatively, you can try some go-easy routes and next year you will know exactly as much as you know now (zero).
Title: Re: converting 32 bit code to 64 bit
Post by: Mikl__ on May 19, 2018, 06:21:07 PM
Hi, zedd151!
let's see the content of the topic Examples for Win64 Iczelion tutorial (http://masm32.com/board/index.php?topic=4190.0)
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 19, 2018, 07:00:14 PM

let's see the content of the topic Examples for Win64 Iczelion tutorial (http://masm32.com/board/index.php?topic=4190.0)

I've seen the thread, but didn't have much interest until I got this new computer. Just what a starter in 64 bits needs. Thanks.  :t

@aw27, I have seen that as well during my surfing the net for intelligible info on 64 bit programming in assembly. That's good knowledge there.  :icon14:
Title: Re: converting 32 bit code to 64 bit
Post by: Mikl__ on May 19, 2018, 07:53:24 PM
Quote
Just what a starter in 64 bits needs
zedd151,
but you ask and I will answer to you. And I warn you right away, my English is is the worst, only via google-translator
Title: Re: converting 32 bit code to 64 bit
Post by: LordAdef on May 22, 2018, 02:19:51 AM
Hey Hutch,
How is your development of the 64bit Masm? I tend to be far away from the Masm 64, since I'm still learning the 32 one. Is it progressing as you expect?
Title: Re: converting 32 bit code to 64 bit
Post by: hutch-- on May 22, 2018, 02:42:39 AM
Alex,

It is already application capable, has a large collection of macros and about 110 library modules. It is fully Microsoft ABI compliant, uses the correct calling convention and you can use it to do more or less anything you like. I have some documentation done but its a really tedious task while I keep adding to the library but the source code for the modules contain most of the required data.

You can convert 32 to 64 bit but you must understand both to do it. Both Win64 and ML64 are highly intolerant so its a bit harder to get working but it has its advantages, more registers and will handle very large data if you need to. You can get a lot of the code to look very similar and the mnemonics work mush the same way but it is a different animal under the hood, you can code applications with it at very low level but its a pain to do with the complexity of the calling convention.
Title: Re: converting 32 bit code to 64 bit
Post by: felipe on May 23, 2018, 01:44:01 PM
This is the only thing you need to get started and become a great 64-bit programmer.
https://software.intel.com/en-us/articles/introduction-to-x64-assembly

Quote
RIP-relative addressing: this is new for x64 and allows accessing data tables and such in
the code relative to the current instruction pointer, making position independent code
easier to implement.
MOV AL, [RIP] ; RIP points to the next instruction aka NOP
NOP

 :greenclp:

Quote
Unfortunately, MASM does not allow this form of opcode

 :(
Title: Re: converting 32 bit code to 64 bit
Post by: AW on May 23, 2018, 05:10:51 PM
Quote
:(
It is propaganda, nobody needs that, MASM embeds RIP-relative addressing implicitly.
But for those who are using that as an excuse they have various alternatives. This is possibly the smallest one:

lea rax, [$+7]

and rax points to the next instruction.
Title: Re: converting 32 bit code to 64 bit
Post by: felipe on May 24, 2018, 03:48:01 AM
AW, no more excuses to me, i'm putting my head into 64 bits right now!  But, of course, i'm just beginning...Why plus 7, shouldn't be plus 8?  :shock:
Title: Re: converting 32 bit code to 64 bit
Post by: AW on May 24, 2018, 04:20:12 AM
Quote
Why plus 7, shouldn't be plus 8
Felipe,
lea rax, [$+7] is 7 bytes long or is it 8 bytes long?
Title: Re: converting 32 bit code to 64 bit
Post by: felipe on May 24, 2018, 04:28:35 AM
Oh ok, i think i understand now. I was confusing my mind with the addressing of data, but this are opcodes we are talking about... :idea:  :biggrin:
Title: Re: converting 32 bit code to 64 bit
Post by: felipe on May 24, 2018, 04:51:08 AM
I remember when i used the debug program (from DOS). It was very usefull for some cases, like writting whatever code (without assembler directives) and to see the opcodes and operands (of course) almost inmmediately. Counting bytes there were easier...Is there a tool like this one for 64 bits or 32 bits? Olly support this kind of feature? I mean like opening your debugger, write a command like -a to start writing assembly instructions. Then save this and then see the opcodes with operands in each line, along with the assembly instructions. I know you can produce an assembly listing with opcodes, but that involves writting a program with at least some directives, etc. I'm not trying to be lazy  :biggrin:  , i'm just having an appetite for some utility like this. If anybody knows one, please let me know.  :idea:
I think may be useful to look this kind of things in a fast way.  :idea:
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 25, 2018, 07:28:27 AM

Code: [Select]

    include \masm32\include64\masm64rt.inc
    .data
    .data?
    .code

   

    entry_point proc
    invoke MessageBox,0,"Hello World","Title",MB_OK
    invoke ExitProcess, 0
    entry_point endp
   
    end


disassembles to this: (x64dbg.exe)

Code: [Select]

.code
00007FF60F181000 | enter 80,0                                |
00007FF60F181004 | sub rsp,60                                |
00007FF60F181008 | mov rcx,0                                 |
00007FF60F18100F | mov rdx,qword ptr ds:[7FF60F18306C]       | rdx:EntryPoint, 00007FF60F18306C:&"Hello World"
00007FF60F181016 | mov r8,qword ptr ds:[7FF60F183086]        | 00007FF60F183086:&"Title"
00007FF60F18101D | mov r9,0                                  | r9:EntryPoint
00007FF60F181024 | call qword ptr ds:[<&MessageBoxA>]        |
00007FF60F18102A | mov rcx,0                                 |
00007FF60F181031 | call qword ptr ds:[<&ExitProcess>]        |

.data
00007FF60F183000  0D 0A 00 00 30 18 0F F6 7F 00 00 0D 0A 00 0B 30  ....0..ö.......0 
00007FF60F183010  18 0F F6 7F 00 00 09 00 16 30 18 0F F6 7F 00 00  ..ö......0..ö... 
00007FF60F183020  22 00 20 30 18 0F F6 7F 00 00 3C 00 2A 30 18 0F  ". 0..ö...<.*0.. 
00007FF60F183030  F6 7F 00 00 3E 00 34 30 18 0F F6 7F 00 00 21 00  ö...>.40..ö...!. 
00007FF60F183040  3E 30 18 0F F6 7F 00 00 28 00 48 30 18 0F F6 7F  >0..ö...(.H0..ö. 
00007FF60F183050  00 00 29 00 52 30 18 0F F6 7F 00 00 00 00 00 00  ..).R0..ö....... 
00007FF60F183060  48 65 6C 6C 6F 20 57 6F 72 6C 64 00 60 30 18 0F  Hello World.`0.. 
00007FF60F183070  F6 7F 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ö............... 
00007FF60F183080  54 69 74 6C 65 00 80 30 18 0F F6 7F 00 00 00 00  Title..0..ö..... 


So, the converting of the arguments to registers is automatically done by the ?? preprocessor?
And what about the text strings, how and when are they put into the data section. I don't
fully understand.

Ooops, I see that I didn't put a "ret"
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 25, 2018, 09:37:07 AM
Here's a 'converted' example that doesn't fully work. It has been literally converted from 32 bit. It assembles and links okay with the bat file
but hangs during 'board' creation while trying to run.   :(

This very same program was used as a compatibility test for os's other than windows xp. It ran well as 32 bit program, and I can't figure out
what the exact problem. I know its stuck in a loop, and I tried changing rip to get out of the loop in debugger, window displays, but just a
black background.


Code: [Select]


        include \masm32\include64\masm64rt.inc


; ##############################################################################

        WinMain         proto :qword
        WndProc         proto :qword, :qword, :qword, :qword
        randb           proto :qword
        set_board       proto :qword, :qword
        find_mt         proto :qword, :qword
        painting        proto :qword, :qword, :qword
        moveit          proto :qword, :qword, :qword, :qword, :qword, :qword, :qword

; ##############################################################################

    .data
        CommandLine     dq 0
        hWnd            dq 0
        hInstance       dq 0
       
        Wwd             dq 262
        Wht             dq 288
       
        hBmp0           dq 0
        hBmp1           dq 0
        hBmp2           dq 0
        hBmp3           dq 0
        hBmp4           dq 0
        hBmp5           dq 0
        hBmp6           dq 0
        hBmp7           dq 0
        hBmp8           dq 0
        hBmp9           dq 0
        hBmp10          dq 0
        hBmp11          dq 0
        hBmp12          dq 0
        hBmp13          dq 0
        hBmp14          dq 0
        hBmp15          dq 0
       
        sqct            db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                       
        board           db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0
                        db 0

        mtoffset        db 0
                       
        szClassName     db "Game_Class", 0
        szDisplayName   db "4x4 Game", 0

; ##############################################################################

    .code

    entry_point proc
        invoke GetModuleHandle, 0
        mov hInstance, rax
        invoke WinMain, hInstance
        invoke ExitProcess, 0
    entry_point endp
; ##############################################################################

    WinMain proc hInst:qword
    local wc:WNDCLASSEX, msg:MSG, Wtx:qword, Wty:qword
   
    ; --------------------------------------------------
    ; fill the WNDCLASSEX structure with needed data
    ; --------------------------------------------------
   
        mov wc.cbSize, sizeof WNDCLASSEX
        mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
        lea rax, WndProc
        mov wc.lpfnWndProc, rax
        mov wc.cbClsExtra, 0
        mov wc.cbWndExtra, 0
        push hInst
        pop wc.hInstance
        mov wc.lpszMenuName, 0
        lea rax, szClassName
        mov wc.lpszClassName, rax
       
    ; --------------------------------------------------
    ; set background color
    ; --------------------------------------------------
   
        invoke CreateSolidBrush, 0
        mov wc.hbrBackground, rax

    ; --------------------------------------------------
    ; load icon
    ; --------------------------------------------------
   
        invoke LoadIcon, hInst, 1234
        mov wc.hIcon, rax

        ; use same handle for small icon
   
        push wc.hIcon
        pop wc.hIconSm
       
    ; --------------------------------------------------
    ; load cursor
    ; --------------------------------------------------
   
        invoke LoadCursor, 0, IDC_ARROW
        mov wc.hCursor, rax


    ; --------------------------------------------------
    ; register class
    ; --------------------------------------------------
   
        invoke RegisterClassEx, addr wc

    ; --------------------------------------------------
    ; center window to screen
    ; --------------------------------------------------
   
        invoke GetSystemMetrics, SM_CXSCREEN
        shr rax, 1
        mov rdx, Wwd
        shr rdx, 1
        sub rax, rdx
        mov Wtx, rax
       
        invoke GetSystemMetrics, SM_CYSCREEN
        shr rax, 1
        mov rdx, Wht
        shr rdx, 1
        sub rax, rdx
        mov Wty, rax

    ; --------------------------------------------------
    ; create main window
    ; --------------------------------------------------
   
        invoke CreateWindowEx, 0, addr szClassName, addr szDisplayName, \
                                WS_CAPTION or WS_SYSMENU or WS_VISIBLE, \
                                Wtx, Wty, Wwd, Wht, 0, 0, hInst, 0
           
        mov hWnd, rax
       
    ; --------------------------------------------------
    ; show & update window
    ; --------------------------------------------------

        invoke ShowWindow, hWnd, SW_SHOWNORMAL
        invoke UpdateWindow, hWnd
       
    ; --------------------------------------------------
    ; message dispatcher
    ; --------------------------------------------------
   
    StartLoop:
        invoke GetMessage, addr msg, 0, 0, 0
        cmp rax, 0
       
        je ExitLoop
            invoke TranslateMessage, addr msg
            invoke DispatchMessage, addr msg
    jmp StartLoop
        ExitLoop:
       
    ; --------------------------------------------------
    ; exit winmain
    ; --------------------------------------------------
 ;         mov rax, msg.wParam
        ret
    WinMain endp
   
; ##############################################################################
align 10h
    WndProc proc hWin:qword, uMsg:qword, wParam:qword, lParam:qword
   
        .if uMsg == WM_CREATE
       
        invoke seed_rrand, 123456786   ;;;;; <--- for use with rrand
       
; ------------------------------------------------------------------------------
; load bitmaps, obtain handles
; ------------------------------------------------------------------------------

        invoke LoadBitmap, hInstance, 100
        mov hBmp0, rax          ; for the 'empty' square
       
        invoke LoadBitmap, hInstance, 101
        mov hBmp1, rax          ; handle # is also the pieces' number,
                                ; for this one and the rest
                               
        invoke LoadBitmap, hInstance, 102
        mov hBmp2, rax
       
        invoke LoadBitmap, hInstance, 103
        mov hBmp3, rax
       
        invoke LoadBitmap, hInstance, 104
        mov hBmp4, rax
       
        invoke LoadBitmap, hInstance, 105
        mov hBmp5, rax
       
        invoke LoadBitmap, hInstance, 106
        mov hBmp6, rax
       
        invoke LoadBitmap, hInstance, 107
        mov hBmp7, rax
       
        invoke LoadBitmap, hInstance, 108
        mov hBmp8, rax
       
        invoke LoadBitmap, hInstance, 109
        mov hBmp9, rax
       
        invoke LoadBitmap, hInstance, 110
        mov hBmp10, rax
       
        invoke LoadBitmap, hInstance, 111
        mov hBmp11, rax
       
        invoke LoadBitmap, hInstance, 112
        mov hBmp12, rax
       
        invoke LoadBitmap, hInstance, 113
        mov hBmp13, rax
       
        invoke LoadBitmap, hInstance, 114
        mov hBmp14, rax
       
        invoke LoadBitmap, hInstance, 115
        mov hBmp15, rax

; ------------------------------------------------------------------------------
; randomly set board with random numbered game pieces
; ------------------------------------------------------------------------------

        invoke set_board, addr board, addr sqct
       
; ------------------------------------------------------------------------------
; locate the empty square and save the offset to it
; ------------------------------------------------------------------------------

        invoke find_mt, addr board, addr mtoffset

        .elseif uMsg == WM_KEYDOWN
       
            .if wParam == VK_LEFT
           
                ; moveit - arguments:
                ; ptr Board
                ; offset of empty square
                ; illegal move # 1
                ; illegal move # 2
                ; illegal move # 3
                ; illegal move # 4
                ; offset of piece to move (relative to mt square)
               
                invoke moveit, addr board, mtoffset, 3, 7, 11, 15, 1
               
            .elseif wParam == VK_UP
                invoke moveit, addr board, mtoffset, 12, 13, 14, 15, 4
   
            .elseif wParam == VK_RIGHT
                invoke moveit, addr board, mtoffset, 0, 4, 8, 12, -1
   
            .elseif wParam == VK_DOWN
                invoke moveit, addr board, mtoffset, 0, 1, 2, 3, -4
   
            .elseif wParam == VK_ESCAPE
                invoke SendMessage, hWin, WM_CLOSE, 0, 0
            .endif
           
            invoke find_mt, addr board, addr mtoffset
            invoke painting, hWin, addr board, addr hBmp0
           
        .elseif uMsg == WM_PAINT
            invoke painting, hWin, addr board, addr hBmp0
           
        .elseif uMsg == WM_CLOSE
            invoke PostQuitMessage, 0
           
        .endif
       
        invoke DefWindowProc, hWin, uMsg, wParam, lParam
        ret
    WndProc endp
   
; ##############################################################################
align 10h
    randb proc base:qword           ; simplified version of 'nrand'
    local random_seed:qword         ; not fast, but small and
        invoke GetTickCount         ; adequate for our purposes here.
        add rax, random_seed
        xor rdx, rdx
        mov rcx, 127773
        div rcx
        mov rcx, rax
        mov rax, 432836
        mul rdx
        sub rcx, rax
        xor rdx, rdx
        mov rax, rcx
        mov random_seed, rcx
        div base
        mov rax, rdx
        inc rax
        ret
    randb endp
   
; ##############################################################################
align 10h
    set_board proc pbrd:qword, psqct:qword
        push rsi
        push rdi
        push rbx
        mov rsi, pbrd       ; pointer to byte values representing the game board
        mov rdi, psqct      ; pointer to byte array acting as 'valid piece' counter

; ***************** hangs here*********************

    toppa:
        push rcx

        invoke randb, 16    ; generate random value for location
        pop rcx
        mov rdx, rax
        dec rdx
        push rdx

        invoke randb, 15    ; generate random value for game piece
        pop rdx
        mov rcx, rax
        dec rcx
        ; both of these values must be zero to create a new valid game piece
       
        cmp byte ptr [rdi+rcx], 0   ; check if location is empty
        jnz @f
        cmp byte ptr [rsi+rdx], 0   ; check if piece value is not already used
        jnz @f
       
        mov byte ptr [rsi+rdx], al  ; write new piece value to location
        mov byte ptr [rdi+rcx], 1   ; set counter for piece value to 1
                                    ; indicating the value has been used already

    @@:
        xor rax, rax                ; clear eax for the next step
        xor rcx, rcx                ; clear ecx for the next step
    @@:
        add al, byte ptr [rdi+rcx]  ; adding up all of the piece value counters
        inc rcx
        cmp rcx, 16                 ; check all 16 possible locations
        jl @b
        cmp rax, 15                 ; check all possible piece values
        jnz toppa

;***************************************************
 ; hangs above this line, in the loop
;***************************************************
        pop rbx
        pop rdi
        pop rsi
        ret
    set_board endp

; ##############################################################################
align 10h
    find_mt proc pbrd:qword, pmtoffs:qword
        xor rax, rax                ; simple proc that scans all locations
        mov rcx, pbrd               ; to locate the empty square
    @@:
        cmp byte ptr [rcx+rax], 0
        jz @f
        inc rax
        jmp @b
    @@:
        mov rcx, pmtoffs
        mov [rcx], rax              ; saving the location of the empty square
        ret
    find_mt endp
   
; ##############################################################################
align 10h
    painting proc hWin:qword, pbrd:qword, phndl:qword
    local tX:qword, tY:qword, hDC:qword, hMemDC:qword, ps:PAINTSTRUCT, numb:qword
        push rsi
        push rdi
        push rbx
       
        invoke GetDC, hWin
        mov hDC, rax
        invoke CreateCompatibleDC, NULL
        mov hMemDC, rax

        mov numb, 0
        mov tX, 0
        mov tY, 0
       
    top0:
       
        mov rcx, numb           ; index to location
        mov rdi, phndl          ; pointer to handle array
        mov rsi, pbrd           ; pointer to game board
        xor rdx, rdx            ; counter
        mov dl, [rsi+rcx]       ; get piece value (to be used as index)
        mov eax, [rdi+rdx*8]    ; get handle from array

        invoke SelectObject, hMemDC, rax
        invoke BitBlt, hDC, tX, tY, 64, 64, hMemDC, 0, 0, SRCCOPY
        inc numb
        add tX, 64              ; incrementing tX and tY as dictated
        cmp tX, 256             ; by the location being processed
        jnz @f
        add tY, 64
        mov tX, 0
    @@:
        cmp numb, 16            ; compare if all squares have been processed
        jnz top0

        invoke DeleteDC, hMemDC
        invoke DeleteDC, hDC
        pop rbx
        pop rdi
        pop rsi
        ret
    painting endp

; ##############################################################################
align 10h
    moveit proc pbrd:qword, mt:qword, i1:qword, i2:qword, i3:qword, i4:qword, v7:qword
        push rsi
        push rdi
        mov rsi, pbrd               ; pointer to game board
        mov rcx, mt                 ; pointer to empty square
        cmp rcx, i1                 ; check against illegal move #1
        jz @f
        cmp rcx, i2                 ; check against illegal move #2
        jz @f
        cmp rcx, i3                 ; check against illegal move #3
        jz @f
        cmp rcx, i4                 ; check against illegal move #4
        jz @f
        mov rdi, rcx                ; move empty location to edi
        add rdi, v7                 ; add movement offset
        mov al, [rsi+rcx]           ; swap values of the two squares
        mov dl, [rsi+rdi]           ; source square now becomes the empty square
        mov [rsi+rdi], al           ; empty square now becomes filled with source value
        mov [rsi+rcx], dl
    @@:
        pop rdi
        pop rsi
        ret
    moveit endp

; ##############################################################################
end


The attachment 4x4  Windows Game is for this code (64 bit) The code shows the problem area

The 2nd attachment 4x4 Windows compat test is the original (32 bit) which is fully operational

Running this code in the debugger everything else seems to be in order, but always gets stuck in the same loop 
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 25, 2018, 09:43:31 AM
looking at it again, the bitmaps are also not getting loaded. I'm trying to figure this out  :icon_confused:

edit --

Probably a register preservation issue.  ;) The code above only preserves registers 32 bit style. lemme see if I can rewrite some of the code...
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 25, 2018, 03:53:20 PM
I've decided to scrap this idea. I will recreate the game one small step at a time, using tried and true code.   :biggrin:
Trying to convert existing 32 bit code is rather complex it seems. I may have better luck building up slowly.

To simplify things, I've borrowed a rather generic window.

Code: [Select]

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \buildx64\include64\masm64rt.inc

    .data?
      hBrush    dq ?
      hCursor   dq ?
      hFont     dq ?
      hIcon     dq ?
      hInstance dq ?
      hWnd      dq ?
      sHgt      dq ?
      sWid      dq ?

    .data
      classname db "got_no_class",0
      caption db "4x4 Game (64 bit)",0

    .code
etc., etc., etc., ad nauseous


   :P

The remainder of this project will be in the Game Development forum..
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 25, 2018, 04:36:35 PM
from  (masm64.chm) "MASM64 Library And Macro Reference"...

"ML64.EXE is a lower level assembler than the 32 bit version of ML.EXE and it does not support prototypes or parameter and size checking"

So that means that this:

Code: [Select]
        WinMain         proto :qword
        WndProc         proto :qword, :qword, :qword, :qword
        randb           proto :qword
        set_board       proto :qword, :qword
        find_mt         proto :qword, :qword
        painting        proto :qword, :qword, :qword
        moveit          proto :qword, :qword, :qword, :qword, :qword, :qword, :qword



Is totally unnecessary with 64 bit ML?
Title: Re: converting 32 bit code to 64 bit
Post by: jj2007 on May 25, 2018, 05:10:41 PM
So that means that this:

        WinMain         proto :qword

Is totally unnecessary with 64 bit ML?

Yes, exactly. And if you pass 12 arguments to CreateWindowEx instead of 11, no problem, your source will build fine with ML64 8)
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 25, 2018, 05:18:57 PM

... your source will build fine with ML64 8)


 :badgrin:

They made something that should be simple into something more complicated. I noticed too, that the ".if, .elseif, .else, .endif" block is not fully supported without the use of external macros. More reading to do ...
Title: Re: converting 32 bit code to 64 bit
Post by: jj2007 on May 25, 2018, 06:07:09 PM
exchange of views, over 11 years ago, between Microsoft (Kang Su Gatlin, Visual C++ Program Manager) and some members of this forum titled MASM on x64 (http://www.masmforum.com/board/index.php?topic=908.0):

M$: how important is "INVOKE" for x64 MASM? ... Would you rank INVOKE as more or less important than the high-level control flow directives such as .WHILE, .IF, etc...?

Randy Hyde: The *vast* majority of MASM32 projects I've ever seen certainly use both.

Eugen: I am using MASM for writing fairly complex commercial applications (mainly shareware games) and i consider critical to be able to use both invoke and if/else HLL constructs.

hutch--: a properly designed INVOKE style syntax becomes critical to this range of users. Particularly for C/C++ programmers who are used to prototyping and the reliability of size and parameter count checking, bare mnemonics are very unpalatable to them.

Tedd: rough guesses on what I personally use, though I dare say others are similar.. invoke - LOTS, proc/endproc - lots, .IF/.ELSEIF/.ELSE - very often

GregL: PROTO / INVOKE are very important to me, as well as .IF. .WHILE and .LOOP would be next in importance.

BogdanOntanu: I will never use an assembler that has no invoke or extended call syntax and .IF .ELSEIF .ELSE .ENDIF constructs included in the assembler.

hutch--: In terms of priority of pseudo high level constructions, I would tend to place them in this order.
1. INVOKE  Critical for C/C++ programmer who are used to prototyping and who have little chance of writing bare mnemonic code.
2. .IF block syntax for sequential conditional testing. Nearly as critical for reliable higher level code.
3.  .WHILE / .REPEAT loop code syntax.  Useful but can generally be replaced with manual loop code.

M$: I'd like to thank EVERYONE for their feedback.
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 25, 2018, 06:13:46 PM
 8)  I'll stick around in 32-bit land for a while. It will probably outlive my existence.

While there is still an abundance of 32 bit software available that's how long I'll stick with 32 bits.   :bgrin:
Title: Re: converting 32 bit code to 64 bit
Post by: hutch-- on May 25, 2018, 07:18:27 PM
You need to know a bit of the history of MASM. When Microsoft introduced MASM version 6.0 in about 1990, it was a full development environment aimed at the programming consumer market, they did an update a couple of years later with MASM 6.1 which was the last consumer version they ever sold. They tried to drop it after that in the middle 90s but after consumer demand did not drop off they re-introduced it as a free add on to the version of VC at the time, it was version 6.15.

By the time 64 bit started to hit the market they started to look around and the drift at the time was "Don't mess up ML.EXE" as it was a decent reliable tool and due to its age it still retained all of the consumer capacity it started with in 1990.

ML64.EXE is a different animal, its a boiler room low level tool that was never pointed at the consumer market, its not far off an "in house" low level tool for the stuff they needed to make OS bits but fortunately it still retained the old pre-processor which made at least some of the missing capacity possible. It is an unconfigured raw assembler which has both virtues and vices. Prototyping disappeared, the .IF block notation went and the pseudo high level loop techniques did not survive either.

With the work I have done with ML64, the invoke style notation is up and running, I have used Vasily's .IF block notation which does the job and produced a stackframe macro that handles the quirks of the Win64 ABI so its no big deal to write once you are used to it. From one who remembered the crap back in the middle to late 90s about MASM, ML.EXE was just as badly understood and heavily criticised by the TASM guys until it was developed and supported properly.

I have much the same view on ML64, it is a pretty bare bones tool but you can get results with it if you know what you are doing with it. Import libraries, include files, a range of macros and a custom library seem to be the way and it is complete application capable at the moment, library modules can be added ad infinitum so I don't see any real problems here.

ML64 is not the only low level assembler, FASM is at least as low level as MASM yet it is an excellent tool. The main gain in using ML64 has been that it no longer requires prototypes and this improved my coding speed and flexibility by a reasonable amount.
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 25, 2018, 07:41:33 PM
@hutch..
Your points are well taken.  But it seems like I'm a fish out of water, floundering around with ml64.

I'll stick with ml (32 bit),  but I still have the capability to try 64 bit again in the future.   8)

I've bitten off more than I can chew with ml64. I still have a lot to learn with ml 32 bit programming, and probably have no business attempting coding for 64 bit.   :P
Title: Re: converting 32 bit code to 64 bit
Post by: hutch-- on May 25, 2018, 09:05:45 PM
Z,

It will come with practice, working with 32 bit will get you back up to pace and this much, mnemonics in win64 are much the same as in 32 bit, just a bit bigger. When you have another go at 64 bit, start with the higher level stuff and when you have got the swing of it you can play with the lower level stuff if you need to. Starting with the bottom line low level stuff in win64 is the wrong way to go as its messy and complicated but the higher level stuff with a stack frame is very similar to working with 32 bit MASM.
Title: Re: converting 32 bit code to 64 bit
Post by: nidud on May 25, 2018, 09:16:57 PM
 :biggrin:

Here's a simpler way of doing this which shows some the of the advantages of using HLL.

The 32-bit version: asmc -pe -gui test.asm
Code: [Select]
include windows.inc
include d3d9.inc
include tchar.inc

.data
g_bContinue dd TRUE

.code

MsgProc proc WINAPI hWnd:HWND, msg:UINT, wParam:WPARAM, lParam:LPARAM

    .switch(msg)
      .case WM_DESTROY:
        PostQuitMessage( 0 )
        mov g_bContinue,FALSE
        .endc
      .default
        DefWindowProc( hWnd, msg, wParam, lParam )
    .endsw
    ret

MsgProc endp

WinMain proc WINAPI hInstance:HINSTANCE, hPrevInstance:HINSTANCE, lpCmdLine:LPSTR, nShowCmd:SINT

    local wc:WNDCLASSEX
    local hWnd:HWND
    local pD3D:LPDIRECT3D9
    local d3dpp:D3DPRESENT_PARAMETERS
    local pd3dDevice:LPDIRECT3DDEVICE9
    local msg:MSG

    xor eax,eax
    mov pd3dDevice,rax
    lea rdx,wc
    xchg rdi,rdx
    mov ecx,sizeof(WNDCLASSEX)
    rep stosb
    mov rdi,rdx
    mov wc.cbSize,sizeof(WNDCLASSEX)
    mov wc.style,CS_CLASSDC
    lea rax,MsgProc
    mov wc.lpfnWndProc,rax
    lea rax,@CStr("Direct3D Window")
    mov wc.lpszClassName,rax
    mov wc.hInstance,GetModuleHandle(NULL)
    RegisterClassEx( &wc )
    mov hWnd,CreateWindowEx(0, "Direct3D Window", "DirectXers - D3D9 Tutorial 1",
        WS_OVERLAPPEDWINDOW, 100, 100, 400, 400, GetDesktopWindow(), NULL, wc.hInstance, NULL )
    ShowWindow( hWnd, SW_SHOW )

    .repeat

        mov pD3D,Direct3DCreate9(D3D_SDK_VERSION)
        .break .if !rax

        ZeroMemory( &d3dpp, sizeof(d3dpp) )
        mov d3dpp.Windowed,TRUE
        mov d3dpp.SwapEffect,D3DSWAPEFFECT_DISCARD
        mov d3dpp.BackBufferFormat,D3DFMT_UNKNOWN

        .ifd pD3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice )

            MessageBox(hWnd, "No HAL HARDWARE_VERTEXPROCESSING! Sample will exit!", NULL, 0)
            pD3D.Release()
            mov eax,E_FAIL
            .break
        .endif

        .while ( g_bContinue )

            pd3dDevice.Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0, 0 )
            pd3dDevice.BeginScene()
            pd3dDevice.EndScene()
            pd3dDevice.Present( NULL, NULL, NULL, NULL )
            TranslateMessage( &msg )
            DispatchMessage( &msg )
            PeekMessage( &msg, 0, 0, 0, PM_REMOVE )
        .endw
        pd3dDevice.Release()
        pD3D.Release()
        xor eax,eax
    .until 1
    ret

WinMain endp

    end _tstart

The 64-bit version: asmc -pe -win64 -gui -Zp8 test.asm
Code: [Select]
include windows.inc
include d3d9.inc
include tchar.inc

.data
g_bContinue dd TRUE

.code

MsgProc proc WINAPI hWnd:HWND, msg:UINT, wParam:WPARAM, lParam:LPARAM

    .switch(msg)
      .case WM_DESTROY:
        PostQuitMessage( 0 )
        mov g_bContinue,FALSE
        .endc
      .default
        DefWindowProc( hWnd, msg, wParam, lParam )
    .endsw
    ret

MsgProc endp

WinMain proc WINAPI hInstance:HINSTANCE, hPrevInstance:HINSTANCE, lpCmdLine:LPSTR, nShowCmd:SINT

    local wc:WNDCLASSEX
    local hWnd:HWND
    local pD3D:LPDIRECT3D9
    local d3dpp:D3DPRESENT_PARAMETERS
    local pd3dDevice:LPDIRECT3DDEVICE9
    local msg:MSG

    xor eax,eax
    mov pd3dDevice,rax
    lea rdx,wc
    xchg rdi,rdx
    mov ecx,sizeof(WNDCLASSEX)
    rep stosb
    mov rdi,rdx
    mov wc.cbSize,sizeof(WNDCLASSEX)
    mov wc.style,CS_CLASSDC
    lea rax,MsgProc
    mov wc.lpfnWndProc,rax
    lea rax,@CStr("Direct3D Window")
    mov wc.lpszClassName,rax
    mov wc.hInstance,GetModuleHandle(NULL)
    RegisterClassEx( &wc )
    mov hWnd,CreateWindowEx(0, "Direct3D Window", "DirectXers - D3D9 Tutorial 1",
        WS_OVERLAPPEDWINDOW, 100, 100, 400, 400, GetDesktopWindow(), NULL, wc.hInstance, NULL )
    ShowWindow( hWnd, SW_SHOW )

    .repeat

        mov pD3D,Direct3DCreate9(D3D_SDK_VERSION)
        .break .if !rax

        ZeroMemory( &d3dpp, sizeof(d3dpp) )
        mov d3dpp.Windowed,TRUE
        mov d3dpp.SwapEffect,D3DSWAPEFFECT_DISCARD
        mov d3dpp.BackBufferFormat,D3DFMT_UNKNOWN

        .ifd pD3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice )

            MessageBox(hWnd, "No HAL HARDWARE_VERTEXPROCESSING! Sample will exit!", NULL, 0)
            pD3D.Release()
            mov eax,E_FAIL
            .break
        .endif

        .while ( g_bContinue )

            pd3dDevice.Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0, 0 )
            pd3dDevice.BeginScene()
            pd3dDevice.EndScene()
            pd3dDevice.Present( NULL, NULL, NULL, NULL )
            TranslateMessage( &msg )
            DispatchMessage( &msg )
            PeekMessage( &msg, 0, 0, 0, PM_REMOVE )
        .endw
        pd3dDevice.Release()
        pD3D.Release()
        xor eax,eax
    .until 1
    ret

WinMain endp

    end _tstart
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 25, 2018, 11:23:00 PM
@nidud

That's odd,  I thought the first example was 32 bit code.  I see rax rdi and rdx in there in WinMain   :P
Title: Re: converting 32 bit code to 64 bit
Post by: nidud on May 25, 2018, 11:31:38 PM
 :biggrin:

From the main Masm include file (cruntime.inc) in VS:

    rax equ <eax>
    rbx equ <ebx>
    rcx equ <ecx>
    rdx equ <edx>
    rdi equ <edi>
    rsi equ <esi>
    rbp equ <ebp>
    rsp equ <esp>


This is defined in tchar.inc (https://github.com/nidud/asmc/blob/master/include/tchar.inc#L1007) included in the sample.
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 26, 2018, 01:33:06 AM
:biggrin:

From the main Masm include file (cruntime.inc) in VS:
This is defined in tchar.inc (https://github.com/nidud/asmc/blob/master/include/tchar.inc#L1007) included in the sample.

That's cheating.    :P     :lol:
Title: Re: converting 32 bit code to 64 bit
Post by: daydreamer on May 26, 2018, 02:59:39 AM
Isn't it best to start learn to code 64bit with new mindset, similar to have different mindset when coding SIMD?
And is it not easier to code a 64bit program. From beginning than think in terms of translate 32bit to 64bit?
Similar to you train English and at one point you start to think in English
(for us who don't have English as native language)
After enough 64bit exercises, you adapt to the 64bit ways
Title: Re: converting 32 bit code to 64 bit
Post by: mineiro on May 26, 2018, 06:04:29 AM
Similar to you train English and at one point you start to think in English
(for us who don't have English as native language)
hello;
I have seen a lot of faults on my way to express and this happens frequently. I have tried to think out of the box because english teachers on my country say that thing: "think, write, speak using english language". This is hard because portuguese language have more verbal modes than english language. So, I have read philosopher Mortimer J. Adler (how to read a book), sister Mirian Joseph (trivium and quadrivium - liberal arts), priest Antonin Sertillanges (intelectual mind) just to see my own fault. The solution that I don't do, only when talking seriously is:
Think using your own language, write with your own language, translate that and correct. The point is that all translators online change sense; sometime you affirms and translations do on negative sense. One example is "sinuca de bico", that translator translate to "billiards" or "Billfish again", so after some search I found "be behind the eight ball".
Title: Re: converting 32 bit code to 64 bit
Post by: daydreamer on May 26, 2018, 07:45:23 AM
Similar to you train English and at one point you start to think in English
(for us who don't have English as native language)
hello;
I have seen a lot of faults on my way to express and this happens frequently. I have tried to think out of the box because english teachers on my country say that thing: "think, write, speak using english language". This is hard because portuguese language have more verbal modes than english language. So, I have read philosopher Mortimer J. Adler (how to read a book), sister Mirian Joseph (trivium and quadrivium - liberal arts), priest Antonin Sertillanges (intelectual mind) just to see my own fault. The solution that I don't do, only when talking seriously is:
Think using your own language, write with your own language, translate that and correct. The point is that all translators online change sense; sometime you affirms and translations do on negative sense. One example is "sinuca de bico", that translator translate to "billiards" or "Billfish again", so after some search I found "be behind the eight ball".
seem like a problem with English idioms vs native language idioms use completely different ways and Words to describe the same thing,which propably works very bad with translator that dont recognize it as idiom,but tries to convert it Word by Word instead

but some of us maybe has Assembly as their native language  :P :greenclp:
Title: Re: converting 32 bit code to 64 bit
Post by: hutch-- on May 26, 2018, 01:19:42 PM
 :biggrin:

    rax equ <eax>
    rbx equ <ebx>
    rcx equ <ecx>
    rdx equ <edx>
    rdi equ <edi>
    rsi equ <esi>
    rbp equ <ebp>
    rsp equ <esp>

This is exactly the type of confusion you try to avoid when you write assembler code. You know that a 64 bit register fits into a QWORD variable.

MsgProc proc WINAPI hWnd:HWND, msg:UINT, wParam:WPARAM, lParam:LPARAM

Same problem here again, the calling convention is already determined in Win64, its FASTCALL. Then you have data type typedefs using names that have been around since Win16 and no way to know from the code what data size they are. This is fine in a C/C++ compiler where confusion is common but its making a mess of assembler code where you normally know the exact data size.
Title: Re: converting 32 bit code to 64 bit
Post by: daydreamer on May 26, 2018, 05:04:29 PM
:biggrin:

    rax equ <eax>
    rbx equ <ebx>
    rcx equ <ecx>
    rdx equ <edx>
    rdi equ <edi>
    rsi equ <esi>
    rbp equ <ebp>
    rsp equ <esp>

This is exactly the type of confusion you try to avoid when you write assembler code. You know that a 64 bit register fits into a QWORD variable.

MsgProc proc WINAPI hWnd:HWND, msg:UINT, wParam:WPARAM, lParam:LPARAM

Same problem here again, the calling convention is already determined in Win64, its FASTCALL. Then you have data type typedefs using names that have been around since Win16 and no way to know from the code what data size they are. This is fine in a C/C++ compiler where confusion is common but its making a mess of assembler code where you normally know the exact data size.
Now we know the reason why so many stick with masm32bit coding :lol:
Because a lot of bugs caused by the above equates, 99% gave up, never to know why their attempt at adressing over 5gb failed
Title: Re: converting 32 bit code to 64 bit
Post by: jj2007 on May 26, 2018, 05:14:14 PM
Because a lot of bugs caused by the above equates, 99% gave up, never to know why their attempt at adressing over 5gb failed

I have used the rax equ <eax> trick since 2016 (http://masm32.com/board/index.php?topic=5314.msg59884#msg59884) now, and it works perfectly. It seems you have not understood the idea behind ;)
Title: Re: converting 32 bit code to 64 bit
Post by: hutch-- on May 26, 2018, 05:24:41 PM
64 bit code.


mov eax, rct.left    : DWORD sized structure member


Run the register equates and watch it go BANG !  :P
Title: Re: converting 32 bit code to 64 bit
Post by: AW on May 26, 2018, 05:43:01 PM
"dodge the bullet" tricks...  :dazzled:
But the bull needs to be taken directly by the horns.
Title: Re: converting 32 bit code to 64 bit
Post by: nidud on May 27, 2018, 12:36:47 AM
You will not use tchar.h (https://msdn.microsoft.com/en-us/library/c426s321.aspx) in a normal application unless you plan on building a 32/64-bit Unicode/ASCII from the same source. Asmc includes libraries for both 32 and 64-bit, ASCII and Unicode so it's handy for writing test code for the above platforms.

This is exactly the type of confusion you try to avoid when you write assembler code. You know that a 64 bit register fits into a QWORD variable.

And that a 32 bit register fits into a DWORD variable.

Quote

MsgProc proc WINAPI hWnd:HWND, msg:UINT, wParam:WPARAM, lParam:LPARAM

Same problem here again, the calling convention is already determined in Win64, its FASTCALL. Then you have data type typedefs using names that have been around since Win16 and no way to know from the code what data size they are.

Yes, that's basically how it works.

https://msdn.microsoft.com/en-us/library/windows/desktop/ff818516(v=vs.85).aspx
Quote
Using the Windows API, you can develop applications that run successfully on all versions of Windows while taking advantage of the features and capabilities unique to each version. (Note that this was formerly called the Win32 API. The name Windows API more accurately reflects its roots in 16-bit Windows and its support on 64-bit Windows.)

Quote
This is fine in a C/C++ compiler where confusion is common but its making a mess of assembler code where you normally know the exact data size.

This confusion is now (apparently) also available in assembler  :t
Title: Re: converting 32 bit code to 64 bit
Post by: nidud on May 27, 2018, 12:46:59 AM
64 bit code.


mov eax, rct.left    : DWORD sized structure member


Run the register equates and watch it go BANG !  :P

 :biggrin:

You can only use these register equates in 32-bit.

ifndef _WIN64
    rax equ <eax>
    ...
endif
Title: Re: converting 32 bit code to 64 bit
Post by: hutch-- on May 27, 2018, 02:09:36 AM
 :biggrin:

> You can only use these register equates in 32-bit.

So its about as useful as a hip pocket in a T shirt.

> Using the Windows API, you can . . . .

Fine in a C/C++ compiler but hopeless in an assembler. After years of dealing with people who get confused by not knowing what the data size is, using native data sizes dictated by the hardware is reliable and confusion free. Scour you way through a collection of Microsoft .H files to track down the typedefs to eventually find what SIZE the data is.  :P
Title: Re: converting 32 bit code to 64 bit
Post by: jj2007 on May 27, 2018, 02:50:16 AM
64 bit code.


mov eax, rct.left    : DWORD sized structure member


Run the register equates and watch it go BANG !  :P

There is absolutely no reason why it should go BANG.

Code: [Select]
jinvoke GetWindowRect, hWnd, addr rc
mov eax, rc.left
jinvoke TextOut, PtDC, 7, 2, Str$("rc.left: \t%i", eax), s$Len
mov eax, rc.top
jinvoke TextOut, PtDC, 7, 22, Str$("rc.top: \t%i", eax), s$Len
mov eax, rc.right
jinvoke TextOut, PtDC, 7, 42, Str$("rc.right: \t%i", eax), s$Len
mov eax, rc.bottom
jinvoke TextOut, PtDC, 7, 62, Str$("rc.bottom: \t%i", eax), s$Len
Builds and runs just fine, as 32- or 64-bit code. Project attached (exe assembled with ML64, but it builds with UAsm, too).
Title: Re: converting 32 bit code to 64 bit
Post by: nidud on May 27, 2018, 02:53:19 AM
:biggrin:

> You can only use these register equates in 32-bit.

So its about as useful as a hip pocket in a T shirt.

> Using the Windows API, you can . . . .

Fine in a C/C++ compiler but hopeless in an assembler.

The two (identical (https://github.com/nidud/asmc/tree/master/source/test/wininc/D3D9/4)) samples (https://github.com/nidud/asmc/tree/master/source/test/wininc/D3D9/1) provided above do actually work.

Quote
After years of dealing with people who get confused by not knowing what the data size is, using native data sizes dictated by the hardware is reliable and confusion free. Scour you way through a collection of Microsoft .H files to track down the typedefs to eventually find what SIZE the data is.  :P

The source provided is 89 lines of confusing code so it would be interesting to see the Masm32/64 confusing free version of the same.  :P
Title: Re: converting 32 bit code to 64 bit
Post by: jj2007 on May 27, 2018, 03:03:02 AM
My code (see previous post) is equally confusing, of course, but it's only 82 lines. And good to know that AsmC can still be used to build assembly sources :badgrin:
Title: Re: converting 32 bit code to 64 bit
Post by: hutch-- on May 27, 2018, 03:52:53 AM

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    rax equ <eax>

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    LOCAL rct   :RECT           ; 4 x DWORD members

  ; -----------------
    mov rax, rct.left           ; goes BANG here !!!!
  ; -----------------

    waitkey
    .exit

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end

Build

 Assembling: jjxxx.asm
jjxxx.asm(5) : error A2008:syntax error : rax
jjxxx.asm(16) : error A2022:instruction operands must be the same size
POLINK: fatal error: File not found: 'jjxxx.obj'.
 Volume in drive K is disk3_k
 Volume Serial Number is 68C7-4DBB
Title: Re: converting 32 bit code to 64 bit
Post by: nidud on May 27, 2018, 04:17:11 AM
include windows.inc

    rax equ <eax>

.code

main proc

  local rct:RECT

    mov rax,rct.left
    ret

main endp

    end


Build: asmc -win64 test.asm

 Assembling: test.asm
test.asm(3) : error A2008: syntax error : rax
test.asm(11) : error A2022: instruction operands must be the same size : 8 - 4
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 27, 2018, 05:53:58 AM
I've created a monster with this thread.  8)

Funny thing is, I've temporarily at least given up the idea of programming in Masm64, and the thread has taken a tangent from its original purpose.   :icon_confused:  And the debate goes on..
Title: Re: converting 32 bit code to 64 bit
Post by: jj2007 on May 27, 2018, 06:33:40 AM
Don't worry, zedd, we are just teasing each other a little bit :icon_mrgreen:

mov rax, rct.left is certainly bad code. It should be mov eax, rct.left - in 32-bit as well as in 64-bit land ;)

Btw my includes do contain rax equ eax. And my source above builds with ML, UAsm and Asm, as 32- or 64-bit code. Which doesn't imply that I would seriously consider to start a 64-bit career. Unless you need to address more than 2 gigabytes of RAM, there is absolutely no advantage using 64-bit code. Slow and messy :biggrin:
Title: Re: converting 32 bit code to 64 bit
Post by: zedd151 on May 27, 2018, 12:31:38 PM
The way that it's going, Micro$**t might even kill macro support altogether. Along with the other niceties that made it very easy and fun to work with. If that does happen,  might as well assemble your code with Olly.    :biggrin:

Just create a file filled with 0x0h bytes,  slap on a generic header,  adjust  section headers and import infos accordingly.  And don't forget to build your resources with resource hacker.    8)

(actually it's a lot more involved than that..  But you get the idea)     :greensml:
Title: Re: converting 32 bit code to 64 bit
Post by: hutch-- on May 27, 2018, 01:54:17 PM
One of the reasons why you don't need to worry about Microsoft trashing MASM is that they need it, that is why it still exists. The last commercial version was 6.1 about 1993 (I still have the box, manuals and probably even the disks) but it has continued in VC/VS for no other reason than there are things in an OS that cannot be done with ultra high level visual garbage generators. ML was consumer software where ML64 in close to being an "in house" scruffy that does the job they need but with few frills and conveniences. The ancient pre-processor survives because it already existed and it is (in their terms) useful at times.
Title: Re: converting 32 bit code to 64 bit
Post by: daydreamer on May 27, 2018, 03:55:14 PM
64 bit code.


mov eax, rct.left    : DWORD sized structure member


Run the register equates and watch it go BANG !  :P

There is absolutely no reason why it should go BANG.

Code: [Select]
jinvoke GetWindowRect, hWnd, addr rc
mov eax, rc.left
jinvoke TextOut, PtDC, 7, 2, Str$("rc.left: \t%i", eax), s$Len
mov eax, rc.top
jinvoke TextOut, PtDC, 7, 22, Str$("rc.top: \t%i", eax), s$Len
mov eax, rc.right
jinvoke TextOut, PtDC, 7, 42, Str$("rc.right: \t%i", eax), s$Len
mov eax, rc.bottom
jinvoke TextOut, PtDC, 7, 62, Str$("rc.bottom: \t%i", eax), s$Len
Builds and runs just fine, as 32- or 64-bit code. Project attached (exe assembled with ML64, but it builds with UAsm, too).
its feels so unneccerary to type extra chars,like in jinvoke,coinvoke, etc,when masm has capabilities to reprogram keywords
and why dont anyone dare to use equates like this:  :P
rax equ <al> etc
Title: Re: converting 32 bit code to 64 bit
Post by: daydreamer on May 27, 2018, 04:13:51 PM
you are all way late when it comes to code 64bit coding,pentium MMX(1993) came with 64bit coding although very limited to 64bit qword operations but still,nintendo64bit,PS2 had 128bit cpu ,SSE came shortly afterwards with 128bit xmm regs,also the first pixelshaders hardware was compiled with nvasm (nvidias assembler)  :P
today its time for you to code with 256/512 bit hardware,pixelshaders or avx
Title: Re: converting 32 bit code to 64 bit
Post by: jj2007 on May 27, 2018, 05:34:32 PM
its feels so unneccerary to type extra chars,like in jinvoke,coinvoke, etc,when masm has capabilities to reprogram keywords

masm has capabilities to reprogram keywords? It is not that easy...

Note that Hutch & Vasily do have a macro that's called invoke. But their invoke doesn't check the type and number of parameters; jinvoke does, and will throw an error if you pass 10 arguments to CreateWindowEx instead of the 11 required.

Furthermore, it's a matter of taste if you want to write
  .if eax<=ecx
or
  .if eax{=ecx

There is a simple solution to such problems, it's called UAsm - same syntax as ML32, all HLL elements intact... it has been discussed before, and compromises are on the table (http://masm32.com/board/index.php?topic=6447.msg69120#msg69120) (i.e. a switch that disables the HLL macros), but as it stands, you can pick either

- an assembler that understands eax<=ecx but has no libraries attached (UAsm, AsmC)
or
- an assembler that has libraries but forces you to use eax{=ecx (ML64)

My personal solution is to avoid 64-bit coding.
Title: Re: converting 32 bit code to 64 bit
Post by: nidud on May 27, 2018, 07:14:13 PM
- an assembler that understands eax<=ecx but has no libraries attached (UAsm, AsmC)

 :biggrin:

Small correction.

The Asmc package currently include the following:
- assembler, linker and library manager for 16/32/64-bit
- 239 include files (203642 lines) with 3000 macros
- 109 win32 import libraries
- 670 win64 import libraries
- libc.lib (16-bit) – 403 files
- libc.lib (32-bit) – 493 files
- libc.lib (64-bit) – 214 files
- quadmath.lib (32/64-bit) 69 files
- directxmath.lib (64-bit) - 285 files
- 1240 test/sample files

Title: Re: converting 32 bit code to 64 bit
Post by: LordAdef on May 27, 2018, 10:05:24 PM
I am particularly happy I'm still getting to learn everything I can in masm32, and am not going into 64bits.
One thing I always thought to be bad for asm is the forking numbers of dialects. A unified MASM with joined forces would be so much better for the language, but we ended up having all these flavours hanging around and dividing. Imagine C with that many forks..

Title: Re: converting 32 bit code to 64 bit
Post by: jj2007 on May 27, 2018, 10:15:01 PM
The Asmc package
Is there an installer? I tried "asmc" download installer but the first link that looks relevant is HOW TO REMOVE TROJAN.WIN32.AGENT.ASMC EASILY FROM YOUR COMPUTER (http://www.antivirus-remove.com/post/How-To-Remove-Trojan.Win32.Agent.asmc-Easily-From-Your-Computer_14_110467.html) ::)
Quote
Trojan.Win32.Agent.asmc is a malicious backdoor Trojan that endangers target computers terribly. It is a risky computer infection designed by cyber criminals to attack computer users all over the world. The backdoor Trojan is capable to take over the whole contaminated system upon its arrival. It is designed to perform malicious actions on victimized computers. To illustrate, the Trojan virus leads serious computer damages and data loss to victims. It has the ability to change your system files and entries and even drop harmful files in your system. Besides, this Trojan comes bundled with many potential threats like malware and adware to invade the victimized computer deeply in every possible way.
Title: Re: converting 32 bit code to 64 bit
Post by: nidud on May 27, 2018, 11:18:31 PM
One thing I always thought to be bad for asm is the forking numbers of dialects. A unified MASM with joined forces would be so much better for the language, but we ended up having all these flavours hanging around and dividing.

The forks you referring to are Masm compatible assemblers capable of swallow all the Masm code available and then some, so there's no new dialects added at all.

Quote
Imagine C with that many forks..

New C forks are created all the time but that doesn't mean the latest version is not capable of compiling C source written for older versions.
Title: Re: converting 32 bit code to 64 bit
Post by: LordAdef on May 28, 2018, 12:01:28 AM
One thing I always thought to be bad for asm is the forking numbers of dialects. A unified MASM with joined forces would be so much better for the language, but we ended up having all these flavours hanging around and dividing.

The forks you referring to are Masm compatible assemblers capable of swallow all the Masm code available and then some, so there's no new dialects added at all.

Quote
Imagine C with that many forks..

New C forks are created all the time but that doesn't mean the latest version is not capable of compiling C source written for older versions.
I might have not expressed myself well in this one. Masm compatible assemblers work nicely. I actually use UAsm myself.
My feeling is more towards the feeling of joining all these forces together really. And I'm talking about real dialects, like SolAsm etc...
Title: Re: converting 32 bit code to 64 bit
Post by: felipe on May 28, 2018, 04:34:15 AM
LordAdef i don't think is to hard to go from 1 assembler to the other. You can even try assemblers for different "machines", like microcontroller assemblers...

Different flavours for 1 particular machine and system shouldn't be an obstacle at all, i think.  :idea:
Title: Re: converting 32 bit code to 64 bit
Post by: LordAdef on May 28, 2018, 05:06:27 AM
Hi Felipe, I didn't say it's hard
Title: Re: converting 32 bit code to 64 bit
Post by: mineiro on May 28, 2018, 09:12:23 AM
Hello Alex, Alexandre!? My name is Ricardo, like Ricciardo or Richard or Rijkard.
I was thinking on your idea years ago, the point is that we take inside the bubble with this. Like microsoft world only, so, they dictates the rules. Like what they have done with ml64, forgeting many features.
I take your point about solasm, I played with that before and indicate to everyone to try.  That use pointers instead of contents of pointers on invoke per example. Well, I like that. On assembly we play only with pointers and pointer contents while addressing, to a microcontroler or any processor. Thats why I recommend old books. New technologies don't appears to be quickly as default 8086 mnemonics, on my tests, even x64 world!?. I don't update anymore myself, this new technologies are not quickly, only an evolution from past!. I'm supposed to be wrong here, but coding tells by itself.
I have a debt with an user that I forgot the name, but he mixed hardware and software here, not subject of this board of course.
When we adapt ourselves to right to left inside instructions have a motorola syntax that tell us from left to right. So, we need change our brain from rational to emotional, well brother, it's hard is the solution.
ps: I preffer addressing modes instead of address contents.
Title: Re: converting 32 bit code to 64 bit
Post by: felipe on May 28, 2018, 09:17:58 AM
So, we need change our brain from rational to emotional

 :biggrin: This is interesting, but i think in such cases we don't change the mind from 1 point to other...probably the mind gets wet with emotion but remains rational... :idea:
Title: Re: converting 32 bit code to 64 bit
Post by: mineiro on May 28, 2018, 10:05:06 AM
good answer felipe; we are humans, we adapt to anything, even bad things like smoke, drink, coding hehehe. Well, you're talking spanish this can be jejeje, or japanese hihihi, ... .

felipe offtopic:
Chile is fine now, better university from south america thas was from us, but Brasil is trying to get your position. Wait next elections. :D, just kidding my brother, yes, I like this.
Title: Re: converting 32 bit code to 64 bit
Post by: felipe on May 28, 2018, 10:15:42 AM
mineiro:
:biggrin: I don't want to touch politics concerns in the campus...(But Chile sucks!  :badgrin:)

  :idea: And yes, i'm chilean... :biggrin:
Title: Re: converting 32 bit code to 64 bit
Post by: hutch-- on May 28, 2018, 11:06:30 AM
> But Chile sucks!

I think you will find that all Governments suck, here in OZ we have a conservative government that is on its way out doing everything it can to line the pockets of their backers by screwing the poorest people in the country. OZ is dangerously over regulated and has a new world order police state legislated into place in the different states. I see the humour in countries that have freedom for its population are those that get criticised the most.

At the risk of sounding political, one thing that pisses me off is the level of interference that some major powers apply to other smaller countries. In particular I would like to travel in Venezuela to shoot video in the south east of the country of the fabulous table top mountains that the locals call tepius. I am probably too old to climb Mount Roraima or the one along side it called Kukenan but you can get to the top by helicopter. The other major site is the collection of tepuis around the waterfall Salto Angel (Angel Falls) and the trick is to take the boat ride up the river and rapids into the Canon Del Diablo.

Sad to say the US is deliberately trying to destroy Venezuela with sanctions and it is causing great hardship to ordinary people there and the country is no longer safe for foreigners. The only good choice for me is China as its cheap to get to and it has some amazing stuff to see.
Title: Re: converting 32 bit code to 64 bit
Post by: felipe on May 28, 2018, 11:35:27 AM
I think i understand you hutch and i agree with you. The sad with Chile (apart for goverment) is that is still a third world country, with a lot of pooverty. And there's a lot of stupid and ignorante people here...but maybe i should finish here this issue... :idea:
Title: Re: converting 32 bit code to 64 bit
Post by: hutch-- on May 28, 2018, 12:09:22 PM
I gather its been slow since Pinochet was dumped and from what I hear Chile is well on the road to recovery but like much of South America, greedy bastards from other countries have exploited as much of the country as possible which is very unfortunate as Chile has its share of natural resources that should go to the people, not greedy foreigners.

The guy who does the post office deliveries in my area is from Chile, his name is Luis and he is a great guy with a sense of humour. It used to be possible to take a Lan Chile flight to Easter Island and then on to Chile which would have been a good trip but I don't know if it is still available. It must be one of the few places in the world where you can see the sea, jungle and snow capped mountains in the same photo.
Title: Re: converting 32 bit code to 64 bit
Post by: felipe on May 28, 2018, 01:11:20 PM
Yes, the Eastern Island, 1 of the few places in Chile where you will not find (i think) the "Loxosceles laeta"  :shock:

 :biggrin: Just clean your house well and remember to shake off your clothes and shoes before using it and you will be safe... :idea:
Title: Re: converting 32 bit code to 64 bit
Post by: LordAdef on May 29, 2018, 01:59:29 AM
Hello Alex, Alexandre!? My name is Ricardo, like Ricciardo or Richard or Rijkard.
I was thinking on your idea years ago, the point is that we take inside the bubble with this. Like microsoft world only, so, they dictates the rules. Like what they have done with ml64, forgeting many features.
I take your point about solasm, I played with that before and indicate to everyone to try.  That use pointers instead of contents of pointers on invoke per example. Well, I like that. On assembly we play only with pointers and pointer contents while addressing, to a microcontroler or any processor. Thats why I recommend old books. New technologies don't appears to be quickly as default 8086 mnemonics, on my tests, even x64 world!?. I don't update anymore myself, this new technologies are not quickly, only an evolution from past!. I'm supposed to be wrong here, but coding tells by itself.
I have a debt with an user that I forgot the name, but he mixed hardware and software here, not subject of this board of course.
When we adapt ourselves to right to left inside instructions have a motorola syntax that tell us from left to right. So, we need change our brain from rational to emotional, well brother, it's hard is the solution.
ps: I preffer addressing modes instead of address contents.
Ta' maluco Ricardo? E' lo'gico que eu sei quem voce e' kkkkkkkkk  (no Portuguese accents for some reason... sorry)
Title: Re: converting 32 bit code to 64 bit
Post by: LordAdef on May 29, 2018, 02:02:43 AM
Quote
(But Chile sucks!  (http://masmforum.com/~masm32/board/Smileys/mforum/badgrin.gif))
What??? A joke of course!
Please don't spread the word but.... Chile is one of the most amazing countries in the world, and one of the most beatiful too! I strongly suggest it for your next Holidays. Fantastic people, fantastic food, fantastic places!!!! I'm a fan
Title: Re: converting 32 bit code to 64 bit
Post by: daydreamer on May 29, 2018, 03:51:26 AM
I am from sweden,I like to travel to Denmark,its easy when I live Close to it, I live far away from Stockholm,so when I Went to South Africa ,I go to nearest Airport(Copenhagen),so I was mistaken for Danish by some people,when I told them I fly from Copenhagen
but vacation around Kebnekaise and northermost sweden has great landscapes,nice birchtree's with winds make the branches turn to corkscrews,fighting to stay on high altitude
Southern sweden has lots of nice sandbeaches,many danish and germans like to have vacation here

Ricardo, my name comes from latin,Magnus

its great with friends that are from all around The World,sometimes we inspired each other to achieve better coding,new ways of coding,new macros and proc's and libraries,games
but the nature of international friends =different languages and countries has inspired me go on a unicode trip,but also reach out of assembly Community to try to code it in other languages,as I cannot guarantee all people I know understand I show an assembler code solution
Title: Re: converting 32 bit code to 64 bit
Post by: HSE on May 29, 2018, 04:26:39 AM
far away from Stockholm

In the same TV "Vikings" kingdom. I know that swedden's scenes were shooted in Ireland. But lanscapes ¿are authentic?
Title: Re: converting 32 bit code to 64 bit
Post by: felipe on May 29, 2018, 11:31:41 AM
Southern sweden has lots of nice sandbeaches,many danish and germans like to have vacation here

You mean nudist beaches?  8)

 :redface:  :P