Lecture5-80x86 Assembly Programming I
Lecture5-80x86 Assembly Programming I
Review
• 80x86 memory organization
– Memory segments
• Addressing modes
1
10/6/2024
Outline
• Assembly statement
• Model definition
• Segments definition
• Building programs
• Data movement instructions
• Control transfer instructions
– Short, near and far
• Data types and definition
2
10/6/2024
Form of a Statement
[label:] mnemonic [operands] [;comment]
• label is a reference to this statement
– Rules for names: each label must be unique; letters, 0-
9, (?), (.), (@), (_), and ($); first character cannot be a
digit; less than 31 characters
– “:” is needed if it is an instruction
• Mnemonic and the operands perform the real
work of the program.
• “;” leads a comment, the assembler omits
anything on this line following a semicolon
3
10/6/2024
Model Definition
• The MODEL directive selects the
size of the memory model
– SMALL: code <= 64KB
data <= 64KB
– MEDIUM: data <= 64KB
code > 64KB
– COMPACT:code <= 64KB
data > 64KB
– LARGE: data > 64KB
(single set of data<64KB)
code> 64KB
– HUGE: data > 64KB
code > 64KB
– TINY: code + data < 64KB
4
10/6/2024
5
10/6/2024
Program Execution
• Program starts from the
entrance
– Ends whenever calls 21H
interrupt with AH = 4CH
• Procedure caller and callee
– CALL procedure
– RET
6
10/6/2024
7
10/6/2024
➢ Memory-to-memory only
with MOVS
Check the reference for more details
Microprocessors and Interfacing 15
8
10/6/2024
Conditional Jumps
• Jump according to the value of the flag
register
• Short jumps
• Example:
Unconditional Jumps
• JMP [SHORT|NEAR|FAR PTR] label
• Near by default
• In FAR jump, both IP and CS change
– another way to obtain a far jump is to define a
label as a far label
– The JMP UP instruction references a far label.
• label UP is defined as a far label by the EXTRN UP:FAR
directive
9
10/6/2024
10
10/6/2024
11
10/6/2024
Example
12
10/6/2024
13
10/6/2024
.COM Executable
• One segment in total
– Put data and code all together
– Less than 64KB
Next Lecture
• 8086 Assembly
– Addition and subtraction
– Multiplication and division (unsigned)
– BCD arithmetic
– Rotate instructions
14