CS305 F2011 Final Exam

Date: 12 PM, 12/14/2011 Print Name ______Sign ______Score ___

Note: Email me and hand in a hardcopy of this exam to .

I. Multiple-Choice (40%, 2% for each question)

  1. ( ) The two's complement of an integer is formed by doing which of the following?

a. reversing (inverting) the bits and adding 1 b. adding 1 and reversing the bits

c. calculating the integer's additive inverse d. changing the highest bit to a 1

  1. ( ) What is the largest signed integer that may be stored in 32 bits?

a. 232 - 1 b. 232 c. 231 - 1 d. 231

  1. ( ) Which of the following binary values is equivalent to hexadecimal 7CBE?

a. 0111 1101 1011 1110 b. 0111 1011 1011 1100

c. 0111 1100 1100 1110 d. 0111 1100 1011 1110

  1. ( ) If you wanted to find out whether an integer contained an even number of 1 bits, which status flag would be useful?

a. carry b. overflow c. sign d. parity

  1. ( ) Within the CPU, all calculations and logic operations take place inside the ______.

a. registers b. ALU c. CU d. MBU

  1. ( ) List the three primary steps of the instruction execution cycle, in sequential order:

a. fetch, decode, memory write b. fetch, memory read, execute

c. decode, fetch, execute d. fetch, decode, execute

  1. ( ) Which register is known as a loop counter?

a. EAX b. EBX c. ECX d. EDX

  1. ( ) Which directive identifies the part of a program containing instructions?

a. .DATA b. .CODE c. .STACK d. .PROG

  1. ( ) Which directive(s) are used when defining both signed and unsigned 64-bit integers?

a. QWORD and SQWORD b. DWORD c. QWORD d. DWORD and SDWORD

  1. ( ) The byte-ordering scheme used by computers to store large integers in memory with the high-order byte at the lowest address is called:

a. big endian b. byte-major c. little endian d. byte-minor

  1. ( ) What is the final hexadecimal value of AX when this code executes?

mov ebx,OFFSET dword1

sub ebx,2

mov ax,[ebx]

a. 0000h b. 0010h c. 9000h d. 0020h

  1. ( ) What is the final hexadecimal value of EAX when this code executes?

mov edx,8

mov eax,dword1[edx]

a. 00000010h b. 20000000h c. 00300000h d. 00000030h

  1. ( ) Which of the following CALL instructions writes the contents of EAX to standard output as a signed decimal integer?

a. call WriteInteger b. call WriteDec c. call WriteHex d. call WriteInt

  1. ( ) Which answer choice shows the correct values of the Carry, Zero, and Sign flags after the following instructions execute?

mov al,00110011b

test al,2

a. CF = 1, ZF = 0, SF = 1 b. CF = 0, ZF = 1, SF = 0

c. CF = 1, ZF = 0, SF = 1 d. CF = 0, ZF = 0, SF = 0

  1. ( ) Suppose we want to copy the value of the Carry flag into bit 7 of AL, and shift all existing bits in AL one position to the right. Which of the following instructions will work?

a. shr al,1 b. sar al,1 c. ror al,1 d. rcr al,1

  1. ( ) Which of the following instructions will multiply the integer in EBX by 32?

a. shr ebx,5 b. rol ebx,32 c. shl ebx,5 d. ror ebx,32

  1. ( ) What will be 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

a. DX = 0148h, AX = C691h b. DX = 012Ah, AX = C9A2h

c. DX = 012Ah, AX = D692h d. DX = 024Bh, AX = D692h

  1. ( ) The MOVSB instruction uses which register as the source operand?

a. ESI b. EDI c. EAX d. ECX

  1. ( ) What data definitions will be created by the following directives?

FOR colorVal,<red,green,blue,turquoise,purple,orange>

BYTE "&colorVal",0

ENDM

a. six strings, each equal to "&colorVal", followed by a null byte.

b. six null-terminated strings, each containing the name of a different color

c. six variables, each having a label whose name is a color

d. this statement will cause a syntax error

  1. ( ) Which of the following statements permits assembly if arg1 is exactly the same as arg2? (Assume that a case-senstitive comparison is used.)

a. IFEQUAL <arg1>,<arg2> b. IFIDN <arg1>,<arg2> c. IF arg1 EQ arg2 d. IFEQ arg1,arg2

II. Fill Blanks and Short Answers (20%)

II. Fill Blanks and Short Answers (30%, 2% for each question)

  1. (2%) Which directive is used when defining unsigned 16-bit integers? ______
  2. (2%) Which library procedure reads a string from standard input? ______
  3. (2%) What will be the value of ECX when the following sequence of instructions has executed? ______

push 5

push 10

pop ebx

pop eax

pop ecx

  1. (4%) In the following instruction sequence, show the changed values of AL where indicated, in binary:

mov al,11001111b

and al,00101011b ; a. ______00001011

mov al,4Bh

and al,6Ch ; b. ______01001000

mov al,00111100b

or al,82h ; c. ______10111110

mov al,94h

xor al,37h ; d. ______10100011

  1. (6%) Define a structure named ThreeInts containing three unsigned doublewords named field1, field2, and field3. The fields should be uninitialized.
  2. (4%) Write code that causes a 500 millisecond delay, using a library procedure.

III. Short Programming Problems (40%, 8% for each problem)

Note: Paste screenshots of your programs and execution results under each question.

Email me your assembly source code of each question.

  1. Given the following data definition, write a sequence of statements that display a dump of the data in 32-bit hexadecimal, using the DumpMem procedure from the link library.

array DWORD 10h,20h,30h,40h

  1. Write a sequence of two instructions that 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 will be cleared, as will the upper 4 bits of BL.
  2. Using the following definition of a two-dimensional array, write a sequence of instructions that use a base-index operand to move the element at row 2, column 3 to AX. (Row and column numbers begin at 0).

.data

ROWSIZE = 5

NUMROWS = 4

twArray WORD NUMROWS DUP( ROWSIZE DUP(?) )

  1. 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(?)

  1. Create a macro named putChar that writes a single character, passed as a macro argument, to standard output. Be sure to push and pop any registers modified by the macro.