Final Review Questions Flashcards

1
Q

For the following segment, what is SIZEOF myChecker (in decimal - ignore the .0000 from Canvas)

.data
myChecker   BYTE   12h
            BYTE   34h
            BYTE   56h
            BYTE   78h
            BYTE   90h
A

1 byte.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The _________ operator returns a value that is equivalent to multiplying the number of elements in a single data declaration by the size, in bytes, of a single element of a data declaration.

A

SIZEOF

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The _________ operator overrides the default type of a label (variable), and can also be used to combine elements of a smaller data type and move them into a larger operand.

A

PTR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What do these do?

    • lodsb
    • stosb
    • cld
    • std
A

lodsb: load string byte
stosb: store string byte
cld: clear direction flag
std: set direction flag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

True or False? If the string direction flag is not set, string operations will move backward through the string.

A

False. It only moves backwards when the direction flag is set.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Suppose that you are given the following partial data segment, which starts at address offset 0x1000 :
.data
idArray WORD 3546, 1534, 12, 3481, 154, 6423
x DWORD LENGTHOF idArray
y DWORD SIZEOF idArray
z DWORD TYPE idArray

x contains what value, in decimal?

y contains what value, in decimal?

A

Y contains 6. There are 6 elements in the array, so it has the lengthof 6.

X contains 12, or the LENGTHOF the array * its TYPE size.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
Suppose that you are given the following partial data segment:
.data
myPtrCheck   BYTE   12h, 34h, 56h, 78h,
                    90h, ABh, CDh, EFh
.code
...
mov   eax, DWORD PTR [myPtrCheck+2]

EAX contains what value, in hexadecimal?

A

AB907856h

It starts with 2 bytes beyond the first element of the array (on the third element).

Although strings generally are stored sequentially, once it is stored as a single DWORD using PTR, then it becomes in reverse order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Assume that your program has access to the following data segment (starting at address 0x310):
.data
id DWORD 7
matrix WORD 50 DUP(10 DUP(?))

What is the hexadecimal address of matrix[7][3] (the 4th element of the 8th row)?

A

3A6.

This is a 50 x 10 matrix, with each row taking 210 bytes. Therefore, to figure out the address of the 8th row, add 7210 = 140. Next, we add 32 = 6, which will make 146 on top of the original address.

Since the data segment starts at 310h, and we add 4 for the DWORD and 146 for the matrix navigation, we end up with 3A6.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How would you write this as a postfix expression?

56 / (42 * 2.6 * 2) + (256 / (128 - 64)) * 3 ^ 12

A

56 42 2.6 * 2 * / 256 128 64 - / 3 12 ^ * +

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How would this postfix expression look when represented as infix?

3 3 * 5 4 2 * / -

A

3 * 3 - 5 / (4 * 2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What FPU manipulations corresponds to the given infix notation?

Z = (A+B-C)/D*E

A
finit
fld    A
fld    B
fadd
fld    C
fsub
fld    D
fdiv
fld    E
fmul
fstp   Z
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you generate random numbers?

A

First, call Randomize just once (e.g. main). Whenever you call RandomRange (N>0 in eax), it’ll return random number between 0 and N-1. Therefore, you need to find the range (hi-lo + 1), put that range in eax, and add that to the minimum.

	;generate and display random integer n
	mov		eax, N_MAX    
	sub		eax, N_MIN	
	inc		eax
	call	RandomRange		
	add		eax, N_MIN	
	mov		esi, [ebp+12]
	mov		[esi], eax
	call	WriteDec
	call	CrLF
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What specifically is indexed addressing?

A
Indexed addressing: Used for global array references, array name with subscript [distance]
	Mov edi, 0
	Mov list[edi], eax
	Add edi, 4
	Mov list[edi], ebx
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What specifically is register indexed addressing?

A
Register indirect addressing: Get the address of list into esi, and then use [esi]. 
	Mov esi, [ebp+8]
	Mov eax, [esi]
	Add esi, 4
        mov eax, [esi]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What specifically is base-indexed addressing?

A
Base-indexed addressing: Starting address in one register, offset in another, and add and access memory (used for referencing array elements in procedures). 
	Mov edx, [ebp+8]
	Mov ecx, 20
	Mov eax, [edx+ecx]
	Mov ebx, 4
	Add eax, [edx+ebx]
	Mov [edx+ecx], eax
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Given the following register states, and using Indexed Addressing, which of the following lines of code will move the 11th element of the list array (of DWORDs) to the EAX register?

EDX register contans the address of the first element of list.
ESI register contains the address of the eleventh element of list.
EBX register contains the value 40,

A

mov eax, list[ebx]

In indexed addressing, you use the list and a subscript of the index distance you want. Because you want to add 10*4 to the original address, you want list[40].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Given the following register states, and using Register Indirect Addressing, which of the following lines of code will move the 11th element of the list array (of DWORDs) to the EAX register?

EDX register contans the address of the first element of list.
ESI register contains the address of the eleventh element of list.
EBX register contains the value 40,

A

mov eax, [esi]

When you use register indirect addressing, you store the address of the element you want directly in a register, and then dereference that register to access the value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Given list, an array of WORDs, what element is addressed by list[8]?

Hint: It’s Love.

A

5th element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Given the following register states, and using Base Indexed Addressing, which of the following lines of code will move the 11th element of the list array (of DWORDs) to the EAX register?

EDX register contans the address of the first element of list.
ESI register contains the address of the eleventh element of list.
EBX register contains the value 40,

A

mov eax, [edx + ebx]

In base indexed addressing, there are two registers keeping track of two things: (1) the base address of the array and (2) the distance in bytes from the first element.

Here, edx contains the addrss of the first element of the list, and ebx contain 40, the distance offset in bytes of the 11th element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

The following instruction will increment the stack pointer (ESP) by how many bytes?

ret 16

A

20 bytes. By default, it’ll also get rid of the return address (as a DWORD) when it goes back there.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What would the stack look like (and at what distance from the ebp is everything)?

.data
x DWORD 153461
y WORD 37
z WORD 90

.code
main PROC
   push  x
   push  y
   push  z
   call  someProcedure
   ...
   exit
main ENDP

someProcedure PROC
push ebp
mov ebp, esp

A
[ebp] - ebp
[ebp+4] - @ret
[ebp+8] - z - 90
[ebp+10] - y - 37
[ebp+12] - x - 153461

In essence, the distance from the top of the stack depends on the value closer to the stack (since it had decremented to get to that point). Therefore, 90 is at [ebp+8] even though it’s only a WORD because the stack pointer decremented down to [ebp+4] to accommodate the DWORD return address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Suppose that you are given the following program (with memory addresses shown on the left).
What hexadecimal value does EIP hold immediately after “inc EAX” has executed?

.data
0x100 x DWORD 153461
0x104 y BYTE 37
0x105 z BYTE 90

.code
main PROC
0x12   push  x
0x17   mov   AH, y
0x1C   mov   AL, z
0x21   call  someProcedure
0x26   inc   EAX
0x2B   mov   EBX, z
0x30   xor   EAX, EBX
0x35   exit
main ENDP
END MAIN
A

It should be 2B, the address of the very next instruction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Given the following partial data segment, what value would I put in the brackets in list[n] to access the 5th element of list? (Ignore the .0000 that Canvas may append to your answer).

.MAX = 50
.data
list  DWORD    MAX   DUP(0)
a     DWORD    25
b     DWORD    15
A
  1. Again, you’d want to add 4*4 = 16.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

For this problem, suppose that you are working with the partial data segment given below. Assume that the memory address of balance is 0x44. What hexadecimal address belongs to the last item in history?

HISTLIMIT = 100

.data
balance   DWORD   0
account   WORD    ?
history   WORD    HISTLIMIT DUP(?)
isValid   BYTE    0
A

110h.

44h starts at decimal 68, and the first item in history will start 4+2 later, or at 74. The last item in history will be 99*2 more than that, which is 110h.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q
Suppose that you are given the following MASM data segment declarations:
.data
idNumber    BYTE     ?
status      WORD     0
list        DWORD    42 DUP(?)
count       DWORD    ?

The address of idNumber is 0x4E00.

What is the hexadecimal address of the 14th element of list? What is the hexadecimal address of count?

A

First, the starting address is 0x4E00, or 19968. Then, you add 1+2, or a starting address of 19971.

list: 0x4E37. To find the 14th element, just add 134 = 20023, or 4E37h.
count: 0x4EAB. To find count, add all 42 elements, 42
4 = 0x4EAB.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Assume that LO and HI have already been assigned as constants with LO

A
First, you can simply subtract directly to find HI-LO+1, and then add LO. 
mov    eax,HI
sub    eax,LO
inc    eax
call   RandomRange
add    eax,LO
mov    x, eax
Second, you can decrement LO, so that when you subtract it, you're actually getting HI-(LO-1), or HI-LO+1.
mov    eax,HI
mov    ebx,LO
dec    ebx
sub    eax,ebx
call   RandomRange
add    eax,LO
mov    x, eax
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q
main PROC
   push OFFSET result
   push x
   call factorial
main ENDP
factorial PROC
   push ebp
   mov ebp, esp
   mov eax, 1
   mov ecx, *****A******
again:
   mul ecx
   loop again
   mov edi, ******B*****
   mov ******C*****, eax
   pop ebp
   ret *****D*****
factorial ENDP
A

A: {ebp+8]. Here, you want to use the actual value of x (since you’re multiplying).

B: [ebp+12]. Here, you want to use the offset of result (b/c edi is normally for that).

C: [edi]. In order to actually save the value in the address of result, you need to use edi as a register index.

D: 8. Because you had pushed only two DWORDs, you only need to get rid of 2*4 = 8.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What hexadecimal number will ESP contain when the “mov eax,1” instruction is executed? The initial address at the top of the stack is 0x0A50.

main PROC
   push OFFSET result
   push x
   call factorial
main ENDP

factorial PROC
push ebp
mov ebp, esp
mov eax, 1

A

Generally, you decrement every time you push something onto the stack. Therefore, since you’ve pushed 4 things onto the stack, you should add 4*4 = 12 to get to the original stack address (including ebp).

Therefore, subtract 16 from 0A50h, and you’ll get 0A40.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Given the following partial data segment, which starts at address 0x0200

.data
list DWORD 1, 2, 6, 24, 120, 720, 5040, 40320
x DWORD LENGTHOF list
y DWORD SIZEOF list

  1. x contains?
  2. y contains?
  3. The address of x is?
A
  1. X contains 8 because the length of the array is 8.
  2. Y contains 32 because the total size in bytes is LENGTHOF (8) * TYPE (4) = 32.
  3. The address of x is 220h because it’ll occur 32 bytes after the starting address of the list.
30
Q

.data
list DWORD 1, 2, 6, 24, 120, 720, 5040, 40320
x DWORD LENGTHOF list
y DWORD SIZEOF list

.code
mov esi, OFFSET list
mov eax, [esi+5*TYPE list]

What does eax contain?

A

720, the 6th element of list.

31
Q

.data
list DWORD 1, 2, 6, 24, 120, 720, 5040, 40320
x DWORD LENGTHOF list
y DWORD SIZEOF list

mov esi, OFFSET list
mov ebx, y
sub ebx, TYPE y
add esi, ebx

What does [esi] contain?

A
  1. Y contains 32, so subtracting TYPE y (4) will give 28. When you add this to the register index esi, you’ll get the very last element when you dereference esi.
32
Q

.data
list DWORD 1, 2, 6, 24, 120, 720, 5040, 40320
x DWORD LENGTHOF list
y DWORD SIZEOF list

.code
mov esi, OFFSET list
mov ebx, y
sub ebx, TYPE y
add esi, ebx
mov al, BYTE PTR [esi+1]
The AL register contains \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
A

Again, we’re accessing the last element of the list. 40320 decimal = 0x9D80, or 00 00 9D 80 in big-endian.

When you add 1 to the start of this element, you’re looking 1 byte in. In the little-endian IA-32, it’s 80 9D 00 00. So the 2nd byte is 0x9D = 157

33
Q

Given the following partial data segment, which starts at address 0x0200 :

.data
matrix DWORD 20 DUP(5 DUP(?))
x DWORD LENGTHOF matrix
y DWORD SIZEOF matrix
pal BYTE ”Hello world.”,0
len DWORD LENGTHOF pal

What does x contain?
What does y contain?
How to access the high-level matrix[8][2]?

A

X contains 100, since that is literally how many elements long the array is.

Y contains 400, since that is the LENGTHOF the array * TYPE.

SInce the start of the address is 0x200 (512 in decimal), you just add the first 8 rows (854) and the next 2 elements (2*4) to get 512+168, or 02A8.

34
Q

.data
MyDouble DWORD 12345678h

.code
mov ax, WORD PTR myDouble

What is being loaded where?

A

5678h is being loaded.

PTR is almost always preceded by a TYPE so that you know what to store something as. Here, you’re storing a DWORD as a WORD, so you just look at the first two bytes.

35
Q

list DWORD 12345678h

What is being loaded?
mov al, BYTE PTR list
mov al, BYTE PTR [list+1]
mov al, BYTE PTR [list+2]
mov ax, WORD PTR list
mov ax, WORD PTR [list+2]
A

In memory, this is stored as 78h, 56h, 34h, and 12h.

mov al, BYTE PTR list: stores 78h into AL.

mov al, BYTE PTR [list+1]: stores 56h into al.

mov al, BYTE PTR [list+2]: stores 34h into al.

mov ax, WORD PTR list: stores 5678h into AX.

mov ax, WORD PTR [list+2] stores 1234h into AX.

36
Q

.data
list BYTE 12h, 34h, 56h, 78h

What is being loaded?
mov ax, WORD PTR list
mov ax, WORD PTR [list+2]
mov eax, DWORD PTR list

A

First, everything in an array is stored in that order. Then, everything gets stored in reverse order in IA-32.

mov ax, WORD PTR list: stores 3412h into ax.

mov ax, WORD PTR [list+2]: stores 7856h into ax.

mov eax, DWORD PTR list: stores 78563412h into eax.

37
Q

Given this code fragment, what is displayed? WriteChar displays the character in the AL register.

pal BYTE ”Hello world.”,0
len DWORD LENGTHOF pal

mov esi, OFFSET pal
mov ecx, len
sub ecx, 2
cld
one: 
   lodsb
   call WriteChar
   loop one
   mov ecx, len
   sub ecx, 2
   std
two:
    lodsb
    call WriteChar
    loop two
A

First, the address of string “Hello World” is moved to esi, and its length moved to ecx (minus 2). Then, the direction flag is cleared (so it goes forward).

One loads and writes the first element into AL, then loops until it’s written all but the null character and the period. Then, it puts len back into ecx (minus 2) and sets the reverse direction flag.

Two loads and writes the last element, then decrements esi until it’s written all but the first letter.

“Hello world.ldorw olle”

38
Q

What is the (string) result of adding the following digit string, digit by digit?

a BYTE ”2458”,0
b BYTE ”6301”,0

A

Literally, just convert each of the digits into their characters and add them up.

2(50) + 6(54) = 104 = h
4(52) + 3(51) = 103 = g
5(53) + 0(48) = 101 = e
8(56) + 1(49) = 105 = i

“hgei”

39
Q

How can you use ptr to contain the offset of another variable?

A

.data
list DWORD 100 DUP(?)
ptr DWORD list

.code

mov esi, ptr
mov eax, [esi] ; eax = @list

The effect of this is the same as mov esi, OFFSET list.

40
Q

.data
list DWORD 100 DUP(?)
ptr DWORD list

What is stored in [ptr]?

A

NEVER try to deference [ptr]!! This is an invalid reference because this is a memory-to-memory location. Get the contents of ptr, and then get the contents of the address stored there.

Instead, move the contents of ptr into another register, and then dereference that register.

mov esi, ptr
mov eax, [esi] ; eax = @list

41
Q

How could you calculate the sum of an integer array using register indirect addressing and a pointer?

.data
intList DWORD 100h, 200h, 300h, 400h
ptrD DWORD intList

A
.code
   mov esi, ptrD
   mov ecx, LENGTHOF intList
   mov eax, 0
L1:
   add eax, [esi]
   add esi, TYPE intList
   loop L1

This loads the address of intList into esi, moves its length into ecx, and the accumulator into 0. Then, to add an integer, just dereference esi, adding the type of that list every time.

42
Q

What specifically do lodsb and stosb do?

A

Lodsb moves byte at [esi] into the AL register. By contrast, stosb moves a byte from the AL register to the memory at [edi].

Both will increment esi/edi (respectively) if the direction flag is 0, and decrement if it equals 1.

43
Q

How do you write the ReadInt program?

A
mov edx, OFFSET string
  mov ecx, MAXSIZE
  dec ecx
  call ReadString
  mov ecx, eax 
  mov val, 0
  mov esi, OFFSET string
  cld
top:
  mov eax, 0
  lodsb
  sub eax, 48
  mov ebx, eax
  mov eax, val
  mov edx, 10
  mul edx
  add eax, ebx
  mov val, eax
  loop top
done:
  mov eax, val
  call WriteDec
44
Q

After ReadInt reads “5738” into val DWORD ?, what is stored in memory at val?

A

0X6A 0x16 0x0 0x0

Because 5738 is 166A in hex, this would normally be stored as 0000166A, but in IA-32 it is stored in reverse order.

45
Q

What is the binary tree method for converting from infix to postfix?

A
  1. Fully parenthesize the infix expression.
  2. Parse the expression left to right, constructing a binary tree
    ( go left
    operand insert
    operator up, insert, right
    } go up
46
Q

How is the FPU stack different?

A

FPU is a “pushdown” stack.

If you push more than 8 valus, the “bottom” of the stack will be lost.

Registers may be referenced by name ST(x).

47
Q

What does FLD MemVar do?

A

It pushes ST(i) “down” to ST(i+1) for i = 0…6. It also loads ST(0) with MemVar.

48
Q

What does FST MemVar do?

A

It moves the top of the stack to memory, leaving the result in ST(0).

49
Q

What does FSTP MemVar do?

A

It pops the top of the stack to memory, moving ST(i) “up” to ST(i-1) for i = 1…7.

50
Q

What does this code do?

.data
varX REAL10 2.5
varY REAL10 -1.8
varZ REAL10 0.9
result REAL10 ?
.code 
FINIT
FLD varX
FLD varY
FLD varZ
FMUL
FADD
FSTP result
A

It initializes the FPU, then creates a postfix expression.

result = (varY * varZ) + varX.

51
Q

How would you calculate the dot product of (6.0, 4.5) and (2.0, 3.2) using this array?

.data
array REAL10 6.0, 2.0, 4.5, 3.2
dotProduct REAL10 ?

A
finit
fld array ;push 6.0
fld array+10 ;push 2.0
fmul ;ST(0) = 12.0
fld array + 20; push 4.5
fld array + 30; push 3.2
fmul ;ST(0) = 14.4
fadd ;ST(0) = ST(0) + ST(1)
fstp dotProduct ;pop into variable
52
Q

Which structure is the following true for? Macros AND/OR/NOR Procedures

______________ have a calling mechanism involving the EIP.

A

Procedures. MACROS are simply placed in line by line, so they don’t need to store any return address.

53
Q

Which structure is the following true for? Macros AND/OR/NOR Procedures

_________ are translated only once, and can be called many times.

A

Procedures. Macros are not called at all, since they are simply replacing wherever their nickname is.

54
Q

Suppose that a program’s data and executable code require 1024 bytes of memory. A new section of code must be added; it will be used with various values 74 times during the execution of a program. When implemented as a macro, the macro code requires 69 bytes of memory. When implemented as a procedure, the procedure code requires 154 bytes (including parameter-passing, etc.), and each procedure call requires 10 bytes.

How many bytes of memory will the entire program require if the new code is added as a procedure?

A

If added as a procedure, you just have to multiply how many times it is called by the procedure call (10 * 74) and add that to the bytes the code itself takes (154).

1024+740+154 = 1918.

55
Q

ppose that a program’s data and executable code require 1024 bytes of memory. A new section of code must be added; it will be used with various values 62 times during the execution of a program. When implemented as a macro, the macro code requires 105 bytes of memory. When implemented as a procedure, the procedure code requires 151 bytes (including parameter-passing, etc.), and each procedure call requires 11 bytes.

How many bytes of memory will the entire program require if the new code is added as a macro?

A

When added as a macro, you just multiply the storage of the macro (105) times how many times it is used(62).

1024 + 105*62 = 7534.

56
Q

What is the first number printed to the screen after this code executes?

main PROC
   push 4
   push 5
   call rcrsn
   exit
main ENDP
rcrsn PROC
   push ebp
   mov ebp,esp
   mov eax,[ebp + 12]
   mov ebx,[ebp + 8]
   cmp eax,ebx
   jl recurse
   jmp quit
recurse:
   inc eax
   push eax
   push ebx
   call rcrsn
   mov eax,[ebp + 12]
   call WriteDec
   Space 2
quit:
   pop ebp
   ret 8
rcrsn ENDP
A

4.

57
Q

What is a good macro to write a string? How do you use it in the code?

A
mWriteStr MACRO buffer
   push edx
   mov edx, OFFSET buffer
   call WriteString
   pop edx
ENDM

.code
….
mWriteStr str1
mWriteStr str2

58
Q

What is a good macro to read a string? How do you use it in code?

A
mReadStr MACRO varName
  push ecx
  push edx
  mov edx, OFFSET variable
  mov ecx, (SIZEOF variable)
  call ReadString
  pop edx
  pop ecx
ENDM

.code
mReadStr firstName

59
Q

Write a MASM macro that calculates x^2 – 1 for its parameter x, and stores the result in memory at the second parameter. The caller passes x by value, and the result variable by address.

A
Quadratic MASM x, y
   Push eax
   Push ebx
   Push edi    ;store the memory address
   Mov eax, x
   Mov ebx, x
   Mul eax, ebx
   Dec eax     ;minus 1
   Mov edi, addr    ;save eax in memory address (edi)
   Mov [edi], eax
   Pop edi
   Pop ebx
   Pop eax
ENDM
60
Q

How do you deal with labels ;in macro?

A

You specify that a label is local!! Otherwise, it’s going to jump to wherever you’ve used the MACRO.

seq macro a, b
   LOCAL test
   LOCAL quit
   mov eax, a
   mov ebx, b
test:
   cmp eax, ebx  ;if a
61
Q

What types of arguments can be used in macros?

A

Any types!! There is no checking for memory, registers, or literals!! As long as it can be used in the statements of the macro, it’s fine.

62
Q

What is a recursive summation procedure?

A
summation PROC
   push ebp
   mov ebp, esp
   mov eax, [ebp+16] ;eax = x
   mov ebx, [ebp+12] ; ebx = y
  add [edx], eax
  cmp eax, ebx
  je quit
recurse:
  inc eax
  push eax
  push ebx
  push edx
  call summation
quit:
  pop ebp
  ret 12
summation ENDP
63
Q

One goal of multiple internal buses is to simplify what process?

A

Bus Arbitration

64
Q

Suppose that you are working with a CISC machine using a 1.6 GHz clock (i.e., the clock ticks 1.6 billion times per second). This particular computer uses MASM-like instructions with the following timings:

add reg, mem 5 clock cycles (i.e., the ADD micro-program has 5 instructions)
add reg, immed 4 clock cycles
loop label 8 clock cycles

Also suppose you’re summing an array:
mov bx, 0 ;initialize sum
mov ecx, MAX_SIZE ;initialize loop counter
mov esi, OFFSET list ;initialize array pointer
more:
add bx, esi ;add current list element
add [esi], 2 ;move pointer to next element
loop more ;auto-decrement ecx, jump to more if ecx ≠ 0

After initialization, how many array elements can be processed in 3.6 ms? Round your answer to the nearest integer. Note that 1 ms. = 0.001 second.

A

Since the clock ticks 1.6 billion times per second, we know that it ticks 1.6 million times per millisecond. Therefore, we also know that it ticks 5.76 million times per 3.6 ms.

add bx, esi - 5
add [esi], 2 - 4
loop - 8

(5+4+8) = 17. Therefore, 5.76m/17 = 338, 824.

65
Q

True or false? Multiprocessor Parallelism (shared memory) usually has lower coordination overhead than Multicomputer Parallelism (distributed memory).

A

True.

66
Q

Which of the following portions of a program can complicate the instruction-caching process? (Check all that apply)

Sequential Execution
Repetition
Recursion
Decision Structures

A
  1. Repetition
  2. Recursion
  3. Decision Structures
67
Q

True or false? Software parallelism is currently much more developed than hardware parallelism.

A

False.

68
Q

Assume you are working with the five-stage pipeline. Suppose that each stage requires 3.8 nanoseconds to complete its task. How many nanoseconds would it take to complete 63 instructions without pipelining? Round your answer to the nearest integer.

A

It would take 63*5 *3.8 = 1197 nanoseconds.

69
Q

An algorithm takes 6.8 seconds to execute on a single 3.4 GHz processor. 58% of the algorithm is sequential. Assume that there is zero latency and that the remaining code exhibits perfect parallelism.

How long (in seconds) should the algorithm take to execute on a parallel machine made of 4 3.4 GHz processors? Round answers to one decimal place.

A

6.8(.58) * (1-.58)*6.8/4 = 4.658 seconds.

70
Q

Assume that you are working with the five-stage pipeline shown in the diagram. Suppose that each stage requires 2.8 nanoseconds to complete its task. How many nanoseconds will it take to complete 77 instructions with pipelining?

A

Since the first four instructions are blank, and the rest finish in that order, it’ll take (n+4) steps to finish n instructions. Therefore, (77+4)*2.8 = 227 nanoseconds.