Sunteți pe pagina 1din 17
Computer Organization and Assembly Language

Computer Organization and Assembly Language

The NEG Instruction

ÿ

The NEG (Negate) instruction converts the specified operand to its 2’s complement equivalent and the result returned to the operand location. This is, in effect, reversing the sign of an integer.

Format: NEG D Action: D 0 - [D] Destination Example register NEG AX MM NEG
Format:
NEG D
Action:
D
0 - [D]
Destination
Example
register
NEG AX
MM NEG byte ptr [BX]
Computer Organization and Assembly Language

Computer Organization and Assembly Language

Example – NEG Instruction

ÿ

Determine the value of AL and the value of the flags (assume all flags are initially 0) following the instruction sequence:

MOV AL, 05H NEG AL
MOV AL, 05H
NEG AL
Computer Organization and Assembly Language

Computer Organization and Assembly Language

The CMP Instruction

ÿ

The CMP (Compare) instruction subtracts the source operand from the destination operand. It then discards the result but it updates the values of all the status flags.

Format: Action: CMP D, S [D] - [S] Destination Source Example register register CMP BX,
Format:
Action:
CMP D, S
[D] - [S]
Destination
Source
Example
register
register
CMP BX, CX
register
MM
CMP CX, BETA
MM register
CMP BETA, DX
register
immediate
CMP SI, ABCDH
MM immediate
CMP byte ptr [BX], 34H
Computer Organization and Assembly Language

Computer Organization and Assembly Language

Example – CMP 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
AX
=
0015H
BP =
0002H
CS =
3000H
BX
=
0019H
SP =
0035H
DS =
2000H
CX
=
0012H
DI =
0017H
SS =
2000H
DX
=
001BH
SI =
001EH
ES =
4000H

CMP AX, BX CMP [SI], DI

Computer Organization and Assembly Language

Computer Organization and Assembly Language

Program Tracing Example 1

Trace the following program. Assume the following: all flags and registers (unless specified otherwise) are initially zero, DS = 2000H, SS = 2001H, the label ALPHA = 001CH. Use the memory map (if necessary).

the label ALPHA = 001CH. Use the memory map (if necessary). MOV AX, ALPHA MOV SP,

MOV AX, ALPHA MOV SP, AX POP BX ADD BX, AX SUB BX, 9F79H XCHG BX, BP MOV CX, [BP] SBB AX, CX ADC AX, 0029H ADD AL, CL DAA NEG AX LEA SI, ALPHA MOV DX, [SI]

Computer Organization and Assembly Language

Computer Organization and Assembly Language

The AND Instruction

ÿ

The AND (Logical AND) instruction logically ANDs the source and the destination operands and stores the result in the destination operand.

Format: Action: AND D, S D [D] [S] Destination Source Example register register AND BX,
Format:
Action:
AND D, S
D
[D] [S]
Destination
Source
Example
register
register
AND BX, CX
register
MM
AND DX, [BP + SI]
MM register
AND BETA, CX
register
immediate
AND BX, 0015H
MM Immediate
AND byte ptr BETA, 12H
Computer Organization and Assembly Language

Computer Organization and Assembly Language

Example – AND Instruction

ÿ

Determine the value of affected registers and the value of the flags (assume all flags are initially 0) following the instruction sequence:

MOV AL, 05H MOV BL, FEH AND AL, BL
MOV AL, 05H
MOV BL, FEH
AND AL, BL
Computer Organization and Assembly Language

Computer Organization and Assembly Language

The OR Instruction

ÿ

The OR (Logical OR) instruction logically ORs the source and the destination operands and stores the result in the destination operand.

Format: Action: OR D, S D [D] + [S] Destination Source Example register register OR
Format:
Action:
OR D, S
D
[D] + [S]
Destination
Source
Example
register
register
OR BX, CX
register
MM
OR DX, [BP + SI]
MM register
OR BETA, CX
register
immediate
OR BX, 0015H
MM immediate
OR byte ptr BETA, 12H
Computer Organization and Assembly Language

Computer Organization and Assembly Language

Example – OR Instruction

ÿ

Determine the value of affected registers and the value of the flags (assume all flags are initially 0) following the instruction sequence:

MOV CL, 05H MOV DL, 80H OR CL, DL
MOV CL, 05H
MOV DL, 80H
OR CL, DL
Computer Organization and Assembly Language

Computer Organization and Assembly Language

The XOR Instruction

ÿ

The XOR (Logical XOR) instruction logically XORs the source and the destination operands and stores the result in the destination operand.

Format: Action: XOR D, S D [D] [S] Destination Source Example register register XOR BX,
Format:
Action:
XOR D, S
D
[D] [S]
Destination
Source
Example
register
register
XOR BX, CX
register
MM
XOR DX, [BP + SI]
MM register
XOR BETA, CX
register
immediate
XOR BX, 0015H
MM immediate
XOR byte ptr BETA, 12H
Computer Organization and Assembly Language

Computer Organization and Assembly Language

Example – XOR Instruction

ÿ

Determine the value of affected registers and the value of the flags (assume all flags are initially 0) following the instruction sequence:

MOV AL, 15H MOV BL, ABH XOR AL, BL
MOV AL, 15H
MOV BL, ABH
XOR AL, BL
Computer Organization and Assembly Language

Computer Organization and Assembly Language

The NOT Instruction

ÿ The NOT (Logical NOT) instruction performs a 1’s complement on the operand.

Format: NOT D Action: D [D]’ Destination Example register NOT AX MM NOT byte ptr
Format:
NOT D
Action:
D
[D]’
Destination
Example
register
NOT AX
MM NOT byte ptr BETA
Computer Organization and Assembly Language

Computer Organization and Assembly Language

Example – NOT Instruction

ÿ

Perform the following operation. Each instruction is dependent on one another. Assume that all flags are initially 0:

MOV BX, D32BH MOV CX, 1056LH NOT BX NOT CH
MOV BX, D32BH
MOV CX, 1056LH
NOT BX
NOT CH
Computer Organization and Assembly Language

Computer Organization and Assembly Language

The TEST Instruction

ÿ

The TEST instruction logically ANDs the source and the destination operands. The result is discarded but the values of the status flags are updated.

Format: Action: TEST D, S [D] [S]
Format:
Action:
TEST D, S
[D] [S]
Computer Organization and Assembly Language

Computer Organization and Assembly Language

Example – NOT Instruction

ÿ

Perform the following operation. Each instruction is dependent on one another. Assume that all flags are initially 0:

MOV SI, 2376H MOV DI, 1941H TEST SI, DI
MOV SI, 2376H
MOV DI, 1941H
TEST SI, DI
Computer Organization and Assembly Language

Computer Organization and Assembly Language

Logic Instruction Program Tracing Example

ÿ

Trace the following program. Assume the following: all flags and registers (unless specified otherwise) are initially zero, DS = 2000H, SS = 2001H, the label ALPHA = 001CH. Use the memory map (if necessary).

the label ALPHA = 001CH. Use the memory map (if necessary). MOV BX, ALPHA MOV SP,

MOV BX, ALPHA MOV SP, BX NEG BX AND BX, [AX] OR BX, 0020H CMP BX, SP MOV CX, [SP] TEST BX, CX NOT AX XOR AL, CL

Computer Organization and Assembly Language

Computer Organization and Assembly Language

Program Tracing Exercise 1

ÿ

Trace the following program. Assume the following: all flags and registers (unless specified otherwise) are initially zero, DS = 2000H, SS = 2001H, the label ALPHA = 001CH. Use the memory map (if necessary).

the label ALPHA = 001CH. Use the memory map (if necessary). MOV AL, 23H MOV CH,

MOV AL, 23H MOV CH, 6BH XOR AL, 0CH ADD AL, 77H NEG BX AND CH, 33H XOR CH, AAH TEST CH, AL DEC AX OR CH, AL SUB AX, CX