Hello,
I am new to assembly, and I am trying to convert a 16 bit com program into a 32 bit exe.
I understand the basics decently well.
Here is one of the programs I need to convert to an exe.
NAME 'rpause'
PAGE 55,132
TITLE 'rpause'
CSEG SEGMENT PARA PUBLIC 'CODE'
ASSUME cs:CSEG,ds:CSEG,es:CSEG,ss:CSEG
ORG 100h
_start:
mov dx,offset msg
mov ah,09h
int 21h
mov ax,0c08h
int 21h
int 21h
mov ax,4c00h
int 21h
msg db 0dh,0ah,'Press any key to continue ...',0dh,0ah,'$'
CSEG ENDS
END _start
This is a replacement for the pause command in a batch file.
Since the pause command does not clear the keyboard buffer before taking input.
This replacement works perfectly, but it is a com file.
It is not exactly easy to make com files work on 64 bit machines :(. (dosbox being the only way i've seen one work)
I am searching for a tutorial that will cover how to do this same thing as a 32 bit exe.
And if anyone happens to have the newer equivalant to choice.com, that is the other com file I need to replace.
Thank you for any help you provide.
in this code you no need any reason to use 32 bit registers.
?? What are you talking about,
This is a 16 bit program.
I need a 32 bit equivalent.
So I'm trying to find a good guide on very basic input and output for a 32 bit exe made in assembler.
OK
What is that you posted?
Very confused now.
you may use 32 bit registers. You realy need it when use XMS memory
in this example using 32 bit registers make programe two time quickly
why are you posting a 16 bit program in response to a question about
how to make a 32 bit program???
I understand you want the programe that do the same
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
http://www.masm32.com/board/index.php?topic=14702.15
see here post vortex
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
That's wonderful!! I am trying to move towards making it 32 bit :D not 16 bit.
Do you have any examples of this inkey?
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
Quote from: bomz on September 13, 2010, 02:50:02 PM
http://www.masm32.com/board/index.php?topic=14702.15
see here post vortex
This will help with the command line handling it looks like.
Thank you.
@redskull
umm............. THANKS A TON!!!!
Even though I did want to learn how to do it myself, that should help
me move towards making more complex stuff.
Thank you very much.
not only command line this is example of console programe.
batch to compile console program
ECHO OFF
COLOR 9F
CLS
C:\masm32\bin\ml.exe /c /coff current.asm
C:\masm32\bin\link.exe /subsystem:console current.obj
DEL current.obj
pause
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.
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!
Thank you Mineiro, I may look into that eventually, but I have what I needed to fix the problem.
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
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."
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."
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
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