CPSC 240 CH 8 - 13 SECTION Review Questions

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

(True/False): Linking OBJ modules is much faster than assembling ASM source files.

true

(True/False): Macro expansion is handled by the assembler's preprocessor.

true

(True/False): Passing by reference means that an argument's address is stored on the runtime stack.

true

(True/False): Replacing a long procedure with a macro containing the procedure's code will typically increase the compiled code size of a program if the macro is invoked multiple times.

true

(True/False): The 32-bit Str_compare procedure does not need to use ESI and EDI to access memory.

true

(True/False): The CALL instruction cannot include procedure arguments.

true

(True/False): The PROC directive can contain a USES operator, but the PROTO directive cannot.

true

(True/False): Win32 console input functions can detect when the user has resized the console window.

true

What are the two common types of stack parameters?

value and reference

In the Factorial function, what condition terminates the recursion?

when n = 0

(True/False): The Str_compare procedure stops when the null terminator of the longer string is reached.

False - stops when null terminator of shorter string is reached

Segment selector

a 16-bit value stored in a segment register (CS, DS, SS, ES, FS, or GS).

(True/False): A segment descriptor does not contain segment size information.

false

What is the linker command that specifies that the target program is for the Win32 console?

/SUBSYSTEM:CONSOLE

Suppose a two-dimensional array of doublewords has three logical rows and four logical columns. If ESI is used as the row index, what value is added to ESI to move from one row to the next?

16

In the IEEE double-precision format, how many bits are reserved for the fractional part of the significand?

52 bits

In the IEEE single-precision format, how many bits are reserved for the exponent?

8 bits

What value does the expression SIZEOF MyStruct return?

82

What value does the expression TYPE MyStruct return?

82

Show at least two ways of placing comments in inline assembly code.

; initialize index register // initialize index register /* initialize index register */

How does a Microsoft Visual C++ function return a short int?

A short int is returned in the AX register.

Describe the HeapAlloc function.

Allocates a block of memory from a heap

Write the statements generated by the following macro: FOR val, <100, 20, 30> BYTE 0, 0, 0, val ENDM

BYTE 0, 0, 0, 100 BYTE 0, 0, 0, 20 BYTE 0, 0, 0, 30

Why doesn't the single-precision real format permit an exponent of +128?

Because adding +128 to the exponent bias (127) would generate a negative value.

Why doesn't the single-precision real format permit an exponent of -127?

Because the reciprocal of -127 is +127, which would generate an overflow.

When the second letter of a floating-point instruction is B, what type of operand is indicated?

Binary coded decimal

Name at least three FPU special-purpose registers.

Choose from opcode, control, status, tag word, last instruction pointer, last data pointer.

How do C++ functions usually return floating-point values?

Floating-point values are usually pushed on the processor's floating-point stack before returning from the function.

What is another term for heap allocation, in the context of C, C++, and Java?

Dynamic memory allocation

In reference to string primitives, which 32-bit register is known as the accumulator?

EAX

Which index register is used by the STOSD instruction?

EDI

Which directive stops all further expansion of a macro?

EXITM

Which looping directive would be the best tool to generate a character lookup table?

FORC

(True/False): PROTO directives use up memory, so you must be careful not to include a PROTO directive for a procedure unless the procedure is actually called.

False - PROTO directives are ignored by the assembler if the corresponding procedure is not called

Show a sample call to the HeapCreate function.

HEAP_START = 2000000 ; 2 MB HEAP_MAX = 400000000 ; 400 MB .data hHeap HANDLE ? ; handle to heap .code INVOKE HeapCreate, 0, HEAP_START, HEAP_MAX

What is the purpose of the IFB directive?

IFB directive used to check for blank macro parameters

What is the purpose of the IFDEF directive?

IFDEF returns true if a symbol has already been defined.

What is the purpose of the IFIDN directive?

IFIDN directive compares two text values and returns true if they are identical. performs a case-sensitive comparison.

How is IFIDNI different from IFIDN?

IFIDNI is the case-insensitive version of IFIDN

How is inline assembly code different from an inline C++ procedure?

Inline assembly code is assembly language source code that is inserted directly into high-level language programs. The inline qualifier in C++, on the other hand, asks the C++ compiler to insert the body of a function directly into the program's compiled code

Which instruction copies data from the memory location addressed by ESI into AX?

LODSW

What is the primary advantage to using macros with parameters versus macros without them?

Macros with parameters can be reused more easily.

In the BubbleSort procedure, does the inner loop always execute the same number of times?

No it decreases by 1 each

Will an assembly language procedure that uses the STDCALL language specifier link to a C++ program?

No, because the procedure name will not be found by the linker.

In 32-bit mode, should you use EBP to address an array?

No. EBP should be reserved as a base pointer for the current procedure's stack frame

Which floating-point instructions accept immediate operands?

None

When calling HeapDestroy, how do you identify the memory block being destroyed?

Pass a pointer to the memory block (along with the heap handle).

If ST(0) is positioned at absolute register R6 in the register stack, what is the position of ST(2)?

R0

What does the REPZ prefix do for a CMPSB instruction?

Repeat while ZF = 1

Which instructions in the assembly language Factorial procedure execute after each recursive call has finished?

ReturnFact: mov ebx, [ebp+8] mul ebx L2: pop ebp ret 4

Describe the GetProcessHeap function.

Returns a 32-bit integer handle to the program's existing heap area in EAX.

Which instruction compares a 32-bit integer in the accumulator to the contents of memory, pointed to by EDI?

SCASD

If it were found (through testing) that an array of 500 integers could be sorted in 0.5 seconds, how many seconds would it take to bubble sort an array of 5000 integers?

T(5000) = 0.5 * 10^2 seconds

(True/False): A segment selector is 32 bits.

false

Write an expression that returns the number of bytes in field2 of MyStruct.

TYPE MyStruct.field2 (or: SIZEOF Mystruct.field2)

Briefly describe the FOR directive.

The FOR directive repeats a statement block by iterating over a list of symbols.

Briefly describe the FORC directive.

The FORC directive repeats a statement block by iterating over a string of characters.

In what way is the calling convention used by the Irvine32 library not compatible with the calling convention used by the C and C++ languages?

The Irvine32 library uses STDCALL, which is not the same as the C calling convention used by C and C++. The important difference is in how the stack is cleaned up after a function call.

Briefly describe the REPEAT directive.

The REPEAT directive repeats a statement block based on the value of a counter.

Briefly describe the WHILE directive.

The WHILE directive repeats a statement block based on a boolean expression.

Challenge: How many bytes of stack space would be used by the Factorial procedure when calculating 5! ?

The amount of stack space required for n! is (n + 1) x 12

What would happen to the Factorial program's output if you tried to calculate 13! ?

The calculated value would exceed the range of unsigned DWORD and would roll past zero. Output would appear smaller than 12 factorial.

Which two C++ keywords must be included in a function definition if the function will be called from an assembly language module?

The extern and "C" keywords must be used.

Which memory models are available in real-address mode?

Tiny, small, compact, medium, large, huge

(True/False): As long as it is in the code segment, a macro definition may appear either before or after statements that invoke the macro.

false

(True/False): Given the same task to accomplish, a recursive subroutine usually uses less memory than a nonrecursive one.

false

(Yes/No): Can an inline statement refer to code labels outside the __asm block?

Yes

In a WNDCLASS structure, what is the meaning of the style field?

a combination of different style options, such as WS_CAPTION and WS_BORDER, that control a window's appearance and behavior.

In a WNDCLASS structure, what is the meaning of the lpfnWndProc field?

a pointer to a function in an application program that receives and processes event messages triggered by the user.

Write the code generated by the preprocessor when the mRepeat macro is expanded by each of the following statements (a, b, and c): mRepeat 'X' , 50 ; a mRepeat AL, 20 ; b mRepeat byteVal, countVal ; c

a. mov cx,50 ??0000: mov ah,2 mov dl,'X' int 21h loop ??0000 b. mov cx,20 ??0001: mov ah,2 mov dl,AL int 21h loop ??0001 c. mov cx,countVal ??0002: mov ah,2 mov dl,byteVal int 21h loop ??0002

In 32-bit mode, which registers can be used in a base-index operand?

any 32-bit general purpose register

Declare a variable as an array of 20 MyStruct objects.

array MyStruct 20 DUP(<>)

Logical address

combination of a segment selector and a 32-bit offset.

Describe a POINT structure.

contains two fields, ptX and ptY, that describe the X- and Y-coordinates (in pixels) of a point on the screen.

How is the WNDCLASS structure used?

defines a window class. Each window in a program must belong to a class, and each program must define a window class for its main window. This class is registered with the operating system before the main window can be shown.

(True/False): A macro cannot contain data definitions.

false

(True/False): Local variables are created by adding a positive value to the stack pointer.

false

(True/False): Separating a large program into short modules makes a program more difficult to maintain.

false

(True/False): The 32-bit Str_length procedure uses SCASB to find the null terminator at the end of the string.

false

(True/False): The INVOKE directive can include up to a maximum of three arguments.

false

(True/False): The INVOKE directive can only pass memory operands, but not register values.

false

(True/False): The ReadConsole function reads mouse information from the input buffer.

false

(True/False): The Str_copy procedure prevents a string from being copied into too small a memory area.

false

(True/False): Unicode is the native character set for Windows 98.

false

(True/False): When a macro is invoked, the CALL and RET instructions are automatically inserted into the assembled program.

false

Write an instruction that loads a duplicate of ST(0) onto the FPU stack.

fld st(0)

In a WNDCLASS structure, what is the meaning of the hInstance field?

holds a handle to the current program instance. Each program running under MS-Windows is automatically assigned a handle by the operating system when the program is loaded into memory.

Using the MyStruct array from the preceding exercise, move field1 of the first array element to AX.

mov ax, array.field1

Using the MyStruct array from the preceding exercise, use ESI to index to the third array element and move AX to field1. Hint: Use the PTR operator.

mov esi, OFFSET array add esi, 3 * (TYPE myStruct) mov (myStruct PTR[esi]).field1.ax

If an array were already in sequential order, how many times would the outer loop of the BubbleSort procedure in Section 9.5.1 execute?

n - 1 times

In the BubbleSort procedure, how many times does the inner loop execute on the first pass through the array?

n - 1 times

Multitasking

permits multiple programs (or tasks) to run at the same time. The processor divides up its time between all of the running programs.

Segmentation

provides a way to isolate memory segments from each other. This permits multiple programs to run simultaneously without interfering with each other.

What is meant by the naming convention used by a language?

refers to the rules or characteristics regarding the naming of variables and procedures.

What advantage does inline assembly code offer over the use of external assembly language procedures?

simplicity and it executes more quickly

Declare a MyStruct variable with default values.

temp1 MyStruct <>

Declare a MyStruct variable that initializes the first field to zero.

temp2 MyStruct <0>

Declare a MyStruct variable and initialize the second field to an array containing all zeros.

temp3 MyStruct <, 20 DUP (0)>

(True/False): A function ending with the letter W (such as WriteConsoleW) is designed to work with a wide (16-bit) character set such as Unicode.

true

(True/False): A segment descriptor contains the base location of a segment.

true

(True/False): A segment selector points to an entry in a segment descriptor table.

true

(True/False): A subroutine's prologue code always pushes EBP on the stack.

true

(True/False): A subroutine's stack frame always contains the caller's return address and the subroutine's local variables.

true

(True/False): Arrays are passed by reference to avoid copying them onto the stack.

true

(True/False): In 32-bit mode, the last argument to be pushed on the stack in a subroutine call is stored at location EBP + 8.

true

(True/False): In a multimodule program, an END statement with a label occurs only once, in the startup module.

true


संबंधित स्टडी सेट्स

CFA_L1_Assignment_179_Lesson 1: Introduction, the Benefits of Securitization and the Securitization Process

View Set

Key Concepts of Critical Thinking

View Set

Chapter 8: The Structure of Semantic Memory (Terms)

View Set

Science- Chemical and Physical Changes

View Set

Principles of Business Semester 1 Final Exam True/False

View Set