Comsc 260 Test 2 Study Guide

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

.data var1 WORD 5 DUP(?), ABCDh What will be the value of edx after the following instructions (1) and (2) execute? mov edx, SIZEOF var1 ; (1) mov edx, TYPE var1 ; (2) A) 1. 12 2. 2 B) 1. 12 2. 4 C) 1. 6 2. 2 D) 1. 6 2. 4

A

.data wval LABEL WORD dval LABEL DWORD arrlist BYTE 00h, 01h, 02h, 03h .code mov ax, wval What is the value that is stored in ax? A) 0100h B) 0001h C) 0302h D) 0203h

A

1. LENGTHOF is equivalent to SIZEOF * TYPE 2. LENGTHOF returns the number of bytes in a data declaration. A) 1. False 2. False B) 1. True 2. True C) 1. True 2. False D) 1. False 2.True

A

Suppose a program has the following array in the data segment: arr BYTE 1, 2, 3, 4 And the goal is to remove the first and third elements in the array, and move the second and fourth elements up to the beginning of the array. Here an element will be "removed" by putting a 0 in it's place. After the program has finished running arr should be: [2, 4, 0, 0] Which of the options below is the correct implementation of the program? A) mov al, [arr+LENGTHOF arr-3] mov [arr], al mov al, [arr+LENGTHOF arr-1] mov [arr+1], al mov [arr+LENGTHOF arr-2], 0 mov [arr+LENGTHOF arr-1], 0 B) mov al, [arr+LENGTHOF arr-2] mov [arr], al mov al, [arr+LENGTHOF arr] mov [arr+1], al mov [arr+LENGTHOF arr-1], 0 mov [arr+LENGTHOF arr], 0 C) mov al, [arr+LENGTHOF arr-2] mov [arr+1], al mov al, [arr+LENGTHOF arr] mov [arr+2], al mov [arr+LENGTHOF arr-1], 0 mov [arr+LENGTHOF arr], 0 D) mov al, [arr+LENGTHOF arr-3] mov [arr+1], al mov al, [arr+LENGTHOF arr-1] mov [arr+2], al mov [arr+LENGTHOF arr-2], 0 mov [arr+LENGTHOF arr-1], 0

A

Suppose a program has the following data segment: arrB BYTE 1, 1, 1, 1, 1, 1 And then the following instructions are executed in the code segment: mov al, [arrB+1] add al, arrB mov [arrB+2], al mov al, [arrB+2] add al, [arrB+1] mov [arrB+3], al What does arrB look like after these instructions have executed? A) [1, 1, 2, 3, 1, 1] B) [1, 2, 3, 1, 1, 1] C) [1, 2, 2, 1, 1, 1] D) [1, 1, 2, 2, 1, 1]

A

Suppose a program is supposed to reverse an array. Part of the program is as follows: .data array DWORD 1,5,6,8,0Ah,1Bh,1Eh,22h,2Ah,32h .code mov edx, 0 L1: mov eax, array[edx] xchg eax, array[ebx] mov array[edx], eax add edx, TYPE array sub ebx, TYPE array loop L1 For this program to work correctly, ebx and ecx must both be initialized correctly. Which of the options below correctly initializes both registers? A) mov ebx, SIZEOF array - TYPE array mov ecx, LENGTHOF array / 2 B) mov ebx, SIZEOF array - TYPE array mov ecx, LENGTHOF array / 2 - 1 C) mov ebx, SIZEOF array - TYPE array - 4 mov ecx, LENGTHOF array / 2 - 1 D) mov ebx, SIZEOF array - TYPE array - 4 mov ecx, LENGTHOF array / 2

A

Suppose we have the following initial data segment: .data varA BYTE 1h varB BYTE 2h varC BYTE 3h And the goal is for varA to store 3h, varB to store 1h, and varC to store 2h. All of the options below will achieve this result EXCEPT: A) mov al, varA xchg al, varB xchg al, varC mov al, varA B) mov al, varA xchg varB, al xchg varC, al mov varA, al C) mov al, varA xchg al, varB xchg al, varC xchg al, varA D) mov al, varA mov bl, varB mov cl, varC xchg varB, al xchg varC, bl xchg varA, cl

A

What is the logic behind the loop instruction? A) 1. ECX = ECX - 1 2. if ECX != 0, jump to target B) 1. if ECX > 0, jump to target 2. ECX = ECX - 1 C) 1. ECX = ECX - 1 2. if ECX > 0, jump to target D) 1. if ECX != 0, jump to target 2. ECX = ECX - 1

A

Suppose a program has the string "COMSC 260" stored in source. The goal of the program is to store the reversed string, "062 CSMOC" in target. Part of the program is as follows: .data source BYTE "COMSC 260", 0 target BYTE SIZEOF source DUP(?) .code main PROC mov ecx,SIZEOF source-1 L1: mov al, [esi] mov [edi], al dec esi inc edi loop L1 mov BYTE PTR [edi], 0 For this program to work correctly, esi and edi must both be initialized correctly. Which of the options below correctly initializes both registers? NOTE: The source string ends with a null terminator (0). After the program finishes running, the target string will also end with a null terminator (0). A) mov esi, OFFSET [target - 1] mov edi, OFFSET [source + SIZEOF source + 1] B) mov esi, OFFSET [target - 1] mov edi, OFFSET [source + SIZEOF source] C) mov esi, OFFSET [target - 2] mov edi, OFFSET [source + SIZEOF source] D) mov esi, OFFSET [target - 2] mov edi, OFFSET [source + SIZEOF source + 1]

A?

How does the add instruction affect the carry flag (CF) and the overflow flag (OF)? NOTE: XOR = exclusive or MSB = most significant bit (high order bit) A) CF= carry into the MSB OF = CF XOR MSB B) CF = carry out of the MSB OF = CF XOR MSB C) CF = carry into the MSB OF = CF OR MSB D) CF = carry out of the MSB OF = CF OR MSB

B

Suppose a program has the following array declared in the data segment: array DWORD 99, 33, 77, 11, 22 And the program is supposed to reverse the array. After the program is finished, the array should be: [22, 11, 77, 33, 99] Which of the options below is the correct implementation of the program? A) mov ax, array xchg ax, [array+4] mov array, ax mov ax, [array+12] xchg ax, [array+16] mov [array+12], ax B) mov ax, array xchg ax, [array+16] mov array, ax mov ax, [array+4] xchg ax, [array+12] mov [array+4], ax C) mov ax, array xchg ax, [array+8] mov array, ax mov ax, [array+2] xchg ax, [array+6] mov [array+2], ax D) mov ax, array xchg ax, [array+2] mov array, ax mov ax, [array+6] xchg ax, [array+8] mov [array+6], ax

B

Suppose a program has the following array declared in the data segment: array WORD 1, 5, 7 The program is supposed to calculate the sum of the gaps in the array. A gap in an array is the distance between two adjacent elements in the array. For the array given above, the gaps are: 5 - 1 = 4 7 - 5 = 2 So the sum of the gaps is 4 + 2 = 6 Which of the options below is the correct implementation of the program? A) mov ax, 0 mov bx, array sub bx, [array+2] add ax, bx mov bx, [array+2] sub bx, [array+4] add ax, bx B) mov ax, 0 mov bx, [array+2] sub bx, array add ax, bx mov bx, [array+4] sub bx, [array+2] add ax, bx C) mov ax, 0 mov bx, array sub bx, [array+4] add ax, bx mov bx, [array+4] sub bx, [array+8] add ax, bx D) mov ax, 0 mov bx, [array+4] sub bx, array add ax, bx mov bx, [array+8] sub bx, [array+4] add ax, bx

B

Suppose a program has the following data segment: source BYTE "ASSEMBLY", 0 target BYTE LENGTHOF source dup('#') Which of the options below will move the address of the "L" into BOTH eax AND ebx? A) mov eax, OFFSET source + SIZEOF source -3 mov ebx, OFFSET target - 2 B) mov eax, OFFSET source + SIZEOF source -3 mov ebx, OFFSET target - 3 C) mov eax, OFFSET source + SIZEOF source -2 mov ebx, OFFSET target - 3 D) mov eax, OFFSET source + SIZEOF source -2 mov ebx, OFFSET target - 2

B

Suppose a program is supposed to swap adjacent pairs in an array that always has an even number of elements. For example the array [1, 2, 3, 4, 5, 6, 7, 8] would become [2, 1, 4, 3, 6, 5, 8, 7] The start of the program is as follows: .data array WORD 1,2,3,4,5,6,7,8,9,10 .code main PROC mov esi,0 mov ecx, LENGTHOF array / 2 Which of the options below is the correct continuation of the program? A) L1: mov ax, array[esi] xchg ax, array[esi+4] mov array[esi], ax add esi, 4 loop L1 B) L1: mov ax, array[esi] xchg ax, array[esi+2] mov array[esi], ax add esi, 4 loop L1 C) L1: mov ax, array[esi] xchg ax, array[esi+4] mov array[esi], ax add esi, 2 loop L1 D) L1: mov ax, array[esi] xchg ax, array[esi+2] mov array[esi], ax add esi, 2 loop L1

B

Suppose the following array is declared in the data segment: arrW WORD 1, 2, 3, 4 The goal of the program is to swap adjacent pairs in the array. When the program has finished, the array should be [2, 1, 4, 3]. Which of the options below is the correct implementation of the program? A) mov ax, array xchg ax, [array+4] mov array, ax mov ax, [array+2] xchg ax, [array+6] mov [array+2], ax B) mov ax, array xchg ax, [array+2] mov array, ax mov ax, [array+4] xchg ax, [array+6] mov [array+4], ax C) mov ax, array xchg ax, [array+4] mov array, ax mov ax, [array+8] xchg ax, [array+12] mov [array+8], ax D) mov ax, array xchg ax, [array+8] mov array, ax mov ax, [array+4] xchg ax, [array+12] mov [array+4], ax

B

Suppose the following is declared in the data segment: .data val1 WORD 2h, 1h All of the options below will move the number 2 into al EXCEPT: A) mov al, BYTE PTR val1 B) mov al, SIZEOF val1 C) mov al, TYPE val1 D) mov al, LENGTHOF val1

B

When a loop instruction is encountered, and the jump is taken, which register is affected by the jump? A) ESP B) EIP C) EBP D) ESI

B

Which of the options below will: 1) store 6 in eax 2) store 3 in ebx A) .data arr WORD 99, 51, 73 WORD 23, 47, 61 WORD 17, 89, 93 .code mov eax, LENGTHOF arr mov ebx, SIZEOF arr B) .data arr WORD 99, 51, 73 WORD 23, 47, 61 WORD 17, 89, 93 .code mov eax, SIZEOF arr mov ebx, LENGTHOF arr C) .data arr WORD 99, 51, 73 23, 47, 61 17, 89, 93 .code mov eax, LENGTHOF arr mov ebx, SIZEOF arr D) .data arr WORD 99, 51, 73 23, 47, 61 17, 89, 93 .code mov eax, SIZEOF arr mov ebx, LENGTHOF arr

B

All of the options below will cause an infinite loop EXCEPT: A) mov ecx, 0 L1: mov eax, ecx dec ecx loop L1 B) mov ecx, -1 L1: mov eax, ecx inc ecx loop L1 C) mov ecx, 0 L1: mov eax, ecx inc ecx loop L1 D) mov ecx, -1 L1: mov eax, ecx dec ecx loop L1

C

Suppose a program has the following data segment: .data arr BYTE 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 And the goal is to change second value in the array to 99. After the program has finished arr should be: [1, 99, 3, 4, 5, 6, 7, 8, 9, 10] Which of the options below is the correct implementation of the program? A) mov [arr+SIZEOF arr - SIZEOF arr -1], 99 B) mov [arr+SIZEOF arr - SIZEOF arr -2], 99 C) mov [arr+SIZEOF arr - (SIZEOF arr -1)], 99 D) mov [arr+SIZEOF arr - (SIZEOF arr -2)], 99

C

Suppose a program has the following memory layout: *Relative Address* 0000 0001 0002 0003 0004 0005 0006 0007 *Value* 'A' (ASCII code 41h) 'B' (ASCII code 42h) 'C' (ASCII code 43h) 'D' (ASCII code 44h) 'E' (ASCII code 45h) 'F' (ASCII code 46h) 'G' (ASCII code 47h) 'H' (ASCII code 48h) All of the following data segments would result in this memory layout EXCEPT: A) someval WORD 4241h, 4443h BYTE 45h, 46h, 47h, 48h B) Someval BYTE 41h, 42h WORD 4443h, 4645h, 4847h C) someval WORD 4241h, 4443h DWORD 45464748h D) someval DWORD 44434241h WORD 4645h, 4847h

C

Suppose a program is supposed to calculate the sum of the gaps in an array. For example, for the array [0, 2, 5, 9, 10], the sum of the gaps is 2+3+4+1 = 10. The start of this program is as follows: .data dwarray dword 0,2,5,9,10 count EQU (LENGTHOF dwarray) result dword ? .code mov ebx, 0 mov edx, 0 Which of the options below will correctly continue the program and store the sum of the gaps in the array in the result variable? A) mov ecx, count - 1 L1: mov eax, dwarray[ebx] sub eax, dwarray[ebx+4] add edx, eax add ebx, TYPE dwarray loop L1 mov result, edx B) mov ecx, count L1: mov eax, dwarray[ebx] sub eax, dwarray[ebx+4] add edx, eax add ebx, TYPE dwarray loop L1 mov result, edx C) mov ecx, count - 1 L1: mov eax, dwarray[ebx+4] sub eax, dwarray[ebx] add edx, eax add ebx, TYPE dwarray loop L1 mov result, edx D) mov ecx, count L1: mov eax, dwarray[ebx+4] sub eax, dwarray[ebx] add edx, eax add ebx, TYPE dwarray loop L1 mov result, edx

C

Suppose the following array is declared in the data segment: .data arr BYTE 1, 2, 3, 4 And the goal of the program is to swap the first half and second half of the array. After the program is finished, arr should be: [3, 4, 1, 2] Which of the options below is the correct implementation of the program? A) mov al, [arr+1] mov bl, [arr+LENGTHOF arr/2+1] mov [arr+1], bl mov [arr+LENGTHOF arr/2+1], al mov al, [arr+2] mov bl, [arr+LENGTHOF arr/2+2] mov [arr+2], bl mov [arr+LENGTHOF arr/2+2], al B) mov al, [arr+1] mov bl, [arr+LENGTHOF arr/2] mov [arr+1], bl mov [arr+LENGTHOF arr/2], al mov al, [arr+2] mov bl, [arr+LENGTHOF arr/2+1] mov [arr+2], bl mov [arr+LENGTHOF arr/2+1], al C) mov al, arr mov bl, [arr+LENGTHOF arr/2] mov arr, bl mov [arr+LENGTHOF arr/2], al mov al, [arr+1] mov bl, [arr+LENGTHOF arr/2+1] mov [arr+1], bl mov [arr+LENGTHOF arr/2+1], al D) mov al, arr mov bl, [arr+LENGTHOF arr/2-1] mov arr, bl mov [arr+LENGTHOF arr/2-1], al mov al, [arr+1] mov bl, [arr+LENGTHOF arr/2] mov [arr+1], bl mov [arr+LENGTHOF arr/2], al

C

The relative offset used for jumping in a loop instruction is encoded by a single byte. 1. What is the largest possible backward jump? 2. What is the largest possible forward jump? A) 1. -127 2. +128 B) 1. -127 2. +127 C) 1. -128 2. +127 D) 1. -128 2. +128

C

What will be the value in EAX after each of the lines marked (1) and (2) execute? .data var1 WORD 8321h var2 WORD 7654h .code mov eax, 12ABCDEFh movsx eax, var1 ; (1) movsx eax, var2 ; (2) A) 1. 12AB8321h 2. 12AB7654h B) 1. 00008321h 2. 00007654h C) 1. FFFF8321h 2. 00007654h D) 1. FFFF8321h 2. FFFF7654h

C

Which of the options below meets BOTH of the following criteria: 1. The loop is a pretest This means the condition for the loop is checked BEFORE executing the body of the loop. 2. The body of the loop (i.e., add eax, eax) is executed exactly five times. A) mov eax, 0 mov ecx, 5 jmp L2 L1: add eax, eax L2: loop L1 B) mov eax, 0 mov ecx, 6 jmp L1 L1: add eax, eax L2: loop L1 C) mov eax, 0 mov ecx, 6 jmp L2 L1: add eax, eax L2: loop L1 D) mov eax, 0 mov ecx, 5 jmp L1 L1: add eax, eax L2: loop L1

C

.data val1 BYTE ? val2 WORD ? val3 WORD ? val4 WORD ? Assuming the data segment starts at 0000 0000: mov esi, OFFSET val4 Which address would the above instruction move into esi? A) 0000 0006 B) 0000 0009 C) 0000 000A D) 0000 0005

D

A scale factor is typically used with which type of operand? An example of scaling is as follows: .data barr BYTE 1, 2, 3, 4, 5 warr WORD 1, 2, 3, 4, 5 darr DWORD 1, 2, 3, 4, 5 .code mov esi, 4 mov al, barr[esi*TYPE barr] mov bx, warr[esi*TYPE warr] move cx, darr[esi*TYPE darr] A) Indirect operand B) Direct-offset operand C) Direct-memory operand D) Indexed operand

D

Suppose a program has the following data segment: arrB BYTE 01h, 23h, 45h, 67h, 89, 0ABh, 0CDh, 0EFh Which of the following instructions below will move AB896745h into eax? A) mov ax, DWORD PTR [arrB+5] B) mov eax, DWORD PTR [arrB+6] C) mov eax, DWORD PTR [arrB+3] D) mov eax, DWORD PTR [arrB+2]

D

Which of the options below will correctly store the number of *bytes* of array1 in the array1Bytes constant, and the number of *bytes* of array2 in the array2Bytes constant? HINT: Remember that the number of *bytes* in an array is not necessarily the same as the number of elements in the array. A) array1 WORD 1, 2, 3, 4, 5 array2 WORD 6, 7, 8, 9, 10 array1Bytes = ($ - array1) array2Bytes = ($ - array2) B) array1 WORD 1, 2, 3, 4, 5 array1Bytes = ($ - array1)/2 array2 WORD 6, 7, 8, 9, 10 array2Bytes = ($ - array2)/2 C) array1 WORD 1, 2, 3, 4, 5 array2 WORD 6, 7, 8, 9, 10 array1Bytes = ($ - array1)/2 array2Bytes = ($ - array2)/2 D) array1 WORD 1, 2, 3, 4, 5 array1Bytes = ($ - array1) array2 WORD 6, 7, 8, 9, 10 array2Bytes = ($ - array2)

D


Ensembles d'études connexes

chapter 48 vehicle extrication and special rescue

View Set

Alterations in Nutrition Lecture #15

View Set