Activity 2
Activity 2
2
Registers
Course Code: CPE005
Course Title: Computer Systems Organization with Assembly Language
Section: EC31FB1
Name: GAYAS, MARON MARVIN A.
1. Objective:
This activity aims to demonstrate how the CPU registers are
Program: BSECE
Date Performed: 07/08/16
Date Submitted: 07/08/16
Instructor:
used for addition, subtraction,
multiplication and division operations and how the flag register are affected by these operations
2. Intended Learning Outcomes (ILOs):
After completion of this activity the students should be able to:
1.1 Examine the contents internal CPU registers
1.2 Modify internal CPU register contents
1.3 Demonstrate addition, subtraction, multiplication and division operations
3. Discussion :
The Registers
Every computer contains registers or small areas that can store data temporarily. These registers are too
small to store files instead they are used to store information while the program is running. These registers
are specific for every computer manufacturer. Before one can program in assembly language one should
be familiar with the registers inside their computer and the width of these registers because assembly
language is machine-dependent or machine-specific programming language.
The 8088 CPU for example, has fourteen 16 bit registers to process the data in a computer.
Four are for data: AX,BX,CX,DX
Four are for segment addresses: ES,DS,SS,CS
Four are for index addressing: SP,BP,SI,DI
One is the instruction pointer:- IP
One is the flag register : Flag
The 8086, 8088 and 80286 computers are characterized by a 16-bit architecture. The computers from
the 80386 to the Pentium use the complete 32-bit architecture.
The registers are divided in three categories namely:
General-purpose registers
Segment Registers
Other Registers
The general-purpose registers are primarily used for arithmetic and data movement. Each register can
be addressed as either a single 32-bit value or two 16-bit values. Portions of some registers can be
addressed as 8-bit values.
For example, the 32-bit EAX register has a 16-bit lower half named AX. The AX register, in turn, has
an 8-bit upper half named AH (A-High) and an 8-bit lower half named AL(A-Low).
The same overlapping relationship exists for the EAX, EBX, ECX, and EDX registers.
The remaining general-purpose registers only have specific names for their lower 16 bits, these are
used when writing real-address mode programs.
THE FLAGS
The EFLAGS (or just Flags) register consists of individual binary bits that control the operation of the
CPU or reflect the result of arithmetic and logical instructions. Some instructions test and manipulate
individual processor flags.
A flag is set when it equals 1; it is clear (or reset) when it equals 0. Figure 2-1 shows how each flag is
represented by DEBUG.
Table 2.1- The Flag Register bit representation in DEBUG
Set
Clear
OV= Overflow
NV=No Overflow
DN= Direction Down
UP=Direction Up
EI= Enable Interrupt
DI=Disable Interrupt
NG= Sign Flag Negative
PL=Sign Flag Positive
ZR=Zero
NZ=Not Zero
AC=Auxiliary Carry
NA=No Auxiliary Carry
PO=Parity Odd
PE=Parity Even
CY=Carry
NC=No Carry
The ARITHMETIC OPERATORS
The four basic arithmetic operators are the ADD, SUB, MUL, DIV.
The ADD is used for addition.
Syntax:
ADD destination, source ;dest operand = dest operand + source operand
The destination operand can be a register or in memory. The source operand can be a register, in memory
or immediate data.
ADC, which means to add the two operands plus the carry.
Syntax
ADC destination, source ;dest = dest + source + CF (carry flag)
The SUB is used for subtraction.
The form of the two equivalent subtraction operations (subtract and subtract with borrow) are:
Syntax :
SUB dest, souce ;dest = dest - source
SBB dest, source ;dest = dest - source CF
If the Carry Flag is set after the operation, then a larger number was subtracted from a smaller number, and
a 'borrow' occurred which sets the carry flag.
The MUL is used for multiplication.
The DIV is used for division.
In multiplication and division operations, the x86 microprocessor use the registers AX, AL, AH, EAX, DX
and EDX as used as shown in Table 2.1 and Table 2.2
No. of Bits
8 bits x 8
16 bits x 16
32 bits x 32
No. of BIts
16 bits / 8
32 bits / 16
64 bits / 32
Remainder
AH
DX
EDX
The operands can be considered as signed numbers or unsigned numbers. The unsigned multiplication
and division operations are MUL, DIV.
The signed multiplication/division operations are IMUL, IDIV.
For signed multiplication, if the two numbers have the same sign the result is always positive. If the
operands are different signs then the result will be negative.
For signed division, if the signs of the dividend and divisor are the same, then the quotient sign is positive.
If the signs of the dividend and divisor are different, then quotient sign is negative. The remainder sign is
always the same sign as the dividend. You can always check your work via quotient*divisor + remainder =
dividend)
4. Resources:
Computer with 32-bit Operating System
Debug.exe
5. Procedure:
Sample Problem A.
1. Run DEBUG.EXE.
2. Examine the register contents, type
-R
Observe the output and record all results in Table 2.4.
What did you observed as the default values of the flags? Why?
-The registers satisfy the conditions of the flags. Some flags are set, some are cleared.
Modify the value of the AX register, type
-R AX
AX 0000
:1234_ <Enter>
3. Trace if the contents of register AX changed. Type,
-T
What happened to the value of AX register?
-The value of the AX register changed from 0000 to 1234.
4. Change the value of the Parity flag, from Parity Odd (default) to Parity Even. Type
-R F
NV UP EI PL NZ NA PO NC -PE <Enter>
5. Check if the value of the Parity flag changed. Type,
-R F <Enter>
What is now the new value in of the flag register?
-The value of the flag register is now PE.
6. Reset the values of the registers. Type,
-Q
Sample Problem B:
1. Open Debug.exe
2. Assemble the following program:
-A 100
mov ax,ffff
add ax,01
int 21
3. Trace the values of the registers starting at address 0100
-T=100 2
4. Observe the output.
What did you observe in the output? Why?
-At first line we put a value in the AX register which is FFFF. Following with a command add,
ax 01 and int 21. The program is complete as have been instructed and ready the outputs are
ready to be shown. Two outputs have appear, the first command and the second command. At
first line it shows the process when 01 has been added to AX. At the second line it show that
the value of the AX has changed and the carry flag has been set.
5. Record all results in Table 2.5.
Sample Problem D.
1. Open Debug.exe.
2. Assemble the following program:
-A 100
mov al,0a
mov bl,05
mul bl
int 21
1. Trace the values of the registers.
2. Observe the output.
What did you observe in the output? Why?
-At first line I declare the al to be 0A following with the bl to be 05. Then I declare the bl to be
multiplied to all registers which follows the al to have the only value in all of the register aside from bl.
3. Record all results in Table 2.7.
Register Content
Flag Register
AX
BX
CX
DX
IP
NV
U
P
EI
PL N N
Z A
P N
O C
MOV AX,FFFF
FFF
F
0000
000
0
000 010
0 0
NV
U
P
EI
PL N N
Z A
P N
O C
ADD AX,01
FFF
F
0000
000
0
000
0
010
3
NV
U
P
EI
PL N N
Z A
P N
O C
INT 21h
0000 0000
000
0
000
0
010
6
NV
U
P
EI
PL Z A
R C
P C
E Y
Flag Register
AX
BX
CX
DX
IP
MOV AL,00
0000
0000
000
0
000
0
010
0
NV
U
P
EI
PL N N
Z A
P N
O C
SUB AL,01
00F
F
0000
000
0
000
0
010
2
NV
U
P
EI
PL N N
Z A
P N
O C
INT 21h
00F
F
0000
000
0
000
0
010
4
NV
U
P
EI
N
G
P C
E Y
6. DATA ANALYSIS:
N A
Z C
AX
Register Content
Flag Register
Table 2.5 -Result of Sample Problem C.5
BX Register
CX Content
DX
IP
Flag Register
0000 AX
0000 BX000
0
0000 0000
0000 0000 000
0
000 0000
8003 A 0000 000
0
000 0005
8003 A 0000 010
0
0032 0005
0080 0000 010
0
000
CX
0
000
000
0
0
000
0000
0
000
0000
0
000
0000
0
010
DX
0
000
010
0
3
000
0010
6
000
0010
9
000
0010
B
NV
IP
010
0NV
010
2 NV
010
4 NV
010
6 NV
U
P
NV
U
P
NV
U
P
NV
U
P
NV
U
P
EI
U
EI
P
U
EI
P
U
EI
P
U
EI
P
PL N
Z
EI PL
PL N
Z
EI PL
PL N
Z
EI PL
PL N
Z
EI PL
PL N
Z
N
A
N
NZ
A
N
NZ
A
N
NZ
A
N
NZ
A
P
O
N
P
A
O
N
P
A
O
N
P
A
O
N
P
A
O
N
C
P
NO
C
P
NO
C
P
NO
C
P
NO
C
N
C
N
C
N
C
N
C
PROBLEMS:
1. Determine two 8-bit numbers that will cause the following flag conditions to occur after the
addition. Verify that your numbers cause the specified flag conditions by modifying your program
with your new numbers, executing it, and recording the flag values. Use HEX numbers.
a. Carry = 0, Overflow = 0, Zero = 0, Sign = 0: 0001 + 0001 = 0002
3. Make a program that would implement the expression : var4 = (var1 * -5) / (-var2 + var3);
8. Assessment (Rubric for Laboratory Performance):