Sie sind auf Seite 1von 22

Introduction to Assembly

Language
Bits and Bytes

08/06/09
 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

2
Integer Representation

08/06/09
 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/06/09
 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/06/09
5
Registers

08/06/09
 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

 BL = 05h 6
Registers

08/06/09
 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/06/09
 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
processes in the stack. 8
Registers

08/06/09
 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
9
implementation of a stack in memory that a
program uses for temporary storage of addresses
Registers

08/06/09
 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/06/09
 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
Direction flag (DF) – it is used in string operations
to determine the direction of data transfer. UP is
displayed for upward direction; DN is displayed for
11
downward direction
Registers

08/06/09
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/06/09
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/06/09
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/06/09
 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
debugging executable programs 15
08/06/09
 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/06/09
 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 17
at a specific location address
 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/06/09
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 18

storage
Basic Assembly Instruction used in
Debug

08/06/09
 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> 19
add cx, bx
add ax, 0308
Basic Assembly Instruction used in
Debug

08/06/09
 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/06/09
 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>
loop 0108 21
08/06/09
Seatwork...

22

Das könnte Ihnen auch gefallen