Week 11 Sildes Descriptions
Week 11 Sildes Descriptions
Week 11 Sildes Descriptions
Instruction Guides
Title Description:
Slide #1 – Title
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.
Examples:
99 = 1001 1001
103 = 0001 0000 0011
combinations are never used: 1010, 1011, 1100, 1101, 1110, and 1111.
Examples:
12 = 0001 0010
+ 45 = 0100 0101
57 0101 0111
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
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
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
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 (Add with Carry) instruction adds the source operand and the carry flag to
the destination operand and places the result in the destination operand.
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.
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:
Pointers:
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 (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:
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
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:
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:
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:
Since the least significant nibble not greater than 9, the only adjustment needed is to
zero out the most significant nibble.
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
AL = 77H
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:
After the AAA instruction, the value of AL is adjusted to 00H. The operation is as
follows:
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 subtracts the source operand from the destination operand and
the places the result in the destination operand.
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
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 (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
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
Pointers:
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
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
Example:
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:
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.
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
SF = 0 ZF = 0 PF = 0 CF = 0 AF = 0 OF = 0
DAA
0010 1010
- 0110
0010 0100 – (24H)
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:
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:
Since the least significant nibble not greater than 9, the only adjustment needed is to
zero out the most significant nibble.
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
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:
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).