COMSC 260 Quiz 8

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

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

*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? D-) mov [arr+SIZEOF arr - (SIZEOF arr -2)], 99 *B-) mov [arr+SIZEOF arr - (SIZEOF arr -1)], 99 * C-) mov [arr+SIZEOF arr - SIZEOF arr -2], 99 A-) mov [arr+SIZEOF arr - SIZEOF arr -1], 99

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

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* D-) 1. -128 2. +128 C-) 1. -127 2. +127 A-) 1. -127 2. +128

*B-)* *1. -128* *2. +127*

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: B-) mov al, TYPE val1 *C-) mov al, SIZEOF val1* A-) mov al, BYTE PTR val1 D-) mov al, LENGTHOF val1

*C-) mov al, SIZEOF val1*

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

A-) .data arr WORD 99, 51, 73 WORD 23, 47, 61 WORD 17, 89, 93 .code mov eax, SIZEOF arr mov ebx, LENGTHOF arr

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

C-) *1. False* *2. False*

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

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 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. ------------------------------- D-) mov ecx, DIGITS jmp L2 L1: mov outer_loop, ecx mov ecx, DIGITS 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 ------------------------------- 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 ------------------------------- A-) 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 L2: inc BYTE PTR [pair+1] inc num_of_pairs loop L2 mov ecx, outer_loop loop L1 ------------------------------- C-) mov ecx, DIGITS jmp L2 L1: mov outer_loop, ecx mov ecx, DIGITS mov ah, '0' mov al, BYTE PTR pair inc al mov pair, ax L2: inc BYTE PTR [pair+1] inc num_of_pairs loop L2 mov ecx, outer_loop loop L1

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 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+1], al mov al, [arr+LENGTHOF arr-1] mov [arr+2], al mov [arr+LENGTHOF arr-2], 0 mov [arr+LENGTHOF arr-1], 0 ----------------------------- 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 ----------------------------- C-) 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 ----------------------------- B-) 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], 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 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. C-) mov esi, OFFSET [target - 2] mov edi, OFFSET [source + SIZEOF source + 1] Correct! D-) mov esi, OFFSET [target - 2] mov edi, OFFSET [source + SIZEOF source] B-) mov esi, OFFSET [target - 1] mov edi, OFFSET [source + SIZEOF source] A-) mov esi, OFFSET [target - 1] mov edi, OFFSET [source + SIZEOF source + 1]

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


Conjuntos de estudio relacionados

Pharmacology Exam 1 Fall 2023 Mtech

View Set

Life & Health Comprehensive Exam

View Set

¿Qué hicieron? Práctica (Practice)

View Set

History of ideas AFRICAN-AMERICAN IDEAS. and MORE

View Set

CHAPTER 21 - Northern Renaissance

View Set

TEST 4: Chapter 26 Mastering (Fundamentals of Nursing)

View Set

Banking & the Fed Test Review Questions (Mr. Fortner)

View Set

Chapter 45: Management of Patients With Oral and Esophageal Disorders

View Set