Professional Documents
Culture Documents
PROGRAM DEVELOPMENT
WITH MASM
OPCODE
OPERAND(S)
; COMMENT (S)
EXAMPLES:
START: MOV CX, 10 ;Load a count of 10 into register CX
MOV CX, 10 ;Initialize the count in CX
CLC
Register
AX
Accumulator register
AH
AL
Symbol
Register
SI
DI
SP
BX
Base register
BP
BH
CS
BL
DS
CX
Counter register
SS
CH
ES
CL
DX
Data register
DH
DL
Operand
Example
Segment
Register
Destination
Immediate
Source
Direct
Destination
MOV VARIABLE, AX
Data
Register indirect
Source
Data
Stack
Data
Data
MOV [BX]+DISP, AL
Data
MOV [BP]+DISP, AL
Stack
Data
Data
MOV [BX][SI]+DISP, AH
Data
MOV [BX][DI]+DISP, AH
Data
MOV [BP][SI]+DISP, AH
Stack
Based
Indexed
Based indexed
Destination
Source
Destination
MOV [BP][DI]+DISP, AH
Stack
DIRECTIVE
OPERAND(S)
; COMMENT (S)
EXAMPLES:
DB
0FFH
DB
Solution:
or
or
Solution:
The binary form of 1010 is 010102. Forming the 2s complement
by complementing each bit and adding 1, we get
10101
+1
10110
Therefore, the instruction is written as
MOV CX, 10110B
Operator
Arithmetic
A*B
Example
Function
A/B
MOD
A MOD B
SHL
A SHL n
SHR
A SHR n
A+B
A-B
Operator
Relational
EQ
A EQ B
Example
Function
NE
A NE B
LT
A LT B
GT
A GT B
LE
A LE B
GE
A GE B
Logical
Operator
Example
Function
NOT
NOT A
AND
A AND B
A OR B
A XOR B
OR
XOR
Solution:
The solution is calculated as
(8*4-2)/(5-3) = (32 2)/(2)
= (30)/(2)
= 15
And using hexadecimal notation, we get the instruction
MOV BH, 0FH
Solution:
Substituting into the expression, we get
234 LE (345 111)
234 LE 234
since the relational operator is satisfied, the instruction is
equivalent to
MOV AX, 0FFFFH
Operator
Example
Function
SEG
SEG A
OFFSET
OFFSET A
TYPE
TYPE A
SIZE
SIZE A
LENGTH
LENGTH A
Attribute
Operator
Example
Function
PTR
NEAR PTR A
ES: A
SHORT
JMP SHORT A
THIS
THIS BYTE A
HIGH
HIGH A
LOW
LOW A
Directives
ASSUME
ENDS
NAME
COMMENT
EQU
ORG
DB or BYTE
= (EQUAL SIGN)
PROC
DD or DWORD
EVEN
PUBLIC
DQ or GWORD
EXTRN
.RADIX
DT or TBYTE
GROUP
RECORD
DW OR WORD
INCLUDE
SEGMENT
END
LABEL
STRUC
ELSE
IFDEF
IFNB
ENDIF
IFDIF
IFNDEF
IF
IFE
IF1
IFB
IFIDN
IF2
ENDM
IRPC
PURGE
EXITM
LOCAL
REPT
IRP
MACRO
.CREF
PAGE
TITLE
.LALL
.SALL
.XALL
.LFCOND
.SFCOND
.XCREF
.LIST
SUBTTL
.XLIST
%OUT
.TFCOND
ENDP
Conditional
Macro
Listing
Meaning
Function
EQU
Equate
Equal to
DB or BYTE
Define byte
DW or WORD
Define word
DD or DWORD
Define
double word
10
EQU 0100H
EQU AA+5H
= 0100H
= AA+5H
CC DB 7
EE DB ?
MESSAGE DB JASBIR
TABLE_A DB 10 DUP(?), 5 DUP(7)
TABLE_B DB 0,1,2,3,4,5,6,7,8,9
11
Function
SEGMENT
ENDS
ASSUME
Segment directives
12
Function
PARA
BYTE
WORD
PAGE
Align-type attributes
Function
PUBLIC
COMMON
AT [expression]
STACK
MEMORY
Combine-type attributes
13
Function
CODE
DATA
STACK
EXTRA
Class attributes
Function
proc-name ENDP
PUBLIC Symbol[..]
14
SUB
SUB
CSEG1
PUBLIC
SEGMENT
.
.
PROC
MOV
.
.
RET
ENDP
.
.
.
ENDS
SUB
CSEG2
FAR
AX, BX
Module 1
CSEG2
EXTRN
SEGMENT
.
.
CALL
.
.
.
.
.
ENDS
SUB:FAR
SUB
Module 2
15
Function
ORG [expression]
END [expression]
EXAMPLE:
ORG 100H
ORG 100H
ORG $+200H
(memory locations 10016 to 30016 are skipped and the machine
code of the program can start at address 30116)
Function
TITLE text
SUBTTL text
EXAMPLE:
PAGE 50 100
PAGE +
611 37100 Lecture 07-32
16
17
[]
Object
Module
Source
Program
Assembler
Program
Source
Listing
18
Program
starting
address
Original
source code
Machine
Code
Symbol
table
19
Comment out
the variable N
List syntax
error A2008
Spelling error
of DEC
List syntax
error A2006
20
Object module 2
(MOD2.OBJ)
Run
module
Link
Program
Link
map
Object module 3
(MOD3.OBJ)
21
22
23