Hardware Reference
In-Depth Information
A MASM32 walkthrough
Finally, to illustrate how MASM32 assemble, disassemble and provide debug-
ging and other information, the following assembly language code is for a
simple number guessing game:
; *************************************************************************
; Source file: compare.asm
; Language: x86 assembler for MASM32
; Function: Program compares an input value with an immediate value (10)
; and prints one of three messages to indicate the result of the comparison
; Project build: use "Console Assemble & Link"
; Executable: runs from command prompt
; *************************************************************************
;
.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
call main
; branch to the "main" procedure
exit
main proc
LOCAL var1:DWORD ; space for a DWORD variable
LOCAL str1:DWORD ; a string handle for the input data
mov var1, sval(input("Please enter a number between 1 and 20: "))
cmp var1, 10
; compare the input number with 10
je equal
; Is the input number equal to 10?
jg greater
; Is the input number greater than 10?
jl less
; Is the input number less than 10?
equal:
print chr$("The number you entered is 10",13,10)
jmp over
greater:
print chr$("The number you entered is greater than 10",13,10)
jmp over
Search WWH ::




Custom Search