Overview of Assembly Language: S. Dandamudi
Overview of Assembly Language: S. Dandamudi
Chapter 3
S. Dandamudi
Outline
• Assembly language • Overview of assembly
statements language instructions
• Data allocation ∗ Arithmetic
∗ Conditional
• Where are the operands?
∗ Logical
∗ Addressing modes
∗ Shift
» Register
∗ Rotate
» Immediate
» Direct • Defining constants
» Indirect ∗ EQU and = directives
• Data transfer instructions • Illustrative examples
∗ mov, xchg, and xlat • Performance: When to use
∗ PTR directive the xlat instruction
1998 S. Dandamudi Introduction: Page 2
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Springer-Verlag, 1998.
Assembly Language Statements
• Three different classes
∗ Instructions
» Tell CPU what to do
» Executable instructions with an op-code
∗ Directives (or pseudo-ops)
» Provide information to assembler on various aspects of the
assembly process
» Non-executable
– Do not generate machine language instructions
∗ Macros
» A shorthand notation for a group of statements
» A sophisticated text substitution mechanism with parameters
1998 S. Dandamudi Introduction: Page 3
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Springer-Verlag, 1998.
Assembly Language Statements (cont’d)
• Assembly language statement format:
[label] mnemonic [operands] [;comment]
∗ Typically one statement per line
∗ Fields in [ ] are optional
∗ label serves two distinct purposes:
» To label an instruction
– Can transfer program execution to the labeled instruction
» To label an identifier or constant
∗ mnemonic identifies the operation (e.g. add, or)
∗ operands specify the data required by the operation
» Executable instructions can have zero to three operands
1998 S. Dandamudi Introduction: Page 4
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Springer-Verlag, 1998.
Assembly Language Statements (cont’d)
∗ comments
» Begin with a semicolon (;) and extend to the end of the line
Examples
repeat: inc result ; increment result
CR EQU 0DH ; carriage return character
Examples
sorted DB ’y’
response DB ? ;no initialization
value DW 25159
float1 DQ 1.234
je jump if equal
jg jump if greater
jl jump if less
jge jump if greater or equal
jle jump if less or equal
jne jump if not equal
∗ jz is synonymous for je
∗ jnz is synonymous for jne
1998 S. Dandamudi Introduction: Page 45
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Springer-Verlag, 1998.
Overview of Assembly Instructions (cont’d)
Loop Instruction
LOOP Instruction
∗ Format:
loop target
∗ Semantics:
» Decrements CX and jumps to target if CX ≠ 0
– CX should be loaded with a loop count value
• Example: Executes loop body 50 times
mov CX,50
repeat:
<loop body>
loop repeat
...
1998 S. Dandamudi Introduction: Page 46
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Springer-Verlag, 1998.
Overview of Assembly Instructions (cont’d)
Loop Instruction
• The previous example is equivalent to
mov CX,50
repeat:
<loop body>
dec CX
jnz repeat
...
∗ Surprisingly,
dec CX
jnz repeat
executes faster than
loop repeat
1998 S. Dandamudi Introduction: Page 47
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Springer-Verlag, 1998.
Overview of Assembly Instructions (cont’d)
Logical Instructions
∗ Format:
and destination,source
or destination,source
not destination
∗ Semantics:
» Performs the standard bitwise logical operations
– result goes to destination
∗ TEST is a non-destructive AND instruction
test destination,source
∗ Performs logical AND but the result is not stored in
destination (like the CMP instruction)
1998 S. Dandamudi Introduction: Page 48
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Springer-Verlag, 1998.
Overview of Assembly Instructions (cont’d)
Logical Instructions
Example: Testing the value in AL for odd/even number
SHL CF 0
Bit Position: 7 6 5 4 3 2 1 0
SHR 0 CF
Bit Position: 7 6 5 4 3 2 1 0
ROL CF
Bit Position: 7 6 5 4 3 2 1 0
ROR CF
Bit Position: 7 6 5 4 3 2 1 0
RCL CF
Bit Position: 7 6 5 4 3 2 1 0
RCR CF
Bit Position: 7 6 5 4 3 2 1 0
x lat
ith
Conversion time (seconds)
3
w
ut xlat
w itho
0
0 20 40 60 80 100 120 140 160 180 200
Number of calls (in thousands)
txlat
hou
wit
Conversion time (seconds)
6
x lat
with
4
0
0 20 40 60 80 100 120 140 160 180 200
Number of calls (in thousands)