The following slides of this week explain the sample program, , in detail.
Filename Extensions
A filename extension indicates the kind of data stored in the file.
Extension
Comments
.ASM
Assembly language source file (uncompiled)
.BAT
Batch file, ASCII file of DOS commands, [EXECUTABLE]
.EXE
Executable file (program) (binary) [EXECUTABLE]
.LST
List file
.MAP
A text file that contains information about the segments contained in a program being linked
.OBJ
Object file
.PDB
The program database file with which the debugger is then able to display the program’s source code and provide supplemental information about the program.
TITLE Directive
A directive is a command that is recognized and acted upon by the assembler. It is not related to the Intel instruction set. Directives are used for defining logical segments, choosing a memory model, defining variables, creating procedures, and so on.
TITLE Read and Subtract (ReadSub.asm)
The directive marks the entire line as a comment.
Comments
Comments can be specified in two ways:
Single-line comments, beginning with a semicolon character ().
call WriteString ; print prompt1
Block comments, beginning with the directive and a user specified symbol such as ().
COMMENT !
This program reads and subtracts 32-bit integers.
!
ReadSub.asm
COMMENT!
*
* This program reads and subtracts 32-bit hexadecimal integer from 50000h.
*
!
INCLUDE Irvine32.inc
.data
prompt1 BYTE 0Dh, 0Ah, "Calculate an Arithmetic Expression of 50000h - Y:",
0Dh, 0Ah, 0
prompt2 BYTE "Enter the value of operand Y: ", 0
prompt3 BYTE 0Dh, 0Ah, "The result is ", 0
X DWORD 50000h
Y DWORD ?
result DWORD ?
.code
main PROC
mov edx, OFFSET prompt1
call WriteString ; print prompt1
mov edx, OFFSET prompt2
call WriteString ; print prompt2
call ReadHex
mov Y, eax ; Y = eax (the input)
mov eax, X ; eax = X (50000h)
; calculate 50000h – Y
sub eax, Y ; eax = X (50000h) – Y (the input)
mov result, eax ; result = eax (X – Y)
mov edx, OFFSET prompt3
call WriteString ; print prompt3
call WriteHex ; print eax (result)
exit
main ENDP
END main
An Execution Example
Calculate an Arithmetic Expression of 50000h – Y:
Enter the value of operand Y: 4000
The result is 0004C000
†The white italic text with a navy background color is entered by users.