Assembly Language Final

Ace your homework & exams now with Quizwiz!

mov edi,pString*** mov eax,0**** L1: cmp BYTE PTR [edi],0**** je L2**** inc edi**** inc eax**** jmp L1**** L2:

Assume that pString is a doubleword that contains the offset of a string. This code will will set EAX to the length of the string? (The length should not count the string's null byte.)

arguments pushed on stack; procedure called; EBP pushed on stack; EBP set to ESP

Assuming that a procedure contains no local variables, a stack frame is created by which sequence of actions at runtime?

False

For any two integers n and m, ((n XOR m) OR m) produces n.

DX=FFFFh, AX=80C0h

Given that EAX contains FFFF80C0h, the contents of DX and AX after executing the CWD instruction

mov esi,0**** mov edi,0**** mov ecx,NUMROWS**** mov ax,0**** L1: add ax,twArray[esi+edi]**** add esi,(ROWSIZE * TYPE twArray)**** loop L1

Given the following declaration of a two-dimensional array,write a code to calculate the sum of theelements in column 0:::::: .data ROWSIZE = 5 NUMROWS = 4 twArray WORD NUMROWS DUP( ROWSIZE DUP(?) )

shr ax,1 **** rcr dx,1 **** shr ax,1 **** rcr dx,1

Given the following two assignments to AX and DX, which block of instructions will cause DX to equal 4025h and AX to equal 1AD2h ::::: mov ax,6B49h ***** mov dx,0095h

3

How many daughters did Charles Ingalls have in Little House on the Prairie?

3.78 liters

How many liters are there in the U.S. gallon?

change CMPSB to CMPSW and change JA to JG, and change JB to JL

If var1 and var2 were changed to type SWORD in the following code, then this change(s) would have to be made to the instructions in the code segment: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: .data*** var1 BYTE 10**** var2 BYTE 20**** var3 BYTE 30**** .code********** mov esi,OFFSET var2**** mov edi,OFFSET var1**** cmpsb**** ja L1**** jb L2**** je L3

True

In Protected mode, immediate values pushed on the stack are always 32 bits long.

CF = 0, ZF = 0, SF = 0

These are the values of CF, ZF, and SZF after the following instructions are executed : ::: mov al,00110011b**** test al,2

Chrysler

This US auto maker produced a car called the Cirrus

Delta

This airline company is named after a Greek letter

:mov ax,0FFFFh**** mov esi,OFFSET arrayW**** mov ecx,SIZEOF arrayW**** std**** rep stosw

This block of code will fill all elements of arrayW with FFFFh:::: arrayW WORD 50 DUP(?)

mov ebx,edx ***** shl edx,5 ****** shl ebx,2 ***** add edx,ebx*****ALSO ::::::::mov ebx,edx*** shl ebx,5*** shl edx,2*** add edx,ebx

This blocks of instructions multiplies the contents of the EDX register by 36

MOV EAX, 500 ***** call Delay

This code causes a 500 millisecond delay, using a library procedure.

and al, 11111100 ****jz L3****jmp L

This code clears bits 0 and 1 in AL. Then , if the destination operand is equal to 0, the code should jump to label L3, otherwise, it will jump to label L4

mov Max, eax ; assume Max = eax**** cmp Max, ebx**** jae done**** mov Max, ebx ; Max = ebx**** done:

This code computes the Max of unsigned EAX and EBX

MOV ESI, OFFSET array**** MOV ECX, LENGHTOF array**** MOV EBX, TYPE array**** call dumpMem

This code displays the following array in hexadecimal, using the DumpMem procedure from the link library:::::array DWORD 10h,20h,30h,40h

mov ecx, LENGTHOF mystring**** mov esi, OFFSET mystring**** L1: or BYTE PTR [esi], 20h ; set bit 5**** inc esi**** loop L1****

This code converts the string mystring to lower case

MOV EDX, OFFSET str1****call WriteString

This code will display the following string to standard output::::: str1 BYTE "Display this string",0

0100 0010

This is the binary value of AL after the following instructions have executed ::::::: mov al,10000101b **** clc **** rcr al,1

1100 0000 0010 0111

This is the binary value of AX after the following instructions have executed ::::: mov ax,0000 0000 1001 1101 b **** mov bx,1010 1010 1000 1011 b **** shrd ax,bx,2

0000 0001 0011 1011

This is the binary value of AX after the following instructions have executed :::::: mov ax,0000 0000 1001 1101 b **** mov bx,1010 1010 1000 0000 b **** shld ax,bx,1

10111110

This is the content of AL after the following instructions execute :::: mov al,00111100b**** or al,82h

00001011

This is the content of AL after the following instructions execute :::: mov al,11001111b***** and al,00101011b

00h

.data**** 2: str1 BYTE "AAAX",0**** 3: str2 BYTE 10 DUP(0FFh)**** 4: .code**** 5: mov edi,0**** 6: L1: mov al,[str1+edi]**** 7: cmp al,0**** 8: je L2 9: mov [str2+edi],al 10: inc edi**** 11: jmp L1**** 12: L2:****** If we changed lines 7, 8, and 9 to the following, what value would be stored at offset [str2+4] after the loop finished? 7: mov [str2+edi],al****** 8: cmp al,0***** 9: je L2

0FFh

.data**** 2: str1 BYTE "AAAX",0**** 3: str2 BYTE 10 DUP(0FFh)**** 4: .code**** 5: mov edi,0**** 6: L1: mov al,[str1+edi]**** 7: cmp al,0**** 8: je L2**** 9: mov [str2+edi],al**** 10: inc edi**** 11: jmp L1**** 12: L2: After the code executes, what value will be stored at offset [str2+4]?

CaseTable BYTE 'a'**** DWORD afoo**** EntrySize = ($ - CaseTable)**** BYTE 'b'**** DWORD bfoo**** BYTE 'c'**** DWORD cfoo**** BYTE 'd' **** DWORD dfooo BYTE 'e'**** DWORD efoo**** BYTE 'f' **** DWORD ffooo NumberOfEntries = ($ - CaseTable) / EntrySize

A case table that can call these prosedures if the user selects : a,b,c,d,e,f :::afoo, bfoo, cfoo, dfoo, efoo, ffoo. It must calculate table entry size and how many entries are there in the table.

IsDigit PROC**** cmp al,'0' ; ZF = 0**** jb ID1**** cmp al,'9' ; ZF = 0**** ja ID1**** test ax,0 ; ZF = 1**** ID1: ret**** IsDigit ENDP

A code for a procedure that receives a character in AL. Sets the Zero flag if the character is a decimal digit.

True

A link library is a file containing procedures that have been assembled into machine code.

3 times

Consider the MySub procedure listed below. If it were called with N = 5, how many times would the RET instruction execute? MySub PROC, N:DWORD cmp N,7 je L1 mov eax,N inc eax INVOKE MySub,eax L1: ret MySub ENDP

MySub is recursive and MySub terminates when N is equal to 7 are both correct

Consider the procedure named MySub in the code below. Which of the following statements are true? MySub PROC, N:DWORD cmp N,7 je L1 mov eax,N inc eax INVOKE MySub,eax L1: ret MySub ENDP

cmp ebx, ecx**** jna L1**** cmp ebx, edx**** jna L1**** jmp L2**** L1: cmp edx, eax**** jna L3**** L2: mov X, 1**** jmp next **** L3: mov x, 2 **** next:

In assembly language ::: if(ebx >ecx AND ebx >edx> OR (edx >eax) then X = 1 **** else X = 2

ASCII code of "3"

In this Example, if we change line 7 to "repe scasb", what value will be moved to BL after line 8 executes?::::::::: 1: .data**** 2: str1 BYTE "1324A2342424",0**** 3: .code**** 4: mov edi,OFFSET str1**** 5: mov al,'A'**** 6: cld**** 7: repne scasb**** 8: mov bl,[edi]****

at var2

In this example ESI point at this variable after the CMPSB instruction executes::::.data*** var1 BYTE 10**** var2 BYTE 20**** var3 BYTE 30**** .code********** mov esi,OFFSET var2**** mov edi,OFFSET var1**** cmpsb**** ja L1**** jb L2**** je L3

L1

In this example the program will jump to this label ::::.data*** var1 BYTE 10**** var2 BYTE 20**** var3 BYTE 30**** .code********** mov esi,OFFSET var2**** mov edi,OFFSET var1**** cmpsb**** ja L1**** jb L2**** je L3

00040015h

In this example, assume that str1 is located at offset 00040010h. What will be the value of EDI after line 7 executes?:::::1: .data**** 2: str1 BYTE "1324A2342424",0**** 3: .code**** 4: mov edi,OFFSET str1**** 5: mov al,'A'**** 6: cld**** 7: repne scasb**** 8: mov bl,[edi]****

cannot be determined

In this xample , if we change line 6 to "std", what value will be moved to BL after line 8 executes?::::1: .data**** 2: str1 BYTE "1324A2342424",0**** 3: .code**** 4: mov edi,OFFSET str1**** 5: mov al,'A'**** 6: cld**** 7: repne scasb**** 8: mov bl,[edi]****

In Ohio it is, if done without a hunting license!

Is it illegal to catch mice?

7: cmp al,'z' ***** 8: ja L2***** 9: and BYTE PTR [esi],11011111b***** 10: L2: inc esi***** 11: jmp L1***** 12: L3: ret*****

Suppose we want to convert the letters in myString to uppercase (by clearing bit 5 of each character). Lines 1 through 6 are the first part of the implmentation::::: .data**** myString BYTE "abCDefg123hij",0**** .code**** 1: mov esi,OFFSET myString**** 2: L1: mov al,[esi]**** 3: cmp al,0 **** 4: je L3 **** 5: cmp al,'a'**** 6: jb L2**** WRITE THE REMINING INSTRUCTIONS:::::

FALSE

T/F A WHILE loop can be constructed with a CMP instruction at the bottom of the loop, followed by a conditional jump instruction.

FALSE

T/F The PUSH instruction increments the stack pointer (by 2 or 4) and copies the operand into the stack at the location pointed to by the stack pointer.

FALSE

T/F The assembler knows the exact address of a library procedure

TRUE

T/F This code sequences assigns the value 10h to EBX:::: mov edx,20h**** push edx**** mov ecx,10h**** push ecx**** pop ebx**** pop edx

True

The DIV instruction generates a divide overflow condition when the quotient is too large to fit into the destination operand.

False

The EBP register points to the last value pushed on the stack.

False

The Irvine32.lib procedures cannot directly call functions in the kernel32.lib library.

True

The JA instruction is used when comparing unsigned integers.

False

The JCXZ instruction jumps to a target label when the ECX register is equal to zero.

False

The JL instruction jumps if the (unsigned) first operand is less than the (unsigned) second operand.

ESI

The MOVSB instruction uses this register as the source operand

False

The OR instruction can be used to set an operand's value to zero.

False

The OR instruction modifies the Sign and Zero flags, but not the Parity flag.

False

The PUSH instruction copies a value from the stack to an operand before incrementing the stack pointer.

True

The PUSHAD instruction pushes all the 32-bit general-purpose registers on the stack.

repeats an instruction while the Zero flag is set

The REPE prefix does the following:

False

The ReadChar procedure echoes its input character on the screen.

False

The SAR and SHR instructions perform the same operation.

True

The SAR instruction is suitable for signed integers.

False

The SHL instruction is suitable only for signed integers.

True

The XOR instruction can be used to generate the one's complement of an integer.

True

The binary value of AL after the following instructions have executed is 00011010. mov al,01101011b shr al,2

False

The binary value of AL after the following instructions have executed is 11101101. mov al, 01101011b rol al,2

1 1 0

The contents of CF, SF, and ZF after these instructions are executed ::: mov al,5 cmp al,7

False

The destination operand of the AND instruction must be a register.

True

The destination operand of the IMUL instruction must always be a register.

True

The first value pushed on a stack is the last one to be removed.

mov eax,var1**** cmp eax,var2**** jle ifpart**** mov var3,6**** mov var4,7**** jmp next**** ifpart:**** mov var3,10**** next:

The following code in assembly Language:::if (var1 <= var2) **** {**** var3 = 10;**** }**** else**** {**** var3 = 6;**** var4 = 7;**** }

cmp ebx, ecx**** ja L1****cmp ebx, val1****ja L1****mov X, 2****jmp next****L1: mov X, 1****next:

The following code in assembly language ::: if(ebx > ecx ) OR (EBX >val1 ) then x=1 **** else X = 2

cmp val1, ecx****jna L1**** cmp ecx, edx****jna L1****mov x, 1**** jmp next****L1: mov X, 2****next

The following pseudo code in assembly language::: if(val1 >ecx) AND (ecx >edx ) then X = 1**** else X = 2;

cannot be determined

The hexadecimal values of DX and AX after the following instructions have executed :::: mov ax,3456h **** mov dx,12h **** mov bx,10h **** div bx

False

The runtime stack is managed by the operating system, with no support from the CPU.

1. EAX, 2. ESI

The two registers containing: 1. an integer before calling WriteDec and 2. the starting address of data when calling DumpMem

.DATA***sum DWORD 0***sample DWORD 50*** array DWORD 10, 60, 20, 33, 72, 89, 45, 65, 72,18****arraySize = ($ - array) / TYPE array****.CODE *** mov EAX, 0****mov EBX, sample***mov ESI, 0 **** MOV ECX, arraySize****L1: CMP ESI,ECX***JNL L5****cmp array[ESI*4], EDX****JNG L4**** add EAX, array[ESI*4]****L4 : inc ESI**** jmp L1****L5 : mov sum, EAX

This code is functionally equivalent to example 6.5.3 but has fewer instructions

****MOV EAX, 1000*****call RandomRange ***** calWriteDec

This code uses library procedures to generate a single unsigned pseudorandom integer between 0 and 999 and write it to standard output:

call ReadInt*****call WriteInt

This code writes a sequence of statements that read a signed integer from standard input and write the same integer to standard output. Use library procedures.

mySub PROC USES EAX EBX

This codes a PROC declaration for a procedure named MySub. It uses the USES operator to preserve the EAX and EBX registers.

United States

This country produces the greatest volume of beer per year

kernel32.lib

This file acts as a bridge between Irvine32.lib and kernel32.dll

call writeInt

This instruction ( a function call ) writes the contents of EAX to standard output as a signed decimal integer?

and dl,0Eh**** cmp dl,0Eh**** je L4****

This instruction cause a jump to label L4 if bits 1, 2, and 3 are all set in the DL register?

CLD

This instruction causes the ESI and EDI registers to be incremented by the MOVSB instruction

ROL AL, 4

This instruction converts the value 6Fh in AL to the value F6h.

RCR AL, 1

This instruction copies the value of the Carry flag into bit 7 of AL, and shifts all existing bits in AL one position to the right.

POPFD

This instruction pops the stack into the FLAGS register

PUSHFD

This instruction pushes the 32 bit FLAGS registers on the stack

shr ebx,3

This instruction will divide the unsigned integer in EBX by 8 (using shifts only)

shl ebx,5

This instruction will multiply the integer in EBX by 32 (using shifts only)

1010 1110

This is the binary value of AL after the following instructions have executed :::: mov al,01101011b **** stc **** rcl al,2

10100011

This is the content of AL after the following instructions execute ::::mov al,94h xor al,37h

:: top:**** mov eax,int2**** cmp eax,int1**** jl L3**** add ebx,2**** cmp ebx,int2**** jg L1**** mov ebx,int1**** jmp L2**** L1: mov ebx,0**** L2: jmp top**** L3:

This is the correct implementation of the following pseudocode::::while( int2 >= int1 )**** {**** add ebx,2**** if( ebx > int2)**** mov ebx,0**** else**** mov ebx,int1**** }

mov val1,ebx**** cmp ebx,val2**** jg L1**** cmp val2,eax**** jg L1**** mov ebx,2**** jmp L2**** L1: mov ebx,1**** L2:

This is the correct implementation of the following pseudocode:::if( val1 > val2 || val2 > eax )**** mov ebx,1;**** else**** mov ebx,2;

cmp eax, ebx***jna L1****mov DL, 5****jmp L2****L1: mov dl,6 200

This is the equivalent Assembly Language code of the following C++ code. Assume that integers are unsigned. NO .IF directive allowed: if( eax > ebx ) mov dl,5; ******* else mov dl,6;

DX = 012Ah, AX = D692h

This is the hexadecimal values of DX and AX after the following instructions have executed ::::: mov ax,6B49h **** mov dx,0095h **** shl ax,1 **** rcl dx,1 ****

5

This is the value of EAX when the following sequence of instructions has executed::::: push 5***** push 10***** pop ebx***** pop eax

20

This is the value of EAX when the following sequence of instructions has executed::::: push 5***** push 10***** push 20***** pop eax

Cannot be determined

This is the value of ECX when the following sequence of instructions has executed::::: push 5**** push 10**** pop ebx**** pop eax**** pop ecx

WriteHex

This library procedure writes an unsigned 32-bit integer to standard output in hexadecimal format

KEY = 239 ; Can be any byte value**** BUFMAX = 128**** .DATA**** buffer BYTE BUFMAX+1 DUP(0)**** bufSize DWORD BUFMAX**** .CODE **** mov ecx, bufSize ; loop counter**** mov esi, 0 ; index 0 in buffer**** L1:**** xor buffer[esi], KEY ; translate a byte**** inc esi ; point to next byte**** loop L1****

This loop uses the XOR instruction to transform every character in a string called buffer into a new value ( produce a cipher text)

7

This many red stripes are on the U.S. flag

Elvis Presley

This person of non royal origins was known as "The King"?

Gotoxy

This procedure locates the cursor at a specific row and column on the screen

Rhone River

This river runs through both Lyon and Marseilles?

"The quick brown fox jumps over a lazy dog."

This sentence contains every letter of the English Alphabet.

mov eax, -16 ****cdq*****mov ebx, 5****idiv ebx

This sequence of instructions divides -16 by 5, using the IDIV instruction. It uses the EBX register as a divisor.

mov BL, AL ***** and BL, 0011 1111b

This sequence of two instructions copies bits 0-5 from AL to bits 0-5 in BL. Bits 6-7 in BL are cleared, and AL is unchanged.

shr AL, 4 **** mov BL, AL

This sequence of two instructions copies the integer in bits 4-7 from the AL register into bits 0-3 of the BL register. The upper 4 bits of AL are cleared, as will the upper 4 bits of BL.

mov EBX, EAX ; make copy **** shl EAX, 4 ; EAX * 16 ****shl EBX, 1 ; EBX * 2 ****add EAX, EBX ; answer

This series of instructions multiplies EAX by 18, using a combination of shift, MOV, and ADD instructions.

AND ax, 00FFh

This single instruction uses 16 bit operand that clear the high 8 bits of AX and does not change the low 8 bits

MOV EAX, black + ( white * 16)

This statement moves a video color constant to EAX. The constant should represent black text on a white background, (using the constants in the Irvine32.inc file)

Niagara Falls

This waterfalls are between Lake Erie and Lake Ontario

DX = 0042h, AX = 0F63h

This will be the hexadecimal values of DX and AX after the following instructions have executed :::::: mov dx,000Fh **** mov ax,6342h **** mov bx,100h **** div bx

DX = FFFFh, AX = FFE0h

This will be the hexadecimal values of DX and AX after the following instructions have executed::::: mov dx, -16 **** mov ax,2 **** imul dx

OF = 1 ( DX = 0000h, AX = 8000h, so DX is not a sign extension of AX)

This will be the value of the Overflow flag after the following instructions have executed ::::: mov dx,800h **** mov ax,10h **** imul dx

INVOKE permits you to pass arguments separated by commas.

What advantages does INVOKE offer over the CALL instruction?

"Infart" and "Utfart."

What is "entrance" and "driveway" in Swedish?

The operand order is the same between PUSH and POP, as in: push eax push ebx ...(some other code) pop eax pop ebx

When saving and restoring registers with PUSH and POP, which of the following is a mistakes?

False

When the MUL BL instruction executes, the upper half of the product ends up in the DX register.

False

When the MUL BX instruction executes, the 32-bit product ends up in the EAX register.

True

When the product fits completely into the lower register of the product, IMUL sign extends the product into the upper product register. MUL, on the other hand, zero extends the product

True

When using the Irvine32 library, you should always push 32-bit values on the stack.

after MOV EBP,ESP, subtract 8 from the stack pointer (ESP)

Which action must take place inside a procedure to reserve space on the stack for two doubleword local variables?

Champagne is about 3 times as much pressure as in a tire

Which is greater - The pressure in an automobile tire, or the pressure in a bottle of champagne?

Zurich

Which is the financial centre and main city of Switzerland?

INVOKE mySub, PTR myList

Which of the following INVOKE statements is invalid?

MySub PROC val1:WORD, val2:DWORD

Which of the following PROC statement is invalid?

LOCAL wArray[50]:SWORD

Which of the following defines an array local variable consisting of 50 signed words?

push ebp mov ebp,esp sub esp,4

Which of the following shows the procedure entry code generated by MASM when the LOCAL directive is used to declare a doubleword variable?

Marrakesh ( Morocco )

Which one of these is not on the coast: Venice, San Diego, Reykjavik, Marrakesh, Helsinki, Lisbon

True

With signed operands, the CMP instruction makes the Sign flag equal to the Overflow flag when the destination operand is greater than the source operand.

False

With unsigned operands, the CMP instruction sets the Carry flag when the destination operand is greater than the source operand.

Read10 PROC**** MOV ECX, LENGHTOF myString**** MOV ESI, OFFSET myString**** L1: call ReadChar**** MOV [esi], AL**** INC ESI**** Loop L1**** RET Read10 ENDP

Write a procedure named Read10 that reads exactly ten characters from standard input into an array of BYTE named myString. Use the LOOP instruction with indirect addressing, and call the ReadChar procedure from the book's link library. (ReadChar returns its value in AL.)

ShowBinary PROC**** MOV ECX, LENGHTOF array**** MOV ESI, OFFSET array**** L1: MOV EAX, [esi]**** call WriteBin**** ADD ESI, TYPE array**** Loop L1**** RET**** ShowBinary ENDP

Write a procedure named ShowBinary that displays the following array as a sequence of binary bits, starting with the low-order value (00000010h). Include the use of the LENGTHOF, OFFSET, and TYPE operators, and call the WriteBin procedure::::: array DWORD 10h,20h,30h,40h

; ( first 3 statements may be in any order)**** mov edi, OFFSET arrayD**** mov ecx, LENGHTOF arrayD**** cld*** repz scasd**** mov eax, [edi-4]

Write a sequence of instructions that use SCASD to search arrayD for the first value that is not the same as the current contents of EAX. When the search is completed, move the value you have found into EAX:::: arrayD SDWORD 50 DUP(?)

; ( first 4 statements may be in any order)*** mov eax, 7FFFFFFFh**** mov edi, OFFSET arrayD**** mov ecx, LLENGHTOF arrayD**** cld**** rep stosd

Write a sequence of instructions that use STOSD to fill each position of arrayD with the largest possible 32-bit positive integer: arrayD SDWORD 20 DUP(?)

; ( first 4 statements may be in any order )**** mov esi, arrayA + count - 4**** mov edi, arrayB + count - 4**** mov ecx, count**** std**** repe cmpsd**** ; (next 2 assignments may be in any order)**** mov eax, [esi+4] ; from arrayA ***** mov ebx, [edi +4] ; from arrayB

Write a sequence of instructions using CMPSD that compare arrayA to arrayB in reverse order. After the comparison, move the first pair of non-matching array values to EAX and EBX.::::: COUNT = 5**** arrayA DWORD COUNT DUP(?)**** arrayB DWORD COUNT DUP(?)****

(first 4 statements may be in any order)**** mov ecx, LENGHTOF arrayA**** mov esi, OFFSET arrayA**** mov edi, OFFSET arrayB**** cld******** L1 : LODSB**** or al, 0010 0000**** stosb**** LOOP L1

Write a sequence of instructions using LODSB and STOSB that copy each character from arrayA to arrayB, converting it to lowercase in the process. Note: setting bit 5 in an uppercase character will convert it to lowercase:::: arrayA BYTE "ABCDEFGHI"**** arrayB BYTE LENGTHOF arrayA DUP(0)


Related study sets

Chapter 2 HW: Samples, Good and Bad

View Set

Missouri life insurance exam practice

View Set

Ethics Test 1 - Aristotle, Aquinas, Socrates, Hobbes

View Set

Ethical Dilemmas and Decisions in Criminal Justice, 7th ed. Chapter 1-7 Exam

View Set

Aircraft Painting and Finishing - Test Guide

View Set