Documente Academic
Documente Profesional
Documente Cultură
ASSEMBLY LANGUAGE
PROGRAM DEVELOPMENT
WITH MASM
LABEL:
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
7.1
7.2
7.3
7.4
7.5
Register
Symbol
Register
AX
Accumulator register
SI
AH
DI
AL
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
Constants in a statement
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
Based
Destination
Indexed
Source
Based indexed
Destination
MOV [BP][SI]+DISP, AH
MOV [BP][DI]+DISP, AH
Stack
Stack
EXAMPLE
DIRECTIVE
OPERAND(S)
; COMMENT (S)
Solution:
EXAMPLES:
DB
0FFH
DB
Constants in a statement
Constants in an instruction or directives can be
expressed in any of many data types such binary,
decimal, hexadecimal, octal, and character data
types.
The first digit of a hexadecimal number must be on of
the numbers in the range 0 through 9.
Typically, data and addresses are expressed in
hexadecimal form, and the count for shift, rotate, and
string instructions in commonly expressed in decimal
form.
2s complement of the number must be used for
negative numbers expressed in binary, hexadecimal,
or octal form.
611 37100 Lecture 07-8
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
EXAMPLE
Solution:
or
or
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
Type
Operator
Value-returning
Function
Example
Function
SEG
SEG A
NOT
NOT A
OFFSET
OFFSET A
AND
A AND B
TYPE
TYPE A
SIZE
SIZE A
LENGTH
LENGTH A
OR
XOR
A OR B
A XOR B
EXAMPLE
Find the value the assembler assigns to the source operand for
the instruction
MOV BH, ( A * 4 2 ) / ( B 3 )
for A=8 and B=5
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
Operator
Example
Function
PTR
NEAR PTR A
ES: A
SHORT
JMP SHORT A
THIS
THIS BYTE A
HIGH
HIGH A
LOW
LOW A
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
Type
Attribute
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
Code segment
Data segment
Stack segment
Data directives
Segment-control directives
Directive
EQU
Meaning
Equate
Function
Assign a permanent value to a symbol
Equal to
DB or BYTE
Define byte
DW or WORD
Define word
DD or DWORD
Define
double word
Directive
Function
SEGMENT
ENDS
ASSUME
Segment directives
Data directives
EXAMPLES:
Segment-control directives
EXAMPLES:
AA
BB
AA
BB
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
SEGA SEGMENT
ASSUME
MOV
.
.
.
SEGA ENDS
Segment-control directives
Attribute
Function
PARA
BYTE
WORD
PAGE
Function
proc-name ENDP
PUBLIC Symbol[..]
Align-type attributes
Segment-control directives
Attribute
Function
PUBLIC
COMMON
AT [expression]
STACK
MEMORY
Combine-type attributes
Segment-control directives
Attribute
CSEG1
Function
CODE
DATA
STACK
EXTRA
SUB
SUB
Class attributes
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
Directive
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
[]
Assembler
Program
Source
Listing
Source listing
Spelling error
of DEC
Program
starting
address
List syntax
error A2006
Original
source code
Machine
Code
Object module 2
(MOD2.OBJ)
Run
module
Link
Program
Symbol
table
Link
map
Object module 3
(MOD3.OBJ)
Comment out
the variable N
List syntax
error A2008