Chapter 4.1 Flashcards
What is a data transfer instruction?
Instruction that copies data from a source operand to a destination operand
What is an operand?
A value that is used for input or output for an instruction
What types of operands can assembly language instructions have?
- Register
- Memory operand
- Integer expression
- Input–output port
What is an immediate operand?
A constant integer (8, 16, or 32 bits) encoded within the instruction
What is a register operand?
The name of a register that specifies a processor register as the source or destination of an operation
What is a memory operand?
Reference to a location in memory, specified using an address
What is the syntax of the MOV instruction?
MOV destination, source
What is a direct memory operand?
A named reference to storage in memory that is automatically dereferenced by the assembler
What are the restrictions on operands for the MOV instruction?
- No more than one memory operand permitted
- Both operands must be the same size
- CS, EIP, and IP cannot be the destination operand
- No immediate to segment moves
Why is the MOV instruction ‘mov ds, 45’ invalid?
DS register is a read-only control register managed by the processor
What does the MOVZX instruction do?
Fills the upper half of the destination with zeros when copying a smaller value into a larger destination
What does the MOVSX instruction do?
Fills the upper half of the destination with a copy of the source operand’s sign bit
What are the rules for operands in the XCHG instruction?
- At least one operand must be a register
- No immediate operands are permitted
What happens when using ‘mov al, arrayB+1’?
AL = 20h, where a constant offset is added to a data label to produce an effective address
What is an effective address (EA)?
An address produced by adding a constant offset to a data label
What must the destination be for a MOV instruction?
A register
Fill in the blank: The MOV instruction copies data from a _______ to a destination operand.
source operand
True or False: The MOV instruction can have more than one memory operand.
False
What does the instruction ‘mov ax, num2’ do?
AX is loaded with the word value stored in num2
What is the result of ‘mov al, num1’ where num1 is a byte?
AL will hold the value of num1
What is the purpose of the STC instruction?
Sets the Carry flag, indicating that an overflow occurred
What happens if you try to copy a smaller operand to a larger one directly?
MOV cannot directly copy data from a smaller operand to a larger one
What is the result of ‘mov eax, 0FFFFFFFFh’?
EAX is filled with the value 4294967295d
What occurs when ‘mov ax, [arrayW+2]’ is executed?
AX will be loaded with 2000h
True or False: The operand types in assembly language instructions can include immediate values.
True
What is a DWORD?
A DWORD is a data type that consists of 32 bits or 4 bytes.
What does the CY (Carry Flag) indicate?
It indicates whether an arithmetic operation produced a carry or borrow.
What does the PE (Parity Flag) indicate?
It indicates whether the result of an operation has an even or odd number of 1 bits.
What is the function of the ZR (Zero Flag)?
It indicates whether the result of an operation is zero.
What does the PL (Sign Flag) indicate?
It indicates whether the result of an operation is negative.
What does the OV (Overflow Flag) indicate?
It indicates whether the result of an operation has exceeded the maximum or minimum value that can be represented in the destination operand.
What does the AC (Auxiliary Carry Flag) indicate?
It indicates whether a carry was generated from bit 3 to bit 4 during an arithmetic operation.
What is the role of the UP (Direction Flag)?
It controls the direction of string operations (incrementing or decrementing).
What do the INC and DEC instructions do?
INC adds 1 to the destination operand, and DEC subtracts 1 from the destination operand.
What does the NEG instruction do?
The NEG instruction reverses the sign of a number by converting it to its two’s complement.
Fill in the blank: The _______ flag indicates that an operation produced zero.
Zero Flag
What is the significance of the Carry flag (CF)?
CF = 1 when the sum exceeds the storage size of its destination operand.
What is the purpose of the Overflow flag (OF)?
It is set when the result of a signed arithmetic operation overflows or underflows the destination operand.
True or False: The MOV instruction affects CPU status flags.
False
What happens when two positive operands are added and their sum is negative?
The Overflow flag is set.
What happens when two negative operands are added and their sum is positive?
The Overflow flag is set.
What is the OFFSET operator used for?
It is used to get the memory address of a variable.
What is the SIZEOF operator used for?
It is used to determine the size of a data type or a variable.
What does the LENGTHOF operator return?
It returns the length of an array or a string.
What is the purpose of the TYPE operator?
It is used to determine the data type of a variable.
What does the PTR operator specify?
It specifies the type of pointer to be used.
What are the essential flags affected by arithmetic operations?
- Zero flag
- Sign flag
- Carry flag
- Overflow flag
What is the result of the instruction ‘add al, 1’ when AL = 0?
AL becomes 1.
Fill in the blank: The _______ flag is set when a carry occurs from bit 3 to bit 4.
Auxiliary Carry Flag
What is the effect of the INC instruction on the Carry flag?
The INC instruction does not affect the Carry flag.
What is the result of adding 1 to the largest possible integer signed byte value?
It causes the value to become negative.
What does the Parity flag (PF) indicate?
It is set when the destination has an even number of 1 bits.
What happens to the Overflow flag when the result of an operation is valid?
The Overflow flag is cleared.
What is the result of ‘mov al, 80h; add al, 92h’ regarding the Overflow flag?
The Overflow flag is set (OF = 1).
What happens when the instruction ‘sub cx, 1’ is executed with CX = 0?
CX becomes -1, and the Sign flag is set.
What does the OFFSET operator do?
Returns the address of a variable in memory.
What is the value of OFFSET bVal if the data segment starts at 00404000h?
404000
What is the size of a DWORD?
32 bits = 4 bytes.
How does the TYPE operator function?
Returns the size, in bytes, of a single element of a data declaration.
What is the result of the TYPE operator for a byte?
1
What is the LENGTHOF operator used for?
Counts the number of elements in a single data declaration (array).
What does the SIZEOF operator calculate?
Returns a value equivalent to multiplying LENGTHOF by TYPE.
What is Little Endian order?
A method of storing multi-byte integers with the least significant byte at the lowest address.
True or False: In Little Endian order, the most significant byte is stored first.
False
What does the PTR operator do?
Overrides the default type of a label and provides access to part of a variable.
What is an indirect operand?
A 32-bit general-purpose register used to hold the address of a variable.
What happens when you dereference an indirect operand?
You access the value stored at the address held by the register.
What is the purpose of using the PTR operator with indirect operands?
To clarify the size attribute of a memory operand.
What is the result of the command ‘mov ax, WORD PTR [esi]’?
Moves a word-sized value from the address in ESI to AX.
How do you scale an index for an array element?
Multiply the index by the array’s TYPE.
What does the JMP instruction do?
Transfers control to a different memory address unconditionally.
What is the LOOP instruction used for?
To repeat a block of code a specified number of times.
Fill in the blank: The SIZEOF operator returns a value that is equivalent to multiplying LENGTHOF by _______.
TYPE
What is the difference between LENGTHOF and SIZEOF when dealing with multi-line data declarations?
LENGTHOF counts the elements, SIZEOF calculates the total size.
What is the size returned by the TYPE operator for a doubleword?
4
What is the significance of using the ‘OFFSET’ directive in assembly language?
It provides the memory address of a variable for indirect addressing.
What is the result of the command ‘mov eax, DWORD PTR myBytes’ if myBytes contains 12h, 34h, 56h, 78h?
EAX = 78563412h
What does the command ‘add esi, TYPE arrayW’ do?
Increments ESI by the size of the array elements.
What does a pointer variable represent?
The address of another variable.
True or False: An indirect operand can only hold addresses of byte-sized variables.
False
What is the value of LENGTHOF for an array declared as ‘array1 WORD 30 DUP(?)’?
30
What does the JMP instruction do?
Transfers control to a new location unconditionally.
The address is loaded into the instruction pointer (EIP) and execution continues at that address.
What is the syntax for the JMP instruction?
JMP target
‘target’ is the label to which control is transferred.
What is the purpose of the LOOP instruction?
Repeats a block of statements a specific number of times using ECX as a counter.
ECX is decremented each time the loop repeats.
What is the syntax for the LOOP instruction?
LOOP target
‘target’ is the label to which control jumps if ECX is not zero.
How does the LOOP instruction affect ECX?
ECX is decremented by 1 each time the loop executes.
If ECX reaches 0, the loop terminates.
In the context of loops, what does ‘relative offset’ refer to?
The distance in bytes between the offset of the following instruction and the target label’s offset.
This offset is added to EIP for execution.
What happens to the final value of EAX in the example of summing integers 5 + 4 + 3 + 2 + 1?
EAX = 15
This is the result of adding the integers in the loop.
How many times will the inner loop execute in the nested loop example with ECX set to 20?
20 times
The outer loop executes 100 times while the inner loop executes 20 times for each outer loop iteration.
What is the data type change needed when summing a doubleword array instead of a word array?
Change the data type to DWORD.
This ensures that the program correctly handles the size of the integers being summed.
What is the MOV instruction used for in 64-bit programming?
Transfers data from a source to a destination.
The MOV instruction can handle 8, 16, 32, or 64-bit operands.
What happens to the upper bits of a 64-bit register when a 32-bit value is moved into it?
The upper bits are cleared (set to zero).
For example, moving 0FFFFFFFFh into RAX results in 00000000FFFFFFFF.
What does the MOVSXD instruction do?
Sign extends a 32-bit value into a 64-bit destination register.
This is useful for preserving the sign of the value when moving it to a larger register.
What does the OFFSET operator generate?
A 64-bit address.
This address can be used to reference variables in memory.
What registers does the LOOP instruction use in 64-bit mode?
The RCX register as a counter.
This is consistent with the behavior of the LOOP instruction in 32-bit mode.
True or False: The ADD, SUB, INC, and DEC instructions affect CPU status flags differently in 64-bit mode compared to 32-bit mode.
False
They affect the CPU status flags in the same way in both modes.