Assembly (Test 3)

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

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 + LENTHOF arr/2] mov arr, bl mov [arr + LENGTHOF arr/2], al mov al, [arr + 1] mov bl, [arr + LENGTHOFarr/2+1] mov [arr + 1], bl mov [arr + LENGTHOF arr/2 + 1], al

Suppose a program is supposed to write to memory letter/digital 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, ......, 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 chracters ('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 ah, 'A' mov pair, ax mov num_of_pairs, 1 Which of the options below is the correct continuation of this program?

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 [pairs + 1] inc num_of_pairs loop L2 mov ecx, outer_loop loop L1

Suppose the goal of the program is as follows: Set the parity (PF) to 1 ONLY if the original number in al has an even number of 1's , and otherwise set PF to 0 (it's OK if we change al's value, but we must set the flag correctly). All of the option below will correctly do this EXCEPT:

xor al, al

(Light Blue) main proc . . call (Light Blue) Which is the status of the runtime stack after sub3 has been called (but before sub3 has returned)?

Runtime main return address sub1 return address sub2 return address (arrow ESP)

Suppose the following SIGNED values are compared: mov al, -2 mov al, -5 What are the values of SF (sing flag) and OF (overflow flag)?

SF = 0 OF = 0

For which of the options below swill the jump to the label EvenNumber be taken only when the number in al is even?

and al, 00000001b jz EvenNumber

(the ASCII code) Given the ASCII code table shown above, suppose that we move the DEL character into register al. Which of the options below would convert the DEL character in al to the Space character?

and al, 0A0h

For which of the options below will the jump to L1 only be taken when the number in al is negative?

and al, 10000000b jnz L1

For which of the options below will the jump to OddParity be taken only when the parity of the number in al is odd?

and al, al jnp OddParity

For which of the options below will the jump to Setbits be taken only when bits 0, 1, and 2 are all set for the number in bl?* *The jump to Setbits should only be taken if bits 0, 1, and 2 all have the value 1 in bl.

and bl, 00000111b cmp bl, 00000111b jz Setbits

if (AX <= BX) TEMP = 43; else TEMP = 19; Which of the options below is equivalent to the code shown above?

cmp AX, BX ja L1 mov TEMP, 43 jmp L2 L1: mov TEMP, 19 L2:

cmp al, bl jl YES jmp NO Which of the options below is equivalent to the code shown above?

cmp al, bl js CHECK jo YES jmp NO CHECK: jno YES jmp NO

On programming assignment 9, what is the correct statement to increment the hour portion of the date_time variable?

inc BYTE PTR [date_time + 1]

L1: mov EAX, 1 loop L1 The code shown below is equivalent to the loop shown above: mov ECX, 5 L1: mov EAX, 1 dec ECX cmp ECX, 0 1. ___________________ Which jump instruction should be inserted at line 1 in the code shown above?

jne L1

(C++ code) The linear_search function is implemented as an assembly procedure, which is called from C++ program. Which of the options below shows the correct prototype for the liner_search procedure in the assembly code file?

liner_search PROTO, arr:PTR DWORD, SIZE:DWORD, search_value: DWORD

Which of the options below will set BOTH CF and OF at the same time?

mov al, 80h add al, 80h

Suppose a program has the following array in the data segment: arr BYTE 17, 12, 15, 23 And the goal is to remove the first and the third element in the array, and move the second and fourth elements up to the begging of the array. Here an element will be "removed" by putting a -1 in it's place. After the program has finished running arr should be: [12, 23, -1, -1 ] Which of the options below is the correct implementation of the program?

mov al, [arr + LENGTHOF arr - 3] mov [arr], al mov al, [arr + LENGTHOF arr - 1] mov [arr + 1] mov [arr + LENGTHOF arr-2}, -1 mov [arr + LENGTHOF arr - 1], -1

add al, 0 js YES jmp NO

mov bl, al and bl, 80h jnz YES jump NO

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

mov ecx, 0 L1: mov eax, ecx inc ecx loop L1

ROWS = 5 .data pattern BYTE 32*ROWS dup(?) curr_row DWORD ? outer_loop DWORD ? count DWORD ? .code main proc mov ecx, ROWS mov curr_row, ROWS mov count, 0 L1: mov outer_loop, ecx mov ecx, curr_row mov eax, count jmp L3; this jumps to loop L2 L2: mov [pattern + eax], "#" mov ecx, outer_loop dec curr_row add count, 32 loop l1 (The options are in the next page) What pattern does the above program draw in memory? (assuming columns is set to 32 in visual studio)

# # # # #

1. The or instruction can be used to force specific bit's to be 0 2. The xor instruction can be used to force specific bit's to be 1.

1. False 2. False

1. It's NOT possible for both ZF (zero flag) = 1 and SF (sing flag) =1 at the same time. 2. It's NOT possible for both ZF (zero flag) = 1 and CF (carry flag) = 1 at the same time.

1. True 2. False

1. The instruction xor al, al will always set the sign flag (SF) to 0 2. The instruction xor al, al will always set the zero flag (ZF) to 0

1. True 2. False

1. The runtime stack grows_ 2. From_memory address to_memory addresses.

1. downward 2. higher, lower

if (EBX <= ECX AND EBX <= EDX) OR (EDX <= EAX) x = 37; else x = 14; Part of the equivalent assembly language program is shown below: cmp EBX, ECX 1. __________________ cmp EBX, EDX 2. __________________ jmp L2 L1: cmp EDX, EAX 3. ________________________ L2: 4.__________________________ jmp next L3: 5._______________________ next: Which of the options below contains the correct instructions that can be inserted at line 1-5 in the code above?

1. ja L1: 2. ja L1 3. ja L3 4. mov X, 37 5. mov x, 14

C++ code: if (val1 > ECX) AND (ECX > EDX) x = 33; else x = 55; Part of the equivalent assembly program is shown below: cmp val1, ECX 1. cmp ECX, EDX 2. 3. jmp next: L1: 4. next: Which of the option below contains the correct code to insert at line 1-4 in the program show above?

1. jbe L1 2. jbe L1 3. mov x, 33 4. mov x, 55

Suppose a program has the string "Fall 2022" stored in X. The goal of the program is to store the reversed string, "2202 llaF" in Y. Part of the program is as follows: .data X BYTE "Fall 2022", 0 Y BYTE SIZEOF source dup (?) .code main proc mov ecx, LENGTHOF X-1 mov edi, OFFSET X mov ebx, 0 L1: 1. _______________________ 2. ______________________ add edi, TYPE X loop L1 mov edi, OFFSET Y mov ecx, LENGTHOF Y-1 L2: 3. ___________________ 4.____________________ add edi, TYPE Y loop L2 mov BYTE PTR [esi], 0 invoke ExitProcess, 0 main endp end main Which of the options below contains the correct instructions to insert at lines 1-4 in the code shown above?

1. mov bl, [edi] 2. push ebx 3. pop ebx 4. mov [edi], bl

Suppose the top of the runtime stack is currently memory address 00000006. Then suppose the following instruction is executed: pop bx What will be the new memory address that is at the top of the stack?

00000008

Suppose a program is supposed to write the contents of register al to an array in the data segment. In particular, whenever a 0 bit is encountered in al, the character '0' (which has ASCII code 48) is written to the corresponding position in the array. Whenever a 1 bit is encountered in al, the character ''1' (which has ASCII code 49) is written to the corresponding position in the array. For example, if al = 11110000b array+0 = '1' (character '1') rest of the arrays Part of the program is as follows: .data array BYTE 8 DUP (0), 0 .code mov ecx, 8 mov edi, OFFSET array L1: 1_____________________________________ mov BYTE PTR [edi], '1' 2____________________________________ mov BYTE PTR [edi], '0' L2: inc esi loop L1 Which of the options below contains the correct instructions to insert al line 1 and 2 in the code shown above?

1. sal al, 1 2. jc L2

Suppose a program is suppose 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] Part of the program is as follows: .data array BYTE 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 .code main PROC mov edi, LENGTHOF array - 1 mov ecx, LENGTHOF array / 2 L1: mov bl, array[edi] 1. __________________________ mov array[edi], bl 2. ___________________________ loop L1 Which of the options below contains the correct code to insert at line 1 and 2 in the code shown above?

1. xchg bl, array [edi-1] 2. sub edi, 2

Suppose two players are playing a game that involves tossing a coin. Player 1's choice ('H' for heads or 'T' for tails) is stored in a variable named PLAYER_1. Player 2's choice ('H' for heads or 'T' for tails) is stored in a variable named PLAYER_2. The round number (1,2,3,4,5,6, etc.) is stored in a variable named ROUND_NUMBER. There is also a variable named OUTCOME that store the outcome of the game (0-tie, 1 - player 1 wins, 2 - player 2 wins) The following are the rules for the game: -If both players toss "heads", the outcome of the game is a tie. -If both players toss "tails", the outcome of the game is tie. -If the round number is ODD (1, 3,5, 7, etc.), then the player that tossed heads wins. For example, PLAYER_1 = 'H', PLAYER_2 = 'T', and ROUND_NUMBER = 1 means OUTCOME =1 (player 1 wins). -If the round number is EVEN (2, 4, 6, 8, etc.), then the player that tossed tails wins. For example, PLAYER_1 = 'H', PLAYER_2 = 'T', and ROUND_NUMBER = 2 means OUTCOME = 2 (player 2 wins). Most of the code for the procedure is shown below: coin_toss PROC mov al, PLAYER_2 cmp PLAYER_1, al jne CHECK_ROUND mov OUTCOME, 0 jmp THE_END CHECK_ROUND: mov bl, ROUND_NUMBER and bl, 0000001b jnz ODD_ROUND cmp PLAYER_1, 'T' 1. ________________________ mov OUTCOME, 2 jmp THE_END ODD_ROUND: cmp PLAYER_1, 'H' 2. ________________________ mov OUTCOME, 2 jmp THE_END PLAYER_1_WINS: mov OUTCOME, 1 THE_END: ret coin_toss ENDP Which of the options below contains the correct instructions to insert at lines 1 and 2 in the code shown above?

1..je PLAYER_1_WINS 2..je PLAYER_1_WINS

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

8

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

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

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

C-) 1. False 2. False

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 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 follow: .date source BYTE "COMSC 260", 0 target BYTE SIXEOF source DUP(?) .code main PROC mov ecx, SIZEOF source-1 L1: mov al, [esi] mov [edit], al dec esi inc edi loop L1 mov BYTE PTR [edit],0 For this program to work correctly, esi and edi must both be initialized correctly. Which of the options below correctly initializes both registers?

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

mov al, 00000000b Which of the instruction below contains a set of instructions that will cause the final value in al to be 00000000b?

not al add al, 1

(ASCII code) Given the ASCII code table shown above, suppose that we move space character into register al. Which of the options below would convert the space character in al to the DEL character?

or al, 5fh

(Blue picture) main PROC 00000010 call MySub 00000014 mov eax, ebx . . main ENDP MySub PROC 00000032 mov eax, edx . . MySub ENDP (Blue picture) -Runtime Stack EIP(initial state) (initial state) 00000032 00000014 (ESP arrow) -Runtime Stack EIP (final state) (Final state) 0000014 (empty) Which instruction would cause the runtime stack and register EIP to change from the initial state shown above to the final state shown above?

ret

mov al, FEh add al, 1 The add instruction will set_

sing flag (SF) = 1


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

American History Unit 28 Test Part One

View Set

Dr. Youan Exam 2 Poll Everywhere and Group Qs

View Set