"C" Instructions

AC - Instruções


CALL - Call Procedure

See also: RET, JMP, PROC, NEAR, FAR, EA

Flags not altered

CALL procedure_name

Logic:
if FAR CALL (inter-segment) then
	PUSH CS
	CS = dest_seg
	PUSH IP
	IP = dest_offset

CALL transfers control to a procedure that can either be within the current segment (a NEAR procedure) or outside it (a FAR procedure). The two types of CALLs result in different machine instructions, and the RET instruction that exits from the procedure must match the type of the CALL instruction (the potential for mismatch exists if the procedure and the CALL are assembled separately).

Operands Clocks
byte(word)
Transfers Bytes Example
near-proc 19(23) 1 3 CALL NEAR_PROC
far-proc 28(36) 2 5 CALL FAR_PROC
memptr 16 21(29)+EA 2 2-4 CALL PROC_TABLE[SI]
regptr 16 16(24) 1 2 CALL AX
memptr 32 37(57)+EA 4 2-4 CALL [BX], ROUTINE

Note: For an inter-segment procedure (procedure in a different segment), the processor first pushes the current value of CS onto the stack, then pushes the current value of IP (which is pointing to the instruction following the CALL instruction), then transfers control to the procedure.
For an intra-segment procedure (procedure in the same segment), the processor first pushes the current value of IP (which is pointing to the instruction following the CALL instruction) onto the stack, then transfers control to the procedure.
CALL can also read the procedure address from a register or memory location. This form of CALL is called an indirect CALL.

Norton Guide - ÍndiceÍndice


CBW - Convert Byte to Word

See also: CWD, DIV, IDIV

Flags not altered

CBW

Logic:
if (AL < 80h) then
	AH = 0
else
	AH = FFh

CBW extends the sign bit of the AL register into the AH register. This instruction extends a signed byte value into the equivalent signed word value.

Operands Clocks Transfers Bytes Example
no operands 2 - 1 CBW

Note: This instruction will set AH to 0FFh if the sign bit (bit 7) of AL is set; if bit 7 of AL is not set, AH will be set to 0. The instruction is useful for generating a word from a byte prior to performing byte division.

Norton Guide - ÍndiceÍndice


CLC - Clear Carry Flag

See also: STC, CMC, STD, CLD, STI, CLI, Flags

O D I T S Z A P C
                0

CLC

Logic:
CF = 0

CLC clears (sets to 0) the Carry Flag. No other flags are affected.

Operands Clocks Transfers Bytes Example
no operands 2 - 1 CLC

Norton Guide - ÍndiceÍndice


CLD - Clear Direction Flag

See also: STD, STC, CLC, CMC, STI, CLI, Flags

O D I T S Z A P C
  0              

CLD

Logic:
DF = 0
(Increment in string instructions)

CLD zeros the Direction Flag. No other flags are affected. Clearing the direction flag causes string operations to increment SI and DI.

Operands Clocks Transfers Bytes Example
no operands 2 - 1 CLD

Note: String instructions increment SI and DI when the direction flag is clear.

Norton Guide - ÍndiceÍndice


CLI - Clear Interrupt-Enable Flag

See also: STI, STC, CLC, CMC, STD, CLD, Flags

O D I T S Z A P C
    0            

CLI

Logic:
IF = 0

CLI clears the Interrupt Enable Flag, suppressing processor recognition of maskable interrupts. No other flags are affected. (Non-maskable interrupts are recognized no matter what the state of the interrupt enable flag.)

Operands Clocks Transfers Bytes Example
no operands 2 - 1 CLI

Norton Guide - ÍndiceÍndice


CMC - Complement Carry Flag

See also: STC, CLC, STD, CLD, STI, CLI, Flags

O D I T S Z A P C
                *

CMC

Logic:
CF = CF

CMC reverses the current state of the Carry Flag.

Operands Clocks Transfers Bytes Example
no operands 2 - 1 CMC

Norton Guide - ÍndiceÍndice


CMP - Compare

See also: CMPS, SCAS, EA, Flags

O D I T S Z A P C
*       * * * * *

CMP destination, source

Logic:

Flags set according to result of (destination - source)

CMP compares two numbers by subtracting the source from the destination and updates the flags. CMP does not change the source or destination. The operands may be bytes or words.

Operands Clocks
byte(word)
Transfers Bytes Example
register, register 3 - 2 CMP CX, BX
register, immediate 4 - 3-4 CMP BL, 02h
accumulator, immediate 4 - 2-3 CMP AL, 00010110b
register, memory 9(13)+EA 1 2-4 CMP DH, ALPHA_BETA
memory, register 9(13)+EA 1 2-4 CMP TOTAL, SI
memory, immediate 10(14)+EA 1 3-6 CMP VALUES, 3420h

Norton Guide - ÍndiceÍndice


CMPS - Compare String (Byte or Word)

See also: CMP, CMPSB, CMPSW, SCAS, REP, CLD, STD, Flags

O D I T S Z A P C
*       * * * * *

CMPS destination-string, source-string

Logic:
CMP (DS:SI),(ES:DI) ; Sets flags only
if DF = 0
	SI = SI + n	; n = 1 for byte, 2 for word
	DI = DI + n
else
	SI = SI - n
	DI = DI - n

This instruction compares two values by subtracting the byte or word pointed to by ES:DI, from the byte or word pointed to by DS:SI, and sets the flags according to the results of the comparison. The operands themselves are not altered. After the comparison, SI and DI are incremented (if the direction flag is cleared) or decremented (if the direction flag is set), in preparation for comparing the next element of the string.

Operands Clocks
byte(word)
Transfers Bytes Example
dest, source 22(30) 2 1 CMPS STR1, STR2
(repeat) dest, source 9+22(30)/rep 2/rep 1 REPE CMPS STR1, STR2

Note: This instruction is always translated by the assembler into either CMPSB, Compare String Byte, or CMPSW, Compare String Word, depending upon whether source refers to a string of bytes or words. In either case, you must explicitly load the SI and DI registers with the offset of the source and destination strings.

Example:

Upon exit from the REPE CMPS loop, the Zero Flag will be cleared if a mismatch was found, and set otherwise. If a mismatch was found, DI and SI will be pointing one byte past the byte that didn't match; the DEC DI and DEC SI backup these registers so they point to the mismatched characters.

; Assuming the definition:
buffer1 db 100 dup (?)
buffer2 db 100 dup (?)
; The following example compares BUFFER1 against BUFFER2 for the first mismatch.
cld				;Scan in the forward direction
mov cx, 100			;Scanning 100 bytes (CX is used by REPE)
lea si, buffer1			;Starting address of first buffer
lea di, buffer2			;Starting address of second buffer
repe	cmps buffer1, buffer2	;and compare it.
jne mismatch			;The Zero Flag will be cleared if there
				;is a mismatch
match:		.		;If we get here, buffers match
		.
mismatch:
	dec si			;If we get here, we found a mismatch.
	dec di			;Back up SI and DI so they point to
		.		;the first mismatch
		.

Norton Guide - ÍndiceÍndice


CMPSB - Compare String Byte

See also: CMP, CMPS, CMPSW, SCAS, REP, CLD, STD, Flags

O D I T S Z A P C
*       * * * * *

CMPSB

Logic:
CMP (DS:SI), (ES:DI) 	; Sets flags only
if DF = 0
	SI = SI + 1
	DI = DI + 1
else
	SI = SI - 1
	DI = DI - 1

This instruction compares two values by subtracting the byte pointed to by ES:DI, from the byte pointed to by DS:SI, and sets the flags according to the results of the comparison. The operands themselves are not altered. After the comparison, SI and DI are incremented (if the direction flag is cleared) or decremented (if the direction flag is set), in preparation for comparing the next element of the string.

Operands Clocks Transfers Bytes Example
- 22 2 1 CMPSB
(repeat) 9+22/rep 2/rep 1 REPE CMPSB
Example:

The following example compares BUFFER1 against BUFFER2 for the first mismatch.
Upon exit from the REPE CMPSB loop, the Zero Flag will be cleared if a mismatch was found, and set otherwise. If a mismatch was found, DI and SI will be pointing one byte past the byte that didn't match; the DEC DI and DEC SI instructions backup these registers so they point to the mismatched characters.

cld				;Scan in the forward direction
mov cx, 100			;Scanning 100 bytes (CX is used by REPE)
lea si, buffer1			;Starting address of first buffer
lea di, buffer2			;Starting address of second buffer
repe
	cmpsb			;...and compare it.
	jne mismatch		;The Zero Flag will be cleared if there
				;is a mismatch
match:		.		;If we get here, buffers match
		.
mismatch:
	dec si			;If we get here, we found a mismatch.
	dec di			;Back up SI and DI so they point to the
		.		;first mismatch

Norton Guide - ÍndiceÍndice


CMPSW - Compare String Word

See Also: CMP, CMPS, CMPSB, SCAS, REP, CLD, STD, Flags

O D I T S Z A P C
*       * * * * *

CMPSW

Logic:
CMP (DS:SI), (ES:DI)	; Sets flags only
if DF = 0
	SI = SI + 2
	DI = DI + 2
else
	SI = SI - 2
	DI = DI - 2

This instruction compares two numbers by subtracting the word pointedto by ES:DI, from the word pointed to by DS:SI, and sets the flags according to the results of the comparison. The operands themselves are not altered. After the comparison, SI and DI are incremented (if the direction flag is cleared) or decremented (if the direction flagis set), in preparation for comparing the next element of the string.

Operands Clocks Transfers Bytes Example
- 30 21 CMPSW  
(repeat) 9 + 30/rep 2/rep 1 REPE CMPSW
Example:

The following example compares BUFFER1 against BUFFER2 for the first mismatch.
Upon exit from the REPE CMPSW loop, the Zero Flag will be cleared if a mismatch was found, and set otherwise. If a mismatch was found, DI and SI will be pointing one word (two bytes) past the word that didn't match; the DEC DI and DEC SI pairs backup these registers so they point to the mismatched characters.

cld			;Scan in the forward direction
mov cx, 50		;Scanning 50 words (100 bytes)
lea si, buffer1		;Starting address of first buffer
lea di, buffer2		;Starting address of second buffer
repe	cmps		;...and compare it.
	jne mismatch	;The Zero Flag will be cleared if there
			;is a mismatch
match:
		.	;If we get here, buffers match
		.
mismatch:
	dec si		;If we get here, we found a mismatch.
	dec si		;Back up DI and SI so they point to the
	dec di		;…first mismatch
	dec di

Norton Guide - ÍndiceÍndice


CWD - Convert Word to Doubleword

See Also: CBW, DIV, IDIV

Flags not altered

CWD

Logic:
if (AX < 8000h) then
	DX = 0
else
	DX = FFFFh

CWD extends the sign bit of the AX register into the DX register. This instruction generates the double-word equivalent of the signed number in the AX register.

Norton Guide - ÍndiceÍndice


Última actualização: 02 Maio 2005

Norton Guide - Índice