You are on page 1of 9

Activity No.

2
Registers
Course Code: CPE 021 Program:
Course Title: Computer Architecture and Organization Date Performed:
Section: Date Submitted:
Name: 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?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
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?


______________________________________________________________________________
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?
______________________________________________________________________________
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?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
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?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
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.
8. Observe the output.
What did you observe in the output? Why?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
9. Record all results in Table 2.7.
10. Reset the values of the registers.

Sample Problem E.

1. Open Debug.exe.
2. Assemble the following program:
-A 100
mov dx,0
mov ax,8003
mov cx,100
div cx
int 21
3. Trace the values of the registers.
4. Observe the output.
What did you observe in the output? Why?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
5. Record all results in Table 2.8.
6. Reset the values of the registers.

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=_______ ES=_______ SS=_______ CS=_______ IP=0100 NV UP EI PL NZ NA PO NC

Table 2.5 -Result of Sample Problem C.5


Instruction Register
Table Content
2.5 -Result of Sample Problem B.5 Flag Register

Instruction AX BX CX
Register DX
Content IP Flag Register
MOV AL,0a AX BX CX DX IP
MOV
MOV BL,05
AX,FFFF
MUL BL
ADD AX,01
INT
INT 21h
21h

Table 2.5 -Result of Sample Problem D.5


C.5
Instruction Register Content Flag Register
Instruction Register Content Flag Register
AX BX CX DX IP
AX BX CX DX IP
MOV AL,00
MOV DX,00
SUB AL,01
MOV AX,8003
INT 21h
MOV CX, 100

DIV CX

INT 21h

7. PROBLEMS:

1. Determine two 8-bit numbers that will cause the following flag conditions to occur after the addition.
Verify that your numbers cause thespecified flag conditions by modifying your program with your
new numbers, executing it, andrecording the flag values. Use HEX numbers.
a. Carry = 0, Overflow = 0, Zero = 0, Sign = 0: ___________ + ___________ = ___________
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

9. Assessment (Rubric for Laboratory Performance):

You might also like