AL Basics
AL Basics
1
Define Byte, Word
2
Define Byte, Word
• list db 10,20,30,40
will store the four values in consecutive locations. If the
offset of list is 0000, they will be stored in 0000, 0001,
0002, 0003, respectively. list refers to 0000, list+1
refers to 0001, etc.
• Value1 dw 2AB6h
will place two bytes in consecutive locations with the low
order byte in the lower memory location as: B6 2A
3
Character or String Constants
• ‘ABC’
• “This is a test.”
• ‘This is my file.’
4
Pointer
Given:
message db ‘ABC’ ;define 3 bytes
P db message ;P points to
message
5
ASCII Table
6
MOV Instruction
• Allowable MOVs with scratch registers
MOV reg,reg
MOV mem,reg
MOV reg,mem
MOV mem,immed
MOV reg,immed
7
Direct Operands
8
Illegal Moves
9
Label Directive
.data
countB label byte ;byte attribute,
;no storage allocated
countw dw 0020h ;word attribute
.code
mov al,countB ;retrieve low byte of count
mov cx,countW ;retrieve all of count
countB
countW
20 00
Addressing Modes
11
Based Index Addressing Example
Adding Bytes
12
Based Index Addressing Example
Adding Words
13
Stack Operation
14
Assemble-Link-Execute Cycle
.obj
.lst
.map
15
Hello World .lst File
Origin Group
0001:0 DGROUP
17
XCHG Instruction
18
XCHGing Two Variables
19
Arithmetic Instructions
INC and DEC Instructions
inc destination ;add 1 to destination
dec destination ;subtract 1 from destination
Examples:
inc al
dec ax
dec byte ptr membyte ;dec 8-bit memory operand
dec memword ;dec memory operand
inc word ptr memword ;inc 16-bit memory operand
20
Arithmetic Instructions
ADD Instruction
add destination, source
Contents of Registers
Before After
21
Arithmetic Instructions
ADD Instruction
Consider the way in which add and adc, add with a carry,
deal differently with the carry flag. Both the AX and BX
registers contain 0000 and the carry flag is set, CY.
22
Arithmetic Instructions
SUB Instruction
sub destination, source
Contents of Registers
Before After
23
Arithmetic Instructions
MUL Instruction
mul multiplier ;multiplicand in ax
;product in dx,ax
Example: mul bx
Contents of Registers
Before After
24
Arithmetic Instructions
DIV Instruction
div divisor ;dividend in dx,ax: quotient in ax
;remainder in dx
Example: div bx
Contents of Registers
Before After
25
Memory Models
Produces .com
files
What we will
use
Linear
addressin
g 26
Overlapping Segments
27