You are on page 1of 23

Computer Organization and Assembly Language

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.

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).

3.

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

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.

Arithmetic Instructions

* Property of STI
Page 1 of 23

Computer Organization and Assembly Language

The ADD Instruction
Ø

The ADD instruction adds the source
operand to the destination operand and
then places the result in the destination
operand.
Format:
Action:

ADD D, S
D
[D] + [S]

Destination

Source

register

register

register

MM

ADD DX, [BP + SI]

MM

register

ADD [BX + DI], CX

register

immediate

ADD BX, 0015H

MM

immediate

ADD byte ptr
BETA, 12H

Arithmetic Instructions

Example
ADD BX, CX

* Property of STI
Page 2 of 23

Computer Organization and Assembly Language

Example – ADD Instruction

Ø

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
are initially 0:

AX =

0015H

BP =

0002H

CS = 3000H

BX =

0019H

SP =

0035H

DS = 2000H

CX = 0012H

DI =

0017H

SS = 2000H

DX = 001BH

SI =

001EH ES = 4000H

ADD AX, BX
ADD [SI], DI

Arithmetic Instructions

* Property of STI
Page 3 of 23

Computer Organization and Assembly Language

Exercise 1

Ø

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
are initially 0:

AX =

0015H

BP =

0002H

CS = 3000H

BX =

0019H

SP =

0035H

DS = 2000H

CX = 0012H

DI =

0017H

SS = 2000H

DX = 001BH

SI =

001EH ES = 4000H

ADD AX, [CX]
ADD [DX], SI

Arithmetic Instructions

* Property of STI
Page 4 of 23

Computer Organization and Assembly Language

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.
Format: ADC D, S
Action: D
[D] + [S] + [CF]

Ø

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

Arithmetic Instructions

* Property of STI
Page 5 of 23

Computer Organization and Assembly Language

Example – ADC Instruction

Ø

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
are initially 0:

AX =

0015H

BP =

0002H

CS = 3000H

BX =

0019H

SP =

0035H

DS = 2000H

CX = 0012H

DI =

0017H

SS = 2000H

DX = 001BH

SI =

001EH ES = 4000H

MOV AX, FAFAH
MOV BX, [SP]
ADD AX, BX
ADC SI, DI
Arithmetic Instructions

* Property of STI
Page 6 of 23

Computer Organization and Assembly Language

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
are initially 0:

AX =

0015H

BP =

0002H

CS = 3000H

BX =

0019H

SP =

0035H

DS = 2000H

CX = 0012H

DI =

0017H

SS = 2000H

DX = 001BH

SI =

001EH ES = 4000H

MOV CX, EBADH
MOV BX, [SI]
ADD CX, BX
ADC AX, DX
Arithmetic Instructions

* Property of STI
Page 7 of 23

Computer Organization and Assembly Language

The INC Instruction

Ø

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

Format: INC D
Action: D

Destination
register
MM

Arithmetic Instructions

[D] + 1

Example
INC AX
INC byte ptr [BX]

* Property of STI
Page 8 of 23

Computer Organization and Assembly Language

Example – INC Instruction

Ø

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
are initially 0:

AX =

0015H

BP =

0002H

CS = 3000H

BX =

0019H

SP =

0035H

DS = 2000H

CX = 0012H

DI =

0017H

SS = 2000H

DX = 001BH

SI =

001EH ES = 4000H

INC AX
INC BX
INC CX
INC DX
Arithmetic Instructions

* Property of STI
Page 9 of 23

Computer Organization and Assembly Language

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
Example:
MOV AL, 15H
MOV BL, 15H
ADD AL, BL
DAA

Arithmetic Instructions

* Property of STI
Page 10 of 23

Computer Organization and Assembly Language

Example – DAA Instruction

Ø

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 that all flags
are initially 0:

AX =

0015H

BP =

0002H

CS = 3000H

BX =

0019H

SP =

0035H

DS = 2000H

CX = 0012H

DI =

0017H

SS = 2000H

DX = 001BH

SI =

001EH ES = 4000H

MOV AL, F5H
MOV BL, F5H
ADD AL, BL
DAA
Arithmetic Instructions

* Property of STI
Page 11 of 23

Computer Organization and Assembly Language

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
Example:
MOV AL, 35H;
MOV BL, 34H;
ADD AL, BL
AAA

Arithmetic Instructions

ASCII value of 5
ASCII value of 4

* Property of STI
Page 12 of 23

Computer Organization and Assembly Language

Example – AAA Instruction
Ø

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 that all flags
are initially 0:

AX =

0015H

BP =

0002H

CS = 3000H

BX =

0019H

SP =

0035H

DS = 2000H

CX = 0012H

DI =

0017H

SS = 2000H

DX = 001BH

SI =

001EH ES = 4000H

MOV AL, 74H
MOV BL, 75H
ADD AL, BL
AAA
Arithmetic Instructions

* Property of STI
Page 13 of 23

Computer Organization and Assembly Language

The SUB Instruction

Ø

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

SUB D, S
D

[D] - [S]

Destination

Source

register

register

register

MM

SUB DX, [BP + SI]

MM

register

SUB [BX + DI], CX

register
MM

Arithmetic Instructions

Example
SUB BX, CX

immediate SUB BX, 0015H
immediate SUB byte ptr
BETA, 12H
* Property of STI
Page 14 of 23

Computer Organization and Assembly Language

Example – SUB Instruction

Ø

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
are initially 0:

AX =

0015H

BP =

0002H

CS = 3000H

BX =

0019H

SP =

0035H

DS = 2000H

CX = 0012H

DI =

0017H

SS = 2000H

DX = 001BH

SI =

001EH ES = 4000H

SUB AX, BX
SUB [SI], DI

Arithmetic Instructions

* Property of STI
Page 15 of 23

Computer Organization and Assembly Language

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.
Format:
Action:

Ø

SBB D, S
D
[D] - [S] - [CF]

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.

Arithmetic Instructions

* Property of STI
Page 16 of 23

Computer Organization and Assembly Language

Example – SBB Instruction

Ø

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
are initially 0:

AX =

0015H

BP =

0002H

CS = 3000H

BX =

0019H

SP =

0035H

DS = 2000H

CX = 0012H

DI =

0017H

SS = 2000H

DX = 001BH

SI =

001EH ES = 4000H

MOV AX, 7AFAH
MOV BX, LIST
SUB AX, BX
SBB SI, DI
Arithmetic Instructions

* Property of STI
Page 17 of 23

Computer Organization and Assembly Language

The DEC Instruction

Ø

The DEC (Decrement) instruction subtracts
1 from the destination operand.
Format: DEC D
Action: D

Destination
register
MM

Arithmetic Instructions

[D] - 1

Example
DEC AX
DEC word ptr [BX]

* Property of STI
Page 18 of 23

Computer Organization and Assembly Language

Example – DEC Instruction
Ø

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
are initially 0:

AX =

0015H

BP =

0002H

CS = 3000H

BX =

0019H

SP =

0035H

DS = 2000H

CX = 0012H

DI =

0017H

SS = 2000H

DX = 001BH

SI =

001EH ES = 4000H

DEC AX
DEC BX
DEC CX
DEC DX
Arithmetic Instructions

* Property of STI
Page 19 of 23

Computer Organization and Assembly Language

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
Example:
MOV AL, 34H
MOV BL, 19H
SUB AL, BL
DAS

Arithmetic Instructions

* Property of STI
Page 20 of 23

Computer Organization and Assembly Language

Example – DAS Instruction

Ø

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 that all flags
are initially 0:

AX =

0015H

BP =

0002H

CS = 3000H

BX =

0019H

SP =

0035H

DS = 2000H

CX = 0012H

DI =

0017H

SS = 2000H

DX = 001BH

SI =

001EH ES = 4000H

MOV AL, 3FH
MOV BL, 15H
SUB AL, BL
DAS
Arithmetic Instructions

* Property of STI
Page 21 of 23

Computer Organization and Assembly Language

The AAS Instruction

Ø

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

Format: AAS
Example:
MOV AL, 39H;
MOV BL, 34H;
SUB AL, BL
AAS

Arithmetic Instructions

ASCII value of 9
ASCII value of 4

* Property of STI
Page 22 of 23

Computer Organization and Assembly Language

Example – AAS Instruction
Ø

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 that all flags
are initially 0:

AX =

0015H

BP =

0002H

CS = 3000H

BX =

0019H

SP =

0035H

DS = 2000H

CX = 0012H

DI =

0017H

SS = 2000H

DX = 001BH

SI =

001EH ES = 4000H

MOV AL, 8EH
MOV BL, 62H
SUB AL, BL
AAS
Arithmetic Instructions

* Property of STI
Page 23 of 23