You are on page 1of 9

Activity No.

2
Registers
Course Code: CPE005 Program: BSCPE
Course Title: Computer Systems Organization with Assembly Language Date Performed:
Section: Date Submitted:
Name: Ruiz, Mark Daniel D. Instructor:
1. Objective:
This activity aims to demonstrate how the CPU registers are 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, and 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 command is used for multiplication.
The DIV command 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
Table 2.2- Default Operands for Multiplication
No. of Bits Multiplicand Multiplier Product
8 bits x 8 AL register or memory AX (16 bits)
16 bits x 16 AX register or memory DX:AX (32 bits)
32 bits x 32 EAX register or memory EDX:EAX (64 bits)

Table 2.3- Default Operands for Division


No. of BIts Dividend Divisor Quotient Remainder
16 bits / 8 AX register, memory (8-bit) AL AH
32 bits / 16 DX:AX register, memory (16-bit) AX DX
64 bits / 32 EDX:EAX register, memory (32-bit) EAX 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. Ifthe
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 ispositive. If
the signs of the dividend and divisor are different, then quotient sign is negative. Theremainder sign is
always the same sign as the dividend. You can always check your work viaquotient*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?
Some flags are cleared.The registers also satisfy the conditions of the flags.
3. Modify the value of the AX register, type
-R AX
AX 0000
:1234_ <Enter>
4. Trace if the contents of register AX changed. Type,
-T
What happened to the value of AX register?
The AX register’s value is now 1234.
______________________________________________________________________________
5. 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>
6. Check if the value of the Parity flag changed. Type,
-R F<Enter>
What is now the new value in of the flag register?
Nothing has changed.
7. Reset the values of the registers. Type,
-Q

Sample Problem B:
1. Open Debug.exe
2. Assemble the following program:
-A 100
movax,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?
The output has shown that the sum of bx and si is being moved to AL. And it shows that the
value of AX has chanhed and the carry flag has been set.
5. Record all results in Table 2.5.
6. Reset the values of the registers.

Sample Problem C.
1. Open Debug.exe.
2. Assemble the following program:
-A 100
mov al,00
sub al,01
int 21
2. Trace the values of the registers.
3. Observe the output.
Which flag/flags was/were affected by the given? Why?
The EL and PL were affected because of the negative register.

4. Record all results in Table 2.6.


5. Reset the values of the registers.

Sample Problem D.
1. Open Debug.exe.
2. Assemble the following program:
-A 100
mov al,0a
mov bl,05
mulbl
int 21
7. Trace the values of the registers.
Table 2.5 -Result of Sample Problem B.5
8. Observe the output.
What did you observe in the output? Why?
Instruction Register Content Flag Register
BL is being multiplied to all registers.
9. Record all results in Table 2.7.
AX BX CX DX IP NV U EI PL N N P N
10. Reset the values of the registers.
P Z A O C
Sample
MOVProblem E.
AX,FFFF FFF 0000 000 000 010 NV U EI PL N N P N
F 0 0 0 P Z A O C
1. Open Debug.exe.
ADD 2. AX,01
Assemble the following
FFF program:
0000 000 000 010 NV U EI PL N N P N
-A 100 F 0 0 3 P Z A O C
mov dx,0
INT 21hmov ax,8003 0000 0000 000 000 010 NV U EI PL Z A P C
mov cx,100 Table 2.5 -Result
0 of
0 Sample
6 Problem C.5 P R C E Y
div cx
Instruction Register Content Flag Register
int 21
3. Trace the values ofAX the registers.
BX CX DX IP
4. Observe the output.
What MOV
did you
AL,00
observe in the 0000
output? 0000
Why? 000 000 010 NV U EI PL N N P N
All register has been divided by cx. And 0 also,0the register
0 cx hasP the value 0100Zmoved
A into
O it.C And
ax is divided by cx.
SUB AL,01 00F 0000 000 000 010 NV U EI PL N N P N
5. Record all resultsFin Table 2.8. 0 0 2 P Z A O C
6. Reset the values of the registers.
INT 21h 00F 0000 000 000 010 NV U EI N N A P C
F 0 0 4 P G Z C E Y

6. DATA ANALYSIS:
Table 2.4- Result of Sample Problem A.2

AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000


DS=06B0 ES=06B0 SS=06B0 CS=06B0 IP=0100 NV UP EI PL NZ NA PO NC
Table 2.5 -Result of Sample Problem C.5
Instruction Register Content Flag Register

AX BX CX DX IP

MOV AL,0a 0000 0000 000 000 010 NV U EI PL N N P N


0 0 0 P Z A O C

MOV BL,05 000 0000 000 000 010 NV U EI PL N N P N


A 0 0 2 P Z A O C

MUL BL 000 0005 000 000 010 NV U EI PL N N P N


A 0 0 4 P Z A O C

INT 21h 0032 0005 000 000 010 NV U EI PL N N P N


0 0 6 P Z A O C

Table 2.5 -Result of Sample Problem D.5


7. PROBLEMS:
Instruction Register Content Flag Register
1. Determine two 8-bit numbers that will cause the following flag conditions to occur after the addition.
Verify that yourAXnumbers
BX causeCXthespecified
DX IPflag conditions by modifying your program with your
new numbers, executing it, andrecording the flag values. Use HEX numbers.
MOV DX,00 0000 0000 000 000 010 NV U EI PL N N P N
a. Carry = 0, Overflow = 0, Zero = 0, Sign
0 = 00: ___________
0 P + ___________Z A = ___________
O C

MOV AX,8003 8003 0000 000 000 010 NV U EI PL N N P N


0 0 2 P Z A O C

MOV CX, 100 000 0005 000 100 010 NV U EI PL N N P N


A 0 4 P Z A O C

DIV CX 0000 0000 000 000 010 NV U EI PL N N P N


0 0 6 P Z A O C

INT 21h 0000 0000 000 000 010 NV U EI PL N N P N


0 0 8 P Z A O C
b. Carry = 0, Overflow = 0, Zero = 0, Sign = 1: ___________ + ___________ = ___________

c. Carry = 1, Overflow = 1, Zero = 0, Sign = 0: ___________ + ___________ = ___________


d. Carry = 0, Overflow = 1, Zero = 0, Sign = 1: ___________ + ___________ = ___________
e. Carry = 1, Overflow = 0, Zero = 0, Sign = 1 : ___________ + ___________ = ___________
f. Carry = 1, Overflow = 0, Zero = 0, Sign = 0 : ___________ + ___________ = ___________
g. Carry = 0, Overflow = 0, Zero = 1, Sign = 0 : ___________ + ___________ = ___________

2. Make a program that shows a division overflow.


3. Make a program that would implement the expression : var4 = (var1 * -5) / (-var2 + var3);

8. CONCLUSIONS

The registers can have data stored to them temporarily. Also, they’re versatility allows them to be
manipulated with flags and arithmetic
.

9. Assessment (Rubric for Laboratory Performance):

You might also like