Chap 4 - Basic Concepts

¡Supera tus tareas y exámenes ahora con Quizwiz!

Carry flag

Indicates carrying out or borrowing into the leftmost bit position following an arithmetic operation; also modified by some of the shift and rotate operations.

direct memory operands

Variable names are references to offsets within the data segment. For example, the following declaration for a variable named var1 says that its size attribute is byte and it contains the value 10 hexadecimal: .data var1 BYTE 10h

direct-offset operands

You can add a displacement to the name of a variable, creating a direct-offset operand. This lets you access memory locations that may not have explicit labels. Let's begin with an array of bytes named arrayB: arrayB BYTE 10h,20h,30h,40h,50h ; Direct-Offset Addressing (byte array): mov al,arrayB ; AL = 10h mov al,[arrayB+1] ; AL = 20h mov al,[arrayB+2] ; AL = 30h arrayW WORD 100h,200h,300h ; Direct-Offset Addressing (word array): mov ax,arrayW ; AX = 100h mov ax,[arrayW+2] ; AX = 200h arrayD DWORD 10000h,20000h ; Direct-Offset Addressing (doubleword array): mov eax,arrayD ; EAX = 10000h mov eax,[arrayD+4] ; EAX = 20000h mov eax,[arrayD+4] ;EAX = 20000h

indexed

An indexed operand adds a constant to a register to generate an effective address. Any of the 32-bit general-purpose registers may be used as index registers. There are different notational forms permitted by MASM (the brackets are part of the notation): constant[reg] [constant + reg] The first notational form combines the name of a variable with a register. The variable name is translated by the assembler into a constant that represents the variable's offset. Here are examples that show both notational forms: arrayB[esi] [arrayB + esi] arrayD[ebx] [arrayD + ebx] Indexed operands are ideally suited to array processing. The index register should be initialized to zero before accessing the first array element: .data arrayB BYTE 10h,20h,30h .code mov esi,0 mov al,arrayB[esi] ; AL = 10h

indirect

An indirect operand can be any 32-bit general-purpose register (EAX, EBX, ECX, EDX, ESI, EDI, EBP, and ESP) surrounded by brackets. The register is assumed to contain the address of some data. In the next example, ESI contains the offset of byteVal. The MOV instruction uses the indirect operand as the source, the offset in ESI is dereferenced, and a byte is moved to AL: .data byteVal BYTE 10h .code mov esi,OFFSET byteVal mov al,[esi] ; AL = 10h If the destination operand uses indirect addressing, a new value is placed in memory at the location pointed to by the register. In the following example, the contents of the BL register are copied to the memory location addressed by ESI. mov [esi],bl

ADD

The ADD instruction adds a source operand to a destination operand of the same size. The Carry, Zero, Sign, Overflow, Auxiliary Carry, and Parity flags are changed according to the value that is placed in the destination operand.

JMP

The JMP instruction causes an unconditional transfer to a destination, identified by a code label that is translated by the assembler into an offset.

LENGTHOF

The LENGTHOF operator returns the number of elements in an array.

LOOP

The LOOP instruction, formally known as Loop According to ECX Counter, repeats a block of statements a specific number of times. ECX is automatically used as a counter and is decremented each time the loop repeats.

MOV - data transfer from source to destination

The MOV instruction copies data from a source operand to a destination operand. Known as a data transfer instruction, it is used in virtually every program. Its basic format shows that the first operand is the destination and the second operand is the source: MOV destination,source

MOVSX

The MOVSX instruction (move with sign-extend) copies the contents of a source operand into a destination operand and sign-extends the value to 16 or 32 bits. This instruction is only used with signed integers. There are three variants: MOVSX reg32,reg/mem8 MOVSX reg32,reg/mem16 MOVSX reg16,reg/mem8

MOVZX

The MOVZX instruction (move with zero-extend) copies the contents of a source operand into a destination operand and zero-extends the value to 16 or 32 bits. This instruction is only used with unsigned integers. There are three variants: MOVZX reg32,reg/mem8 MOVZX reg32,reg/mem16 MOVZX reg16,reg/mem8 .data byteVal BYTE 10001111b .code movzx ax,byteVal ; AX = 0000000010001111b mov bx,0A69Bh movzx eax,bx ; EAX = 0000A69Bh movzx edx,bl ; EDX = 0000009Bh movzx cx,bl ; CX = 009Bh

NEG

The NEG (negate) instruction reverses the sign of a number by converting the number to its two's complement. The Carry, Zero, Sign, Overflow, Auxiliary Carry, and Parity flags are changed according to the value that is placed in the destination operand.

OFFSET

The OFFSET operator returns the offset of a data label. The offset represents the distance, in bytes, of the label from the beginning of the data segment. .data bVal BYTE ? wVal WORD ? dVal DWORD ? dVal2 DWORD ? If bVal were located at offset 00404000 (hexadecimal), the OFFSET operator would return the following values: mov esi,OFFSET bVal ; ESI = 00404000h mov esi,OFFSET wVal ; ESI = 00404001h mov esi,OFFSET dVal ; ESI = 00404003h mov esi,OFFSET dVal2 ; ESI = 00404007h

Overflow flags

The Overflow flag indicates signed integer overflow. For example, if an instruction has a 16-bit destination operand but it generates a negative result smaller than decimal, the Overflow flag is set.

PTR

The PTR operator lets you override an operand's default size. Suppose, for example, that you would like to move the lower 16 bits of a doubleword variable named myDouble into AX. The assembler will not permit the following move because the operand sizes do not match: .data myDouble DWORD 12345678h .code mov ax,myDouble ; error But the WORD PTR operator makes it possible to move the low-order word (5678h) to AX: mov ax,WORD PTR myDouble

SIZEOF

The SIZEOF operator returns the number of bytes used by an array initializer. The SIZEOF operator returns a value that is equivalent to multiplying LENGTHOF by TYPE.

SUB

The SUB instruction subtracts a source operand from a destination operand. The set of possible operands is the same as for the ADD and MOV instructions. The Carry, Zero, Sign, Overflow, Auxiliary Carry, and Parity flags are changed according to the value that is placed in the destination operand.

Sign flag

The Sign flag indicates that an operation produced a negative result. If the most significant bit (MSB) of the destination operand is set, the Sign flag is set.

TYPE

The TYPE operator returns the size, in bytes, of a single element of a variable. For example, the TYPE of a byte equals 1, the TYPE of a word equals 2, the TYPE of a doubleword is 4, and the TYPE of a quadword is 8.

TYPEDEF

The TYPEDEF operator lets you create a user-defined type that has all the status of a built-in type when defining variables. TYPEDEF is ideal for creating pointer variables. For example, the following declaration creates a new data type PBYTE that is a pointer to bytes: PBYTE TYPEDEF PTR BYTE

XCHG

The XCHG (exchange data) instruction exchanges the contents of two operands. There are three variants: XCHG reg,reg XCHG reg,mem XCHG mem,reg

Zero flag

The Zero flag indicates that an operation produced zero. For example, if an operand is subtracted from another of equal value, the Zero flag is set.

INC

add 1 from a register or memory operand. The Overflow, Sign, Zero, Auxiliary Carry, and Parity flags are changed according to the value of the destination operand. The INC and DEC instructions do not affect the Carry flag (which is something of a surprise).

DEC

subtract 1 from a register or memory operand. The Overflow, Sign, Zero, Auxiliary Carry, and Parity flags are changed according to the value of the destination operand. The INC and DEC instructions do not affect the Carry flag (which is something of a surprise).


Conjuntos de estudio relacionados

Music 13personalizing the Conversation: Beethoven and the Classical Sonata

View Set

17. Local and humoral control of tissue blood flow

View Set

Citi Trainings: Research Involving Human Subjects (RCR-Basic)

View Set