Vous êtes sur la page 1sur 22

INTRODUCTION TO

ASSEMBLY LANGUAGE
BITS AND BYTES

08/23/10
 Bits – fundamental building block of computer storage. It is a
contraction of the compound word “binary digit”
 Bytes – each group of 8 related bits. It is the basic unit of binary
information.
 Related bytes

Term Meaning
Nibble Half of a byte
Byte Group of 8 bits
Word A 2-byte (16-bit) data item
Doubleword A 4-byte (32-bit) data item
Quadword An 8-byte(64-bit) data item
Paragraph A 16-byte(128-bit) data item
Kilobyte Equivalent to 1,024 bytes (210 )
2
Megabyte Equivalent to 2, 048 bytes (220 )
INTEGER REPRESENTATION

08/23/10
 Sign-magnitude – the leftmost bit is the sign
bit ; the most significant bit (MSB)
 Ones’ complement – negation of the number
is obtained by inverting each of its bits
 Two’s complement – the negation of the
number is obtained by inverting each of its
bits then adding 1 to the resulting bit pattern

3
ASCII

08/23/10
 To get information in and out of the
computer, we need to use numbers, letters
and other symbols. This implies some kind of
alphanumeric code for the I/O unit of a
computer
 American Standard Code for Information
Interchange

4
ASCII TABLE

08/23/10
5
REGISTERS

08/23/10
 General Purpose Registers
 AX register – sometimes called as the
accumulator. This is used in input, output and
arithmetic operations
 AX = 8035h
 AH = 80h

 AL = 35h

 BX Register – also known as the Base Register. It


is also used for computations since it is the only
general purpose register that can be used to
extend addressing
 BX = 0C05h
 BH = 0Ch
6
 BL = 05h
REGISTERS

08/23/10
 General Purpose Registers
 CX register – referred to as the counter register.
This is used with certain instructions that
perform operations repeatedly. It can also be
used for computations
 CX = B1F2h
 CH = B1h

 CL = F2h

 DX register – also known as data register. It is


used to hold data for any purposes. Some I/O
operations and multiply/divide operations that
involve large values require its use
 DX = 0BEAh
 DH = 0Bh

 DL = EAh
7
REGISTERS

08/23/10
 Pointer Registers
 BP register – this 16-bit base pointer register
facilitates referencing parameters, which are the
data, and addresses that a program passes
through the stack
 IP register – this 16-bit instruction pointer
register contains the offset address of the next
instruction that is to execute. It is associated
with the CS register in that the IP indicates the
current instruction within the currently executing
code segment
 SP register – this 16-bit stack pointer provides an
offset value which when associated with the SS
register, refers to the current word being
8
processes in the stack.
REGISTERS

08/23/10
 Segment Registers
 CS register – CODE SEGMENT register contains the
starting address of a program’s code segment. This
segment address plus an offset value in the IP register
indicates the address of an instruction to be fetched for
execution
 DS register – DATA SEGMENT register contains the
starting address of a program’s data segment.
Instructions use this to locate data
 ES register – EXTRA SEGMENT register is used by some
string operations to handle memory addressing.
 SS register – STACK SEGMENT register permits the
implementation of a stack in memory that a program
uses for temporary storage of addresses and data
9
REGISTERS

08/23/10
 Index Registers – these are registers
available for indexed addressing and
addition/subtraction operations
 SI register – the 16-bit SOURCE INDEX register is
required for some string operations. It is
associated with the DS register
 DI register – the 16-bit DESTINATION INDEX
register is also required for some operations and
is associated with the ES register.

10
REGISTERS

08/23/10
 Flag Registers – these are special registers
that indicate the present status of the
computer and the results of processing
 Overflow flag (OF) – it indicates that the result of
an operation is too long to be stored in the
destination operand; OV is displayed if there is an
overflow; NV is displayed for no overflow
mov al, 04
add al, 7f
int 20
 Directionflag (DF) – it is used in string operations
to determine the direction of data transfer. UP is
displayed for upward direction; DN is displayed 11
for downward direction
REGISTERS

08/23/10
 Interrupt Flag (IF) – it indicates that all external
interrupts such as keyboard entry are to be
processed or ignored. EI is displayed for enable
interrupt; DI for disabled interrupt
mov ah, 02
mov dl, 41
int 21
int 20
 Sign Flag (SF) – indicates that the result of an
operation is positive or negative. PL for plus and
NG for negative
mov al, 03
sub al, 08 12
int 20
REGISTERS

08/23/10
 Zero Flag (ZF) – it indicates whether an operation
produced a zero result. ZR is displayed for zero;
NZ for nonzero.
mov ax, 0008
sub ax, 0008
int 20
 Auxiliary Flag (AF) – similar to carry flag except
that it indicates the presence or absence of a
carry or borrow based on 4-bit numeric
representation in bits. NA for no auxiliary carry;
AC for auxiliary carry
mov al, ff
sub al, 01 13
int 20
REGISTERS

08/23/10
 Parity Flag (PF) – it indicates whether the result of
an operation contains an even number or odd
number of 1s. PE is displayed for parity even; PO
for parity odd
Mov al, 08
Add al, 02
Int 20
 Carry Flag (CF) – it indicates whether the
instructions produced a value that can be too big
( or too small) to be held in the specified register
or memory location. CY for carry; NC for no carry
mov al, ff
sub al, 01
int 20 14
DEBUG

08/23/10
 Bug – computer technology for error or
mistake in a program or computer system
 Debugging – is a methodological process of
finding and reducing the number of bugs or
defects in a computer program
 Debugger –is a program tool that provides an
environment for testing load modules. Load
modules are executable files that can have
extensions of .COM and .EXE
 Debug – is a software that is classified as
debugger which is used for testing and
15
debugging executable programs
08/23/10
 Advantages of debug
 It is free.
 It is universally available.
 It is simple to use.
 It requires relatively little memory.
 Rules of debug command
 It is not case-sensitive.
 It assumes that all numbers given are in
hexadecimal format.
 You can enter a space only when it is needed to
separate parameters of a particular command.
16
DEBUG COMMANDS

08/23/10
 Q (Quit) – finishes the debug session and exits
back to DOS environment
 H( Hexarithmetic) – shows the sum and
difference of two 4-digit hexadecimal numbers,
coded as H <hex value> <hex value>
 R(Register) – allows you to display all registers
and their values. It also shows the next
instruction and permits you to change the value
of a particular register.
 E (Enter) – enables you to key in data or
machine instructions into memory beginning at
a specific location address 17
 D (Display or Dump) – displays the contents of a
portion memory in hex and ASCII forms starting with
the given address
 A(Assemble) – allows you to create program in

08/23/10
mnemonic or symbolic code. It also translates this
assembly
 T( Trace) – runs the program in single-step mode. It
also displays the new values of the registers and the
next instruction to be executed.
 G(Go) – runs the program as a whole in memory and
displays the output
 U(Unassemble) – lists all the instructions contained in
the program beginning at the given address
 N(Name) – Gives a name to your program, coded as N
<path> <filename>. The base name of the filename
must be eight characters long and the extension name
is .COM
 W(Write) – saves the program onto the disk storage
18
BASIC ASSEMBLY INSTRUCTION USED
IN DEBUG

08/23/10
 Mov (move data) – it copies and transfers data
between two registers, or between an immediate
data to a register
 Mov <register>, <register>
 Mov <register>, <immediate data>
mov ax, bx
mov cx, 5083
 Add (add data) – it is used to get the sum of two
registers or a register and an immediate data,
and stores the result to the left most register
 Add <register>, <register>
 Add <register>, <immediate data>
add cx, bx
add ax, 0308 19
BASIC ASSEMBLY INSTRUCTION USED
IN DEBUG

08/23/10
 SUB(subtract data) – it is used to get the
difference of two registers or a register and an
immediate, and stores the result to the left most
register
sub <register> , <register>
sub <register> , <immediate data>
sub cx, bx
sub ax, 0308
sub al, bl
 MUL (multiply data) – it is used to get the product
of a given register and AX register, and stores the
result to AX register. If the product is greater than
16 bits, the overflow is stored in DX register
 mul <register> 20
 mul cx
 DIV (divide data) – it is used to divide the value of a
given register and AX register, and stores the quotient
to AX and the remainder to DX registers respectively
 DIV <register>
div bx

08/23/10
 INC (increment by one) – it is used to increase the
value of the register by one
 inc <register>
inc ax
 DEC(decrement by one) – the opposite of INC, instead
of increasing, it decreases the value of the register by
one
 dec <register>
dec ax
 Loop (loop until complete) – it controls the execution
of a program segment in a specified number of times.
The CX register should contain a count value before
starting the loop and automatically decrements by
one. If CX register is not equal to zero, it transfers to
its operand address which points to the start of the
loop, otherwise it drops through the next instruction
 loop <offset address> 21
loop 0108
08/23/10
22

Vous aimerez peut-être aussi