Overview of Assembly Language
Overview of Assembly Language
Advantages:
o Faster as compared to programs written using high-level languages
o Efficient memory usage
o Control down to bit level
Disadvantages:
Need to know detail hardware implementation
Not portable
Slow to development and difficult to debug
Basic components in assembly Language:
Instruction, Directive, Label, and Comment
The 16-bit FLAGS registers
Information is stored in individual bits of the FLAGS
register
Whenever an instruction is executed and produces a
result, it may modify some bit(s) of the FLAGS register
Example: Z (or ZF) denotes one bit of the FLAGS
register, which is set to 1 if the previously
executed instruction produced 0, or 0 otherwise
Flag Register
Flag register contains information reflecting the current status of
a microprocessor. It also contains information which controls the
operation of the microprocessor.
15 0
OF DF IF TF SF ZF
AF
PF
CF
Control Flags Status Flags
IF: Interrupt enable flag
CF: Carry flag
PF: Parity flag
DF: Direction flag
AF: Auxiliary carry flag
TF: Trap flag
ZF: Zero flag
SF: Sign flag
OF: Overflow flag
Overflow Flag (OF): indicates the overflow of a high-order bit (leftmost
bit) of data after a signed arithmetic operation.
Direction Flag (DF): determines left or right direction for moving or
comparing string data. When the DF value is 0, the string operation takes
left-to-right direction and when the value is set to 1, the string operation
takes right-to-left direction.
Interrupt Flag (IF): determines whether the external interrupts like
keyboard entry, etc., are to be ignored or processed. It disables the
external interrupt when the value is 0 and enables interrupts when set to
1.
Trap Flag (TF): allows setting the operation of the processor in single-
step mode. The DEBUG program we used sets the trap flag, so we could
step through the execution one instruction at a time.
Sign Flag (SF): shows the sign of the result of an arithmetic operation.
This flag is set according to the sign of a data item following the arithmetic
operation. The sign is indicated by the high-order of leftmost bit. A positive
result clears the value of SF to 0 and negative result sets it to 1.
Zero Flag (ZF): indicates the result of an arithmetic or comparison
operation. A nonzero result clears the zero flag to 0, and a zero result sets
it to 1.
Auxiliary Carry Flag (AF): contains the carry from bit 3 to bit 4 following
an arithmetic operation; used for specialized arithmetic. The AF is set
when a 1-byte arithmetic operation causes a carry from bit 3 into bit 4.
Parity Flag (PF): indicates the total number of 1-bits in the result obtained
from an arithmetic operation. An even number of 1-bits clears the parity
flag to 0 and an odd number of 1-bits sets the parity flag to 1.
Carry Flag (CF): contains the carry of 0 or 1 from a high-order bit
(leftmost) after an arithmetic operation. It also stores the contents of last
bit of a shift or rotate operation.
Generating Memory Addresses
How can a 16-bit microprocessor generate 20-bit
memory addresses?
Left shift 4 bits
FFFFF
+
16-bit register 0000
Addr1 + 0FFFF
Segment
16-bit register Offset
Addr1
Offset (64K)
20-bit memory address
Segment
00000 address
Intel 80x86 memory address generation 1M memory space
Memory Address Calculation
Segment addresses must be stored
0000
Segment address
in segment
registers
+
Offset is derived from the combination
Offset
of pointer registers, the
Instruction
Memory address
Pointer (IP), and immediate Values
Examples
Exercise:
Consider the byte at address 13DFE within 64K segment
defined by selector value 10DE. What is its offset?
13DDE = 10DE * 16
10
+ offset
offset = 13DFE - 10DE0
offset = 301E (a 16-bit quantity)
if zero is added to a decimal number it is multiplied by 10,
however 10h = 16, so if zero is added to a hexadecimal value, it
is multiplied by 16, for example:
7h = 7
70h = 112
MOV, Data Transfer Instructions
The MOV instruction copies the source operand to the destination operand
without affecting the source.
Five types of operand combinations are allowed with MOV:
Instruction type Example
-------------------------- ------------------
mov register, register mov DX, CX
mov register, immediate mov BL, 100
mov register, memory mov EBX, [count]
mov memory, register mov [count], ESI
mov memory, immediate mov [count], 23
Note: the above operand combinations are valid for all instructions that require
two operands.
here is a short program that demonstrates the use
of MOV instruction:
ORG 100h ; this directive required for a simple 1 segment .com program.
MOV AX, 0B800h ; set AX to hexadecimal value of B800h.
MOV DS, AX ; copy value of AX to DS.
MOV CL, 'A' ; set CL to ASCII code of 'A', it is 41h.
MOV CH, 1101_1111b ; set CH to binary value.
MOV BX, 15Eh ; set BX to 15Eh.
MOV [BX], CX ; copy contents of CX to memory at B800:015E
RET ; returns to operating system.
Examples
the main purpose of a register is to keep a number (variable). the size of the above
registers is 16 bit, it's something like: 0011000000111001b (in binary form),
or 12345 in decimal (human) form.
4 general purpose registers (AX, BX, CX, DX) are made of two separate 8 bit
registers, for example if AX= 0011000000111001b, then AH=00110000b and
AL=00111001b. therefore, when you modify any of the 8 bit registers 16 bit
register is also updated, and vice-versa. the same is for other 3 registers, "H" is for
high and "L" is for low part.