I will try to port source code from Randy Hyde's book "The Art of Assembly Language", Windows 32-bit Edition to MASM source code in this topic. I think there are many good examples of code from this valuable book although the source code from this book use HLA :toothy.
I hope you could give me a hand here, too!
Any contribution (comment, advice, optimization, fix, source code etc.) is really appreciated :cheekygreen:.
The electronic edition of "The Art of Assembly Language Programming", Windows 32-bit Edition:
Art of Assembly Language Programming and HLA by Randall Hyde
http://homepage.mac.com/randyhyde/webster.cs.ucr.edu/www.artofasm.com/Windows/index.html
I will update the list of source code in this post.
List of Source Code
HelloWorld, 1_01HelloWorld.hla => 1_01HelloWorld.asm (http://www.masm32.com/board/index.php?topic=17700.msg149123#msg149123)
DemoVars, 1_02DemoVars.hla => 1_02DemoVars.asm (http://www.masm32.com/board/index.php?topic=17700.msg149143#msg149143)
1_01HelloWorld.hla
program HelloWorld;
#include( "stdlib.hhf" )
begin HelloWorld;
stdout.put( "Hello, World of Assembly Language", nl );
end HelloWorld;
MASM:
1_01HelloWorld.asm
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
; Build this with the "Project" menu using
; "Console Assemble and Link"
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.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 files that have MASM format prototypes for function calls
; -----------------------------------------------------------------
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
; ------------------------------------------------
; Library files that have definitions for function
; exports and tested reliable prebuilt code.
; ------------------------------------------------
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.code ; Tell MASM where the code starts
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start: ; The CODE entry point to the program
print chr$("Hello, World of Assembly Language",13,10)
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start ; Tell MASM where the program ends
1_02DemoVars.hla
Program DemoVars;
#include( "stdlib.hhf" );
static
InitDemo: int32 := 5;
NotInitialized: int32;
begin DemoVars;
// Display the value of the pre-initialized variable:
stdout.put( "InitDemo's value is ", InitDemo, nl );
// Input an integer value from the user and display that value:
stdout.put( "Enter an integer value: " );
stdin.get( NotInitialized );
stdout.put( "You entered: ", NotInitialized, nl );
end DemoVars;
MASM:
Could you improve my code please :bg ?
1_02DemoVars.asm
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
; Build this with the "Project" menu using
; "Console Assemble and Link"
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.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 files that have MASM format prototypes for function calls
; -----------------------------------------------------------------
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
; ------------------------------------------------
; Library files that have definitions for function
; exports and tested reliable prebuilt code.
; ------------------------------------------------
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
InitDemo dd 5 ; 32 bit value initialised to 5
.data?
NotInitialized dd ? ; Uninitialised single 32 bit space
str1 dd ? ; a string handle for the input data
.code ; Tell MASM where the code starts
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start: ; The CODE entry point to the program
print chr$("InitDemo's value is ")
print str$(InitDemo)
print chr$(13,10)
mov str1, input("Enter an integer value: ")
mov NotInitialized, sval(str1) ; convert the result to a signed integer
print chr$("You entered: ")
print str$(NotInitialized)
print chr$(13,10)
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start ; Tell MASM where the program ends
Could you improve my code of 1_02DemoVars.asm please :bg ?
have a look at masm32\include\masm32rt.inc
you only need to include that one file
it replaces all of this....
.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 files that have MASM format prototypes for function calls
; -----------------------------------------------------------------
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
; ------------------------------------------------
; Library files that have definitions for function
; exports and tested reliable prebuilt code.
; ------------------------------------------------
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
print str$(InitDemo)
print chr$(13,10)
;
print str$(NotInitialized)
print chr$(13,10)
can be
print str$(InitDemo),13,10
;
print str$(NotInitialized),13,10
generally, with console mode apps, it's a good idea to add....
inkey
exit
Thanks to dedndave, 1_02DemoVars.asm is improved :bg :
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
; Build this with the "Project" menu using
; "Console Assemble and Link"
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
.data
InitDemo dd 5 ; 32 bit value initialised to 5
.data?
NotInitialized dd ? ; Uninitialised single 32 bit space
str1 dd ? ; a string handle for the input data
.code ; Tell MASM where the code starts
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start: ; The CODE entry point to the program
print chr$("InitDemo's value is ")
print str$(InitDemo),13,10
mov str1, input("Enter an integer value: ")
mov NotInitialized, sval(str1) ; convert the result to a signed integer
print chr$("You entered: ")
print str$(NotInitialized),13,10
inkey
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start ; Tell MASM where the program ends