Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Assembly Language Step by Step Programming with DOS and Linux 2nd Ed 2000.pdf
Скачиваний:
156
Добавлен:
17.08.2013
Размер:
4.44 Mб
Скачать

PUSHF Push 16-Bit Flags onto Stack

Flags affected:

O

D

I

T

S

Z A P C

OF: Overflow flag TF: Trap flag AF: Aux carry

F

F

F

F

F

F F F F DF: Direction

flag SF: Sign

flag

PF: Parity flag

 

 

<none>

IF: Interrupt

flag ZF: Zero

flag

CF: Carry flag

Legal forms:

PUSHF <none>

Examples:

PUSHF

Notes:

PUSHF simply pushes the current contents of the Flags register onto the top of the stack. The top of the stack is defined as the word at SS:SP, and there is no way to override that with prefixes.

SP is decremented before the word goes onto the stack. Remember that SP always points to either an empty stack or else real data. There is a separate pair of instructions, PUSH and POP, for pushing and popping other register data and memory data.

The Flags register is not affected when you push the flags, but only when you pop them back with POPF.

PUSHF and POPF are most used in writing interrupt service routines, where you must be able to save and restore the environment, that is, all machine registers, to avoid disrupting machine operations while servicing the interrupt.

r8 = AL AH BL BH CL CH DL DH sr = CS DS SS ES FS GS

m8 = 8-bit memory data

m32 = 32-bit memory data

i16 = 16-bit immediate data

d8 = 8-bit signed displacement

d32 = 32-bit unsigned displacement

r16 = AX BX CX DX BP SP SI DI

r32 = EAX EBX ECX EDX EBP ESP ESI E m16 = 16-bit memory data

i8 = 8-bit immediate data

i32 = 32-bit immediate data

d16 = 16-bit signed displacement

PUSHFD Push 32-Bit EFlags onto Stack (386+)

Flags affected:

O

D

I

T

S

Z A P C

OF: Overflow flag TF: Trap flag AF: Aux carry

F

F

F

F

F

F F F F DF: Direction

flag SF: Sign

flag

PF: Parity flag

 

 

<none>

IF: Interrupt

flag ZF: Zero

flag

CF: Carry flag

Legal forms:

PUSHFD <none>

386+

Examples:

PUSHFD

Notes:

PUSHFD simply pushes the current contents of the 32-bit EFlags register onto the top of the stack. The top of the stack in 32-bit modes is defined as the word at [SS:ESP], and there is no way to override that with prefixes.

ESP is decremented before the EFlags double word goes onto the stack. Remember that ESP always points to either an empty stack or else real data. There is a separate pair of instructions, PUSH and POP, for pushing and popping other register data and memory data, and (in the 286 and later processors) immediate data.

The EFlags register is not affected when you push the flags, but only when you pop them back with POPFD.

PUSHFD and POPFD are most used in writing interrupt service routines, where you must be able to save and restore the environment, that is, all machine registers, to avoid disrupting machine operations while servicing the interrupt.

r8 = AL AH BL BH CL CH DL DH sr = CS DS SS ES FS GS

m8 = 8-bit memory data

m32 = 32-bit memory data

i16 = 16-bit immediate data

d8 = 8-bit signed displacement

d32 = 32-bit unsigned displacement

r16 = AX BX CX DX BP SP SI DI

r32 = EAX EBX ECX EDX EBP ESP ESI E m16 = 16-bit memory data

i8 = 8-bit immediate data

i32 = 32-bit immediate data

d16 = 16-bit signed displacement

RET Return from Procedure

Flags affected:

O

D

I

T

S

Z A P C

OF: Overflow flag TF: Trap flag AF: Aux carry

F

F

F

F

F

F F F F DF: Direction

flag SF: Sign

flag

PF: Parity flag

 

 

<none>

IF: Interrupt

flag ZF: Zero

flag

CF: Carry flag

Legal forms:

RET

RETN

RETF

RET i8

RETN i8

RET i16

RETF i16

Examples:

RET

RET 12H

RETN

RETF 117H

Notes:

There are two kinds of returns: Near and Far, where Near is within the current code segment and Far is to some other code segment. Ordinarily, the RET form is used, and the assembler resolves it to a Near or Far return opcode to match the procedure definition's use of the NEAR or FAR specifier. Specifying RETF or RETN may be done when necessary.

RET may take an operand indicating how many bytes of stack space are to be released on returning from the procedure. This figure is subtracted from the stack pointer to erase data items that had been pushed onto the stack for the procedure's use immediately prior to the procedure call.

The RETF and RETN forms are not available in Microsoft's MASM prior to V5.0!

r8 = AL AH BL BH CL CH DL DH sr = CS DS SS ES FS GS

m8 = 8-bit memory data

m32 = 32-bit memory data

i16 = 16-bit immediate data

d8 = 8-bit signed displacement

d32 = 32-bit unsigned displacement

r16 = AX BX CX DX BP SP SI DI

r32 = EAX EBX ECX EDX EBP ESP ESI E m16 = 16-bit memory data

i8 = 8-bit immediate data

i32 = 32-bit immediate data

d16 = 16-bit signed displacement

ROL Rotate Left

Flags affected:

O D

I

T

S

Z

A

P

C

OF: Overflow flag TF: Trap flag AF: Aux carry

F

F

F

F

F

F

F

F

F

DF: Direction

flag SF: Sign

flag

PF: Parity flag

*

 

 

 

 

 

 

 

* IF: Interrupt

flag ZF: Zero

flag

CF: Carry flag

Legal forms:

ROL r8,1

 

ROL m8,1

 

ROL r16,1

 

ROL m16,1

386+

ROL r32,1

ROL m32,1

386+

ROL r8,CL

 

ROL m8,CL

 

ROL r16,CL

 

ROL m16,CL

386+

ROL r32,CL

ROL m32,CL

386+

ROL r8,i8

286+

ROL m8,i8

286+

ROL r16,i8

286+

ROL m16,i8

286+

ROL r32,i8

386+

ROL m32,i8

386+

Examples:

ROL AL,1

ROL WORD [BX+SI],CL

ROL BP,1

ROL DWORD [EBX+ESI],9

ROL BP,CL

Notes:

ROL rotates the bits within the destination operand to the left, where left is toward the most significant bit (MSB). A rotate is a shift (see SHL and SHR) that wraps around; the leftmost bit of the operand is shifted into the rightmost bit, and all intermediate bits are shifted one bit to the left. Except for the direction the shift operation takes, ROL is identical to ROR.

The number of bit positions shifted may be specified either as an 8-bit immediate value, or by the value in CL- not CX or ECX. (The 8086 and 8088 are limited to the immediate value 1.) Note that while CL may accept a value up to 255, it is meaningless to shift by any value larger than 16, even though the shifts are actually performed on the 8086 and 8088. (The 286 and later limit the number of shift operations performed to the native word size except when running in Virtual 86 mode.)

The leftmost bit is copied into the Carry flag on each shift operation. OF is modified only by the shift-by-one forms of ROL; after shift-by-CL forms, OF becomes undefined.

r8

= AL

AH

BL BH

CL

CH DL DH

r16

= AX BX CX DX

BP SP SI DI

sr = CS

DS SS ES

FS GS

r32

= EAX EBX ECX

EDX EBP ESP ESI E

m8

= 8-bit

memory data

m16

= 16-bit memory data

m32 = 32-bit memory

data

i8 = 8-bit immediate data

i16

= 16-bit

immediate data

i32

=

32-bit

immediate data

d8 = 8-bit signed displacement

d16

=

16-bit

signed displacement

d32

= 32-bit

unsigned displacement