Week 11 Sildes Descriptions

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

QUEZON CITY POLYTECHNIC UNIVERSITY

673 Quirino Highway San Bartolome, Novaliches , Quezon City


BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

Instruction Guides

Subject Code : AR101 (Computer Organization and Architecture)

Week # / Lesson : Week 11 – Lesson9

Topic : Arithmetic Instructions

Title Description:

Slide #1 – Title

Discussion of Learning Outcomes:

 Differentiate all Arithmetic Instructions.


 Apply the different Arithmetic Instructions.

Slide #2 – Learning Outcomes

Slide #3 – Lesson Title

Review of Some Concepts Regarding the Binary Number System

1. Unsigned Integer. Unsigned integers may either be 8 bits or 16 bits in


length. Unsigned integers are viewed as positive numbers only. This means
that all bits are considered in determining the magnitude of a number.
Slide #4 – Review of Some
The value range of an unsigned integer is from 0 to 2n - 1. For 8 bits, the
Concepts Regarding the Binary
range is from 0 to 255, while for 16 bits, the range is from 0 to 65,535.
Number System
2. Signed Integer. Signed integers are viewed as either positive or negative
numbers. Because of this, the most significant bit is viewed as a sign bit (0
for positive and 1 for negative).

The value range of a signed integer is -2n-1 to 2n-1 - 1. For 8 bits, the range
is from -128 to +127 while for 16 bits, the range is from -32,768 to +32,767.
Negative numbers are represented in two’s complement.

3. Binary-Coded Decimal (BCD). In BCD, each decimal digit is represented in


one nibble.

Examples:

99 = 1001 1001
103 = 0001 0000 0011

BCD uses only 10 out of 16 possible combinations. The following 6


QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

combinations are never used: 1010, 1011, 1100, 1101, 1110, and 1111.

There are some situations in which arithmetic operations on BCD numbers


require some adjustments. This happens if the result of the operation falls
into one of the six unused combinations.

Examples:

12 = 0001 0010
+ 45 = 0100 0101
57 0101 0111

In this example, there is no need to adjust result.

12 = 0001 0010
+ 49 = 0100 1001
61 0101 1011

Since 1011 is an invalid BCD code, there is a need to adjust result. This can
be done by adding 6 (0110) to the result:

0101 1011
+ 0110
0110 0001 = 61

The 8086/8088 provides adjustment instructions for BCD-based arithmetic


operations.

4. Packed BCD. In packed BCD, two BCD digits could be packed into one byte.

5. Unpacked BCD. In unpacked BCD, one BCD digit is represented in one byte.
The BCD digit is represented in the least significant nibble, while the most
significant nibble may be 0 or any value

The ADD Instruction

Arithmetic instructions cover the four basic arithmetic operations: addition,


subtraction, multiplication, and division. Arithmetic instructions affect the status
flags.
Slide #5 – The ADD Instruction
The ADD instruction adds the source operand to the destination operand and then
places the result in the destination operand.

Pointers:

1. The ADD instruction does not allow both source and destination operands to
be memory locations (no memory to memory addition). Therefore, the
instruction ADD [BX], BETA is invalid.

2. Both source and destination operands should be of the same data size. The
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

instruction ADD AH, BX is therefore invalid.

3. The destination operand cannot be immediate data. Therefore, the


instruction ADD 1800H, CX is invalid.

4. All status flags are affected after execution.

5. As with the MOV instruction, if the destination operand is a memory location


and the source operand is immediate data, the prefix byte ptr or word ptr
should appear after the ADD instruction to denote the data size of the
immediate operand.

The ADD Instruction Example

Unless otherwise stated, determine the contents of all the affected general purpose
registers and flags after executing the following program. Each instruction is
dependent of one another. Whenever necessary, use the memory map (handout)
for additional data. Assume the following register contents and assume that all flags
Slide #6 – The ADD Instruction
are initially 0:
Example

The Answer:

Exercise #1

Slide #7 – Exercise #1
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

The ADC Instruction

The ADC (Add with Carry) instruction adds the source operand and the carry flag to
the destination operand and places the result in the destination operand.

Slide #8 – The ADC Instruction

One of the uses of the ADC instruction is in the implementation of 32-bit addition
(adding two 32-bit numbers).
Example:

Although there are no 32-bit addition instructions, the problem is easily solved by
using the ADD and the ADC instructions.

The ADC Instrucion Example

Unless otherwise stated, determine the contents of all the affected general purpose
registers and flags after executing the following program. Each instruction is
dependent of one another. Whenever necessary, use the memory map (handout)
for additional data. Assume the following register contents and assume that all flags
Slide #9 – The ADC Instrucion
are initially 0:
Example

We need to determine the content of the memory location specified by the source
operand. Since SP is used, stack segment is addressed.
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

Exercise #2

Unless otherwise stated, determine the contents of all the affected general purpose
registers and flags after executing the following program. Each instruction is
dependent of one another. Whenever necessary, use the memory map (handout)
for additional data. Assume the following register contents and assume that all flags
Slide #10 – Exercise #2
are initially 0:

The INC Instruction

The INC (Increment) instruction adds 1 to the destination operand

Slide # 11 – The INC


Instruction

Pointers:

1. The destination operand is viewed as an unsigned integer.


2. The INC instruction does not affect the carry flag.
3. Segment registers cannot be used as the destination operand. Therefore, the
instruction INC CS is invalid.
4. If the destination operand is a memory location, the prefix byte ptr or word
ptr should appear after the INC instruction to denote the data size of the
destination operand.
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

The INC Instruction Example

Unless otherwise stated, determine the contents of all the affected general purpose
registers and flags after executing the following program. Each instruction is
dependent of one another. Whenever necessary, use the memory map (handout)
for additional data. Assume the following register contents and assume that all flags
Slide #12 – The INC Instruction
are initially 0:
Example

The DAA Instruction

The DAA (Decimal Adjust for Addition) instruction adjusts the result of a previous
addition of two valid packed decimal operands.

Format: DAA
Slide # 13 – The DAA
Instruction
Pointers:
1. The result of the previous operation should be in register AL.
2. OF is undefined after execution.
3. DAA should be executed immediately after an ADD, ADC, or INC instruction.
4. The instruction will adjust the result as follows: if AF = 1, or either of the
nibbles is greater than 9, then 6 is added to the nibble(s) concerned.

Example:

MOV AL, 15H


MOV BL, 15H
ADD AL, BL
DAA

In this example, the values of AL and BL are viewed as packed BCD. Since DAA is
used to adjust the addition operation, the destination operand should be at AL.
Prior to DAA, the value of AL is 2AH. After the DAA instruction, the value of AL is
adjusted to 30H. The operation is as follows.

Since the least significant nibble of the intermediate result is greater than 9, DAA
adjusts the result by adding 6 to the least significant nibble

The DAA Instruction Example

Unless otherwise stated, determine the contents of all the affected general purpose
registers after executing the following program. Each instruction is dependent of one
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

another. Whenever necessary, use the memory map (handout) for additional data.
Assume the following register contents and assume that all flags are initially 0:

Slide #14 – The DAA


Instruction Example

The AAA Instruction

The AAA (ASCII Adjust for Addition) instruction adjusts the result of a previous
addition of two valid unpacked decimal operands.

Format: AAA
Slide #15 – The AAA
Instruction
Pointers:
1. The result of the previous operation should be in register AL.
2. OF, PF, SF, and ZF are undefined after execution.
3. AAA should be executed immediately after an ADD, ADC, or INC instruction.
4. The instruction will adjust the result as follows: if the least significant nibble
is greater than 9, then 6 is added to AL, and 1 is added to AH.
5. Regardless of the value of the least significant nibble, the most significant
nibble is always zeroed out.
6.
Example:

MOV AL, 35H; ASCII value of


5 MOV BL, 34H; ASCII value of 4
ADD AL, BL
AAA

In this example, the values of AL and BL are viewed as unpacked BCD (ASCII
numbers). Since AAA is used to adjust the addition operation, the destination
operand should be at AL. Prior to AAA, the value of AL is 69H. After the AAA
instruction, the value of AL is adjusted to 09H. The operation is as follows:

35H = 0011 0101


34H = 0011 0100
0110 1001 = 69H

Since the least significant nibble not greater than 9, the only adjustment needed is to
zero out the most significant nibble.

The AAA Instruction Example

Unless otherwise stated, determine the contents of all the affected general purpose
registers after executing the following program. Each instruction is dependent of one
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

another. Assume that all flags are initially 0:

MOV AL, 74H


MOV BL, 75H
ADD AL, BL
AAA
Slide #16 – The AAA
Instruction Example
Answer

MOV AL, 74H

AL = 77H

MOV BL, 75H

BL = 75H

ADD AL, BL

In this example, the values of AL and BL are viewed as unpacked BCD (ASCII
numbers). Since AAA is used to adjust the addition operation, the destination
operand should be at AL. Prior to AAA, the value of AL is ECH. The operation is as
follows:

74H = 0111 0111


75H = 0111 0101
1110 1100 = ECH
AAA

After the AAA instruction, the value of AL is adjusted to 00H. The operation is as
follows:

ECH = 1110 1100


AAA = 0000 0110
1111 0010 = F2H

Since the least significant nibble is greater than 9, the adjustment needed is to add 6
to AL and to zero out the most significant nibble. The final value of AL is 02H.

The SUB Instruction

The SUB instruction subtracts the source operand from the destination operand and
the places the result in the destination operand.

Slide #17 – The SUB


Instruction

Pointers:

1. The SUB instruction does not allow both source and destination operands to
be memory locations (no memory to memory addition). Therefore, the
instruction SUB [BX], BETA is invalid.
2. Both source and destination operands should be of the same data size. The
instruction SUB AH, BX is therefore invalid.
3. The destination operand cannot be immediate data. Therefore, the
instruction SUB 1800H, CX is invalid.
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

4. All status flags are affected after execution.


5. As with the MOV instruction, if the destination operand is a memory location
and the source operand is immediate data, the prefix byte ptr or word ptr
should appear after the SUB instruction to denote the data size of the
immediate operand

The SUB Instruction Example

Unless otherwise stated, determine the contents of all the affected general purpose
registers and flags after executing the following program. Each instruction is
dependent of one another. Whenever necessary, use the memory map (handout)
for additional data. Assume the following register contents and assume that all flags
Slide #18 – The SUB
are initially 0:
Instruction Example

The SBB Instruction

The SBB (Subtract with Borrow) instruction subtracts the source operand and the
carry flag from the destination operand and then places the result in the destination
operand.
Slide #19 – The SBB
Instruction

Just like in addition, subtracting a 32-bit number from another 32-bit number can be
done with the combination of the SUB and the SBB instructions.

Example:
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

The SBB Instruction Example

Unless otherwise stated, determine the contents of all the affected general purpose
registers and flags after executing the following program. Each instruction is
dependent of one another. Whenever necessary, use the memory map (handout)
for additional data. Assume the following register contents and assume that all flags
Slide #20 – The SBB are initially 0:
Instruction Example
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

SI = 0006H

The DEC Instruction

The DEC (Decrement) instruction subtracts 1 from the destination operand

Slide #21 – The DEC


Instruction

Pointers:

1. The destination operand is viewed as an unsigned integer.


2. The DEC instruction does not affect the carry flag.
3. Segment registers cannot be used as the destination operand. Therefore,
the instruction DEC CS is invalid.
4. If the destination operand is a memory location, the prefix byte ptr or word
ptr should appear after the DEC instruction to denote the data size of the
destination operand.

The DEC Instruction Example

Unless otherwise stated, determine the contents of all the affected general purpose
registers after executing the following program. Each instruction is dependent of one
another. Assume that all flags are initially 0:
Slide #22 – The DEC
DEC AX
Instruction Example
DEC BX
DEC CX
DEC DX

AX = 0014H BX = 0018H CX = 0011H DX = 001AH

The DAS Instruction

The DAS (Decimal Adjust for Subtraction) instruction adjusts the result of a previous
subtraction of two valid packed decimal operands.

Format: DAS
Slide #23 – The DAS
Instruction
Pointers:
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

1. The result of the previous operation should be in register AL.


2. OF is undefined after execution.
3. DAS should be executed immediately after a SUB, SBB, or DEC instruction.
4. The instruction will adjust the result as follows: if AF = 1, or either of the
nibbles is greater than 9, then 6 is subtracted from the nibble(s) concerned.

Example:

MOV AL, 34H


MOV BL, 19H
SUB AL, BL
DAS

In this example, the values of AL and BL are viewed as packed BCD. Since DAS is used
to adjust the subtraction operation, the destination operand should be at AL. Prior
to DAS, the value of AL is 1BH. After the DAS instruction, the value of AL is adjusted
to 15H. The operation is as follows:

34H = 0011 0100


19H = 0001 1001
0001 1011 = 1BH
- 0110
0001 0101 = 15H

Since the least significant nibble of the intermediate result is greater than 9, DAS
adjusts the result by subtracting 6 to the least significant nibble.

The DAS Instruction Example

Unless otherwise stated, determine the contents of all the affected general purpose
registers after executing the following program. Each instruction is dependent of one
another. Assume that all flags are initially 0:
MOV AL, 3FH
Slide # 24 – The DAS
MOV BL, 15H
Instruction Example
SUB AL, BL
DAS
Answer
MOV AL, 3FH
AL = 3FH
MOV BL, 15H
BL = 15H
SUB AL, BL

[AL] – 3FH = 0011 1111


[BL] – 15H = 0001 0101
0010 1010 – (2AH)

SF = 0 ZF = 0 PF = 0 CF = 0 AF = 0 OF = 0

DAA
0010 1010
- 0110
0010 0100 – (24H)

The AAS Instruction


QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

The AAS (ASCII Adjust for Subtraction) instruction adjusts the result of a previous
subtraction of two valid unpacked decimal operands.

Format: AAS

Pointers:
Slide #25 – The AAS
Instruction
1. The result of the previous operation should be in register AL.
2. OF, PF, SF, and ZF are undefined after execution.
3. AAS should be executed immediately after a SUB, SBB, or DEC instruction.
4. The instruction will adjust the result as follows: if the least significant nibble
is greater than 9, then 6 is subtracted from AL, and 1 is subtracted from AH.
5. Regardless of the value of the least significant nibble, the most significant
nibble is always zeroed out

Example:

MOV AL, 39H; ASCII value of 9


MOV BL, 34H; ASCII value of 4 SUB AL, BL
AAS

In this example, the values of AL and BL are viewed as unpacked BCD (ASCII
numbers). Since AAS is used to adjust the subtraction operation, the destination
operand should be at AL. Prior to AAS, the value of AL is 05H. After the AAS
instruction, the value of AL is adjusted to 05H. The operation is as follows:

39H = 0011 1001


34H = 0011 0100
0000 0101 = 05H

Since the least significant nibble not greater than 9, the only adjustment needed is to
zero out the most significant nibble.

The AAS Instruction Example

Unless otherwise stated, determine the contents of all the affected general purpose
registers after executing the following program. Each instruction is dependent of one
another. Assume that all flags are initially 0:
MOV AL, 8EH
Slide # 26 – The AAS
MOV BL, 62H
Instruction Example
SUB AL, BL
AAS
Answer

MOV AL, 8EH


AL = 8EH
MOV BL, 62H
BL = 62H
SUB AL, BL
In this example, the values of AL and BL are viewed as unpacked BCD (ASCII
numbers). Since AAS is used to adjust the subtraction operation, the destination
operand should be at AL. Prior to AAS, the value of AL is 2CH. The operation is as
follows:

8EH = 1000 1110


62H = 0110 0010
0010 1100 = 2CH

AAA
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

After the AAA instruction, the value of AL is adjusted to 00H. The operation is as
follows:

2CH = 0010 1100


AAA = 0000 0110
0010 0110 = 26H

Since the least significant nibble is greater than 9, the adjustment needed is to
subtract 6 from AL and to zero out the most significant nibble. The final value of AL
is 26H.

End of Lesson

Summary

References:
Slide #27 – End of Lesson
[1] Williams, Stallings (2010), Computer Organization and Architecture:
Designing for Performance (8th Edition, Prentice Hall, New Jersey).

[2] Stalling, William, Computer Organization and Architecture:


Principles of Structure and Function (4th Edition)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy