News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Making the switch

Started by AiaKonai, September 13, 2010, 02:19:36 PM

Previous topic - Next topic

mineiro

Hello Sr AiaKonai;
You're trying to replace your program to 32 bit console or GUI?
If GUI you can start learning some windows API(the old int' in ms-dos), a good tutorial to start is iczelion.
If console mode, you can go into laboratory in this site and find some testbeds, these ones shows how to print a string on screen and thinghs like this.
When I come from 16 bits to 32 bits, I perceive that the ms-dos int's "changed" to windows API. Some instructions like in or out , or some int's of bios are more dificult to access in win32, in old .com program is easy.
To debug something.com you use that debug that comes with you O.S, now, you can try debug using olly debug. In masm32 directory comes with some examples about console.
One thing you have in mind is; in old msdos the terminator character of one string is a "$", in win32 changed to "00h".
Other point of view is; you pass the parameters to some int's using registers in ms-dos, well in a default way, in win32 this can be true or not, to say, you can pass parameters of some functions using stack or registers. This is about calling conventions. In win64, the same point of view, but you can start passing some parameters using registers, and if no more registers by default are allowed, you pass the rest in stack.
the link below have one example about how to write some strings in a console.
http://www.masm32.com/board/index.php?topic=14734.0
Good luck Sr AiaKonai.

AiaKonai

Quote from: oex on September 13, 2010, 02:48:38 PM
You could use:

inkey "Press any key to continue ..."

(see \masm32\macros\macros.asm)

Maybe also a bad answer I dont come from 16 bit

Ok thanks everyone,
I have the pause fix working, but my lack of 32 bit knowledge means I also probably have some clutter.

    .486                                    ; create 32 bit code
    .model flat, stdcall                    ; 32 bit memory model
    option casemap :none                    ; case sensitive

    include \masm32\include\windows.inc     ; always first
    include \masm32\macros\macros.asm       ; MASM support macros

    include \masm32\include\masm32.inc
    include \masm32\include\gdi32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\MSVCRT.INC

    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\gdi32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\msvcrt.lib
.code
start:
    inkey "Press any key to continue..."
    invoke ExitProcess, 0
end start


If anyone is willing, I probably don't need all of those includes...
It will take me a lot longer to learn what each of those is for, but for now I have a working
small 32 bit exe that does the job.

Hopefully I will be able to find the newer choice replacement for win7/vista so I don't have to make
a replacement for that.

Thanks again!

AiaKonai

Thank you Mineiro, I may look into that eventually, but I have what I needed to fix the problem.

AiaKonai

Wow... easier than I expected.
I found a download for choice.exe and thankfully they kept the syntax the same.
So I have a batch file now that is free from those old com files and will
work on the ancient and new machines without problems.

rats....now I'll have to find another excuse to try and learn 32 bit assembly

Magnum

Quote from: AiaKonai on September 13, 2010, 03:48:03 PM
Quote from: oex on September 13, 2010, 02:48:38 PM
You could use:

inkey "Press any key to continue ..."

(see \masm32\macros\macros.asm)


If anyone is willing, I probably don't need all of those includes...

Thanks again!

Do worry about the includes.
If the program doesn't need them, they don't get "included."

Have a great day,
                         Andy

Magnum

Quote from: AiaKonai on September 13, 2010, 03:48:03 PM
Quote from: oex on September 13, 2010, 02:48:38 PM
You could use:

inkey "Press any key to continue ..."

(see \masm32\macros\macros.asm)


If anyone is willing, I probably don't need all of those includes...

Thanks again!

Don't worry about the includes.
If the program doesn't need them, they don't get "included."

Have a great day,
                         Andy

frktons

Quote from: redskull on September 13, 2010, 02:54:22 PM
Here is strictly win32 version

.data?
hConsoleIn  HANDLE ?
hConsoleOut HANDLE ?
NumWritten  DWORD ?
NumRead     DWORD ?
InBuffer    DWORD ?

.data
msg   db 0dh,0ah,'Press any key to continue ...', 0dh, 0ah


.code
start:

    invoke GetStdHandle, STD_INPUT_HANDLE
    mov hConsoleIn, eax
   
    invoke GetStdHandle, STD_OUTPUT_HANDLE
    mov hConsoleOut, eax
   
    invoke WriteConsole, hConsoleOut, ADDR msg, SIZEOF msg, ADDR NumWritten, NULL
   
    invoke ReadConsole, hConsoleIn, ADDR InBuffer, 1, ADDR NumRead, NULL

    invoke ExitProcess, 0
   
end start


-r

Well this routine needs to press ENTER key in order to work,
not 'Press any key to continue ...'.

In order to have the anykey is better to use another win32 API:


;----------------------------------------------------------------------
; Display the message "Press any key to continue..." and wait for
; the user to press a key
;----------------------------------------------------------------------

include \masm32\include\masm32rt.inc

;----------------------------------------------------------------------

.data

    msg   db 0dh,0ah,'Press any key to continue ...', 0dh, 0ah

.data?

     
    NumWritten  DWORD ?
    NumRead     DWORD ?

    wHnd      HANDLE ?
    rHnd      HANDLE ?


    buffer  INPUT_RECORD <>

.code

start:

Main PROC

    CALL   InitProc
    invoke WriteConsole, wHnd, ADDR msg, SIZEOF msg, ADDR NumWritten, NULL
    CALL   AnyKey
    invoke ExitProcess, 0
   
Main ENDP   

; -------------------------------------------------------------------------

InitProc PROC

    INVOKE GetStdHandle, STD_INPUT_HANDLE
    mov rHnd,eax

    INVOKE GetStdHandle, STD_OUTPUT_HANDLE
    mov wHnd,eax 

    ret

InitProc ENDP


; -------------------------------------------------------------------------
;Returns: key code in buffer.KeyEvent.wVirtualKeyCode WORD size
; -------------------------------------------------------------------------

AnyKey PROC

again: 

    INVOKE ReadConsoleInput,rHnd,offset buffer,1,offset NumRead
    cmp buffer.EventType,KEY_EVENT
    jnz again

    cmp buffer.KeyEvent.bKeyDown,0
    jz again

    ret

AnyKey ENDP

; -------------------------------------------------------------------------

end start
Mind is like a parachute. You know what to do in order to use it :-)

brethren

QuoteI have the pause fix working, but my lack of 32 bit knowledge means I also probably have some clutter.

i wouldn't necessarily call it clutter:) but if you want to shorten that source file have a look at \masm32\include\masm32rt.inc