COMSC 260 Exam #2 Questions (Quizzes 6-8)

Ace your homework & exams now with Quizwiz!

Suppose the top of the runtime stack is currently memory address 0000000A (i.e., this address is stored in ESP). Then suppose the following instruction is executed: pop ax What will be the new memory address that is at the top of the stack (i.e., the new address stored in ESP)?

0000000C

X WORD 1A2Bh, 3C4Dh, 5E6Fh How is X stored in memory?

0000: 2B 0001: 1A 0002: 4D 0003: 3C 0004: 6F 0005: 5E

1. An indexed operand stores the address of a variable from the data segment. 2. If we are using ESI as an indexed operand, then we can dereference ESI with [ESI].

1. False 2. False

Suppose we have the following program: MEMORY (RAM) Address Value (instruction) 0000 0000 Mov ax, 0 0000 0003 Mov ecx, 5 0000 0007 L1: add ax, cx 0000 0009 Loop L1 0000 000B Invoke exitProcess, 0 1. When the loop instruction is executed, if the jump to L1 is NOT taken then the address in EIP will be 0000 0007. 2. In the memory diagram shown above, the loop L1 instruction takes up two (2) bytes of memory.

1. False 2. True

Suppose a program is supposed to be able to add two polynomials together. For each polynomial array, the values in the array represent the coefficients in the polynomial. The first value in the polynomial array always has exponent 0, the second value in the polynomial array always has exponent 1, the third value in the polynomial array always has exponent 2, etc. So the exponents do not need to be directly stored in the array -- only the coefficients are directly stored in the array. It is also known that the number of terms in polyB is greater than or equal to the number of terms in polyA. Since the exponents start at 0 with each term in the array, this means that if LENGTHOF Poly A == LENGTHOF PolyB, then all of the exponents will be the same in both polynomials (i.e., all terms will be like terms). But if LENGTHOF PolyA < LENGTHOF PolyB, then there will be one or more exponents that only occur in PolyB that do not occur in PolyA. PolyA and PolyB are the two "input" polynomials -- these are the two polynomials that will be added together. When two polynomials are added together, for each exponent that occurs in both of the two polynomials, the coefficients of that term are added together. So if one polynomial has the term 2X^3 and the other polynomial has the term 7X^3, then the sum of these two terms will be 9X^3. PolyC is the "output" polynomial -- when the program is finished, it should store the sum of PolyA and PolyB. The program must work correctly for ANY values for PolyA and PolyB, but here is a sample data segment that can be used for the program. PolyA DWORD 1, 2, 3, 4, 5 //polynomial is 1 + 2X + 3X^2 + 4X^3 + 5X^4 PolyB DWORD 1, 2, 3, 4, 5, 6, 7, 8 //polynomial is 1 + 2X + 3X^2 + 4X^3 + 5X^4 + 6X^5 + 7X^6 + 8X^7 PolyC DWORD LENGTHOF polyB DUP (?) // this polynomial will be // 2 + 4X + 6X^2 + 8X^3 + 10X^4 + 6X^5 + 7X^6 + 8X^7 // Both polynomials have exponents 0, 1, 2, 3, and 4 (like terms) // But only PolyB has the exponents 5, 6, and 7 (NOT like terms) .code 1 ____________________mov esi, 0 jmp L2 L1:mov eax, [polyA+esi]add eax, [polyB+esi]mov [polyC+esi], eaxadd esi, 4L2:Loop L1 2 ____________________ jmp L4 L3:mov eax, [polyB+esi]mov [polyC+esi], eaxadd esi, 4L4:Loop L3 Question: Which of the options below contains the correct code to insert at lines 1 and 2 in the code shown above? HINT: Remember, the code must work correctly for ALL possible cases, including LENGTHOF Poly A == LENGTHOF PolyB AND LENGTHOF PolyA < LENGTHOF PolyB.

1. mov ecx, LENGTHOF polyA+1 2. mov ecx, LENGTHOF polyB - LENGTHOF polyA + 1

var1 BYTE 7 dup("COMSC 260") How many bytes is var1?

63

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, SIZEOF arr mov ebx, LENGTHOF arr

What is the logic behind the loop instruction?

A-) 1. ECX = ECX - 1 2. if ECX != 0, jump to target

Which of the options below will store the number of elements in arr in the arrsize variable?

A-) arr BYTE 'A', 'B', 'C', 'D', 'E' arrsize = $ - arr

.data arr1 BYTE 'A', 'B', 'C', 'D' arr2 BYTE 'W', 'X', 'Y', 'Z' .code main proc mov al, arr1 mov bl, [arr2+3] mov arr1, bl mov [arr2+3], al mov al, [arr1+1] mov bl, [arr2+2] mov [arr1+1], bl mov [arr2+2], al mov al, [arr1+2] mov bl, [arr2+1] mov [arr1+2], bl mov [arr2+1], al mov al, [arr1+3] mov bl, arr2 mov [arr1+3], bl mov arr2, al What will be stored in arr1 and arr2 after this program finishes?

A-) arr1 = ['Z', 'Y', 'X', 'W'] arr2 = ['D', 'C', 'B', 'A']

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 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

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

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+2] mov array, ax mov ax, [array+4] xchg ax, [array+6] mov [array+4], ax

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

All of the options below will cause an infinite loop* EXCEPT: Here "infinite loop" means either a loop that literally never ends, or a loop that does eventually end but has many, many..... many more iterations than it normally should have (e.g., billions of loop iterations).

A-) mov ecx, 0 L1: mov eax, ecx inc ecx loop L1

.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 0005

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 eax, DWORD PTR [arrB+2]

All of the options below will cause an infinite loop EXCEPT:

A-) mov ecx, 0 L1: mov eax, ecx inc ecx loop L1

The relative offset used for jumping in a loop instruction is encoded by a single byte. What is the largest possible backward jump? What is the largest possible forward jump?

B-) 1. -128 2. +127

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)

B-) 1. FFFF8321h 2. 00007654h

1. OFFSET returns the distance in bytes, of a label from the beginning of its enclosing segment. 2. In real-address mode, the address returned by OFFSET is 32 bits.

B-) 1. True 2. False

Suppose a program has the following array declared in the data segment: array WORD 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?

B-) mov ax, array xchg ax, [array+8] mov array, ax mov ax, [array+2] xchg ax, [array+6] mov [array+2], ax

Suppose a program is supposed to write to memory letter/digit pairs, where the letter comes first and the digit comes second. Each pairing of a capital letter (A - Z) and a digit (0 - 9) should be written to memory in the following order: A0, A1, ...., A9, B0, B1, .... B9, ...., Y0, Y1, .... Y9, Z0, Z1, .... Z9* In addition, the total number of pairings should be stored in num_of_pairs. *Remember if you were to actually run this in visual studio, you would see the ASCII codes in memory itself, and the characters ('A', '0', etc.) off to the side The start of this program is as follows: LETTERS = 26 DIGITS = 10 .data outer_loop DWORD ? pair WORD ? num_of_pairs DWORD ? .code main proc mov outer_loop, LETTERS mov ah, '0' mov al, 'A' mov pair, ax mov num_of_pairs, 1 Which of the options below is the correct continuation of this program? NOTE: inc is the increment instruction -- it increments the value of it's operand by one.

B-) mov ecx, DIGITS-1 jmp L2 L1: mov outer_loop, ecx mov ecx, DIGITS-1 mov ah, '0' mov al, BYTE PTR pair inc al mov pair, ax inc num_of_pairs L2: inc BYTE PTR [pair+1] inc num_of_pairs loop L2 mov ecx, outer_loop loop L1

Suppose a program starts with the following instructions: mov eax, 0 mov ah, 11111111b The first instruction clears eax, and the second instruction moves the 8-bit binary number 11111111 into ah. From here, the program is supposed to shift the number 11111111 from ah to the highest byte of eax. How many add eax, eax instructions are needed to do this?

B-) 16

When a loop instruction is encountered, and the jump is taken, which register is affected by the jump?

B-) EIP

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?

B-) mov [arr+SIZEOF arr - (SIZEOF arr -1)], 99

Suppose a program has the following data segment: .data valA BYTE 1h valB BYTE 2h, 3h, 4h, 5h Which of the following mov instructions will store 4h in register al?

B-) mov al, [valA+3]

.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)

C-) 1. 12 2. 2

1. LENGTHOF is equivalent to SIZEOF * TYPE 2. LENGTHOF returns the number of bytes in a data declaration.

C-) 1. False 2. False

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?

C-) L1: mov ax, array[esi] xchg ax, array[esi+2] mov array[esi], ax add esi, 4 loop L1

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?

C-) L1: mov ax, array[esi] xchg ax, array[esi+2] mov array[esi], ax add esi, 4 loop L1

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.

C-) array1 WORD 1, 2, 3, 4, 5 array1Bytes = ($ - array1) array2 WORD 6, 7, 8, 9, 10 array2Bytes = ($ - array2)

mov al, 11111111b movsx bx, al Which of the options below is equivalent to the code shown above?

C-) mov al, 11111111b mov bl, al add bl, bl (8 times total) mov bl, al

.data valW WORD 1234h, 5678h .code mov al, BYTE PTR [valw+3] What value is stored in al?

C-) 56h

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:

C-) mov al, SIZEOF val1

1. PTR can be used to combine elements of a smaller data type and move them into a larger operand. 2. PTR can be used to access part of a variable.

D-) 1. True 2. True

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?

D-) 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

Suppose a program has the following data segment: .data arr1 BYTE 1, 2 arr2 BYTE 3, 4 And the goal is to swap arr1 and arr2 such that: arr1 = [4, 3] and arr2 = [2, 1] Which of the options below is the correct implementation of the program?

D-) mov al, arr1 mov bl, [arr2+1] mov arr1, bl mov [arr2+1], al mov al, [arr1+1] mov bl, arr2 mov [arr1+1], bl mov arr2, al

Which of the options below meets BOTH of the following criteria: The loop is a pretest This means the condition for the loop is checked BEFORE executing the body of the loop. The body of the loop (i.e., add eax, eax) is executed exactly five times.

D-) mov eax, 0 mov ecx, 6 jmp L2 L1: add eax, eax L2: loop L1

Which of the options below meets BOTH of the following criteria: The loop is a pretest loop. This means the condition for the loop is checked BEFORE executing the body of the loop. The body of the loop (i.e., add eax, eax) is executed exactly five times.

D-) mov eax, 0 mov ecx, 6 jmp L2 L1: add eax, eax L2: loop L1

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?

D-) mov eax, OFFSET source + SIZEOF source -3 mov ebx, OFFSET target - 3

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 = 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?

D-) 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

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?

D-) 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

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). NOTE: inc is the increment instruction -- it increments the value of it's operand by one. Likewise dec is the decrement instruction -- it decrements the value of it's operand by one.

D-) mov esi, OFFSET [target - 2] mov edi, OFFSET [source + SIZEOF source]

Suppose a program has the following memory layout: Relative Address Value 0000 'A' (ASCII code 41h) 0001 'B' (ASCII code 42h) 0002 'C' (ASCII code 43h) 0003 'D' (ASCII code 44h) 0004 'E' (ASCII code 45h) 0005 'F' (ASCII code 46h) 0006 'G' (ASCII code 47h) 0007 'H' (ASCII code 48h) All of the following data segments would result in this memory layout EXCEPT:

D-) someval WORD 4241h, 4443h someval2 DWORD 45464748h

Suppose a program has the following memory layout: Relative Address Value 0000 'A' (ASCII code 41h) 0001 'B' (ASCII code 42h) 0002 'C' (ASCII code 43h) 0003 'D' (ASCII code 44h) 0004 'E' (ASCII code 45h) 0005 'F' (ASCII code 46h) 0006 'G' (ASCII code 47h) 0007 'H' (ASCII code 48h) All of the following data segments would result in this memory layout EXCEPT: Group of answer choices

D-) someval WORD 4241h, 4443h someval2 DWORD 45464748h

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?

D-) [1, 1, 2, 3, 1, 1]

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?

DIFFERENT IN EXAM 1 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

Which of the following options below is the correct way to end a string with the null terminator character?

Text BYTE "Hello World", 0

Which of the following options below represents a 16 bit unsigned integer?

WORD

All of the following are valid operand types for the push instruction EXCEPT:

imm 16

Which of the following options below is the correct way to do a line return (new line) in x86 assembly language?

line_return BYTE 0Dh, 0Ah

Which of the following options below will 1) Produce the largest sum (and store it in al) AND 2) NOT produce a carry out of the MSB (most significant bit)? HINT: How many bits are registers al and bl?

mov al, 254 mov bl, 1 add al, bl

Which of the following options below will produce a carry out of the MSB (most significant bit)?

mov al, 255 mov bl, 1 add al, bl

Which of the following options below will produce a carry out of the MSB (most significant bit)? HINT: How many bits are registers al and bl?

mov al, 255 mov bl, 1 add al, bl


Related study sets

Understanding Business Chapter 9 (77 terms)

View Set

NURS 125 MONDAY CLINICAL JUDGMENT

View Set

NCLEX Hurst Adult/Maternity/Psy/Priority/Child/Fundamental Questions

View Set

Repaso del desgaste, la erosión y la deposición

View Set