Date: 10:00-11:50AM, 12/16/2014. Name: Steven Centino Score: ________
I. Multiple-Choice (30%, 2% for each question)
1. (D) 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
2. (A) Which of the following are true about the PUSH instruction?
a. It decrements the stack pointer (by 2 or 4) and copies the operand into the stack at the location pointed to by the stack pointer.
b. It copies the operand into the stack at the location pointed to by the stack pointer, and then decrements the stack pointer (by 2 or 4).
c. It increments the stack pointer (by 2 or 4) and copies the operand into the stack at the location pointed to by the stack pointer.
d. It increments the stack pointer by 1 and copies the operand into the stack at the location pointed to by the stack pointer.
3. (A) What will be the hexadecimal value of AL after these instructions execute? mov al,0CFh and al,2Bh
a. 0Bh b. EAh c. 06h d. none of the above
4. (C) What will be the hexadecimal value of AL after these instructions execute? mov al,3Ch or al,82h
a. 3Eh b. BCh c. BEh d. none of the above
5. (B) What will be the hexadecimal value of AL after these instructions execute? mov al,94h xor al,37h
a. B7h b. A3h c. 3Fh d. none of the above
6. (A&D) Which answer choice shows the correct values of the Carry, Zero, and Sign flags after the following instructions execute? mov al,6 cmp al,5
a. CF = 0, ZF = 0, SF = 0 b. CF = 1, ZF = 0, SF = 0
c. CF = 1, ZF = 1, SF = 0 d. CF = 1, ZF = 0, SF = 1
7. (B) Suppose EAX, EBX, and ECX contained three unsigned integers. Which of the following code excerpts would display the largest of the three integers?
a.
cmp eax,ebx jb L1 mov eax,ebx
L1: cmp eax,ecx jb L2 mov eax,ecx
L2: call WriteInt
b.
cmp eax,ebx jae L1 mov eax,ebx
L1: cmp eax,ecx jae L2 mov eax,ecx
L2: call WriteInt
c.
cmp eax,ebx jnae L1 mov eax,ebx
L1: cmp ecx,eax jnae L2 mov eax,ecx
L2: call WriteInt
d.
cmp eax,ecx jae L1 mov eax,ebx
L1: cmp eax,ebx jae L2 mov eax,ecx
L2: call WriteInt
8. ( ) What will be the final value of ESI when the following code executes?
.data
array SWORD 8,2,3,5,-4,6,0,4
.code
mov esi,0 mov ecx,LENGTHOF array
L1: mov ax,array[esi] cmp ax,0 pushf add esi,TYPE array popf Loopne L1
a. 00000006h b. 00000007h c. 0000000Ch d. 0000000Eh
9. ( ) What will be the final values of CX and DX when the following code executes?
.data
array SWORD 8,2,3,5,-4,6,0,4
.code
mov cx,1 mov esi,2 mov ax,array[esi] mov bx,array[esi+4] cmp ax,3 jae L2 cmp bx,4 jb L1 jmp L3
L1: mov cx,4
L2: mov dx,5 jmp L4
L3: mov dx,6
L4:
a. CX = 4, DX = 5 b. CX = 1, DX = 6 c. CX = 1, DX = 5 d. CX = 4, DX = 6
10. (B) 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
11. (B) Which of the following instructions will divide the unsigned integer in EBX by 8?
a. shr ebx,8 b. shr ebx,3 c. sar ebx,8 d. shl ebx,3
12. (C) 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
13. (C) 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
14. (B) Which of the following blocks of instructions will multiply the contents of the EDX register by 36?
a.
mov ebx,edx shl edx,5 shl ebx,2 add ebx,edx
b.
mov ebx,edx shl edx,5 shl ebx,2 add edx,ebx
c.
mov ebx,4 add edx,ebx shl edx,2 shl ebx,5 add edx,ebx
d.
mov ebx,edx shl ebx,5 shl edx,2 add edx,ebx
15. ( ) Given that EAX contains FFFF80C0h, which of the following would be true after executing the CWD instruction?
a. AX=FFFFh, DX=80C0h b. EDX=FFFFFFFFh, EAX=FFFF80C0h
c. DX=FFFFh, AX=80C0h d. cannot be determined
II. Short Programming Problems (40%, 10% for each problem)
16. Given the following string definition, write a sequence of statements that write the string to standard output. Use a library procedure. str1 BYTE "I love UOG and Computer Science",0 mov dx, OFFSET str1 call WriteString
17. Write statements that use library procedures to generate a single unsigned pseudorandom integer between 0 and 99 and write it to standard output. mov eax, 100 call RandomRange call WriteDec
18. Write a series of instructions that will multiply EAX by 20, using a combination of shift, MOV, and ADD instructions.
Mov ebx, eax
Shl eax, 4 ;2^4=16
Shl ebx,2 ;2^2=4
Add eax,ebx
19. Write a sequence of instructions that divide 15 by 5, using the IDIV instruction. Use the EBX register as the divisor.
Mov eax, -15
Cdq ; extend eax into edx
Mov ebx, 5
Idiv ebx
III. Assembly Programming (30%).
20. a. Chapter 9.7.2 (page 295): Write a procedure named Str_concat that concatenates a source string to the end of a target string….
b. Use screenshots to show the memory dumps of your source, original target, and concatenated target strings.
Original Target:
Concatenated target strings:
Source Code:
You May Also Find These Documents Helpful
-
2. What type of instruction is used to execute different code based on a condition? -Jumps…
- 239 Words
- 2 Pages
Satisfactory Essays -
The second category of fault changes individual instructions in the text segment. These faults are intended to approximate the assembly-level manifestation of real C-level programming…
- 285 Words
- 2 Pages
Satisfactory Essays -
A user has opened a word processor, typed the numbers 123456789, and stored the document as a file called report 1. Which of the following determines, in part, what bits the computer stores in the file to represent the text typed into the report?…
- 957 Words
- 4 Pages
Good Essays -
The process of how the subroutine works within an operating environment is as follows. While the main part of the program is running, there will be a call command sent to the CPU to tell it to stop wherever the program is at, store the W, Z and status along with where in the main program the CPU is at in the stack. Then the main program is cleared from memory and the subroutine is loaded for the CPU to start processing the code. Once the subroutine has finished, the subroutine code is deleted from memory and the CPU will load up the main program back on and will retrieve from stack the stored information (W, Z and status) which will allow the CPU know exactly where it needs to start from.…
- 645 Words
- 3 Pages
Good Essays -
* C. Follows the instructions as they appear in the program, whether they are right or wrong…
- 383 Words
- 2 Pages
Satisfactory Essays -
computation are stored in registers R1 and R2, and the result of the computation is stored…
- 27742 Words
- 111 Pages
Powerful Essays -
To explain this, we should already know that in real life scenarios, stack increases to lower memory addresses, whenever program calls some function, the address of function call instruction is saved in stack as a return for the function. When the function executes, it allocates local variables, including buffers to stack and they are given a lower address than the return address. So, in this scenario the return address is a certain level above the base address for buffers and if the buffer is overflowing, then it is most likely that an attacker can change return address as well. If the return address is changed to some random value, then it will cause segmentation fault, but if the return address is changed to a certain address where some executable code is present, then that may complete attackers intended tasks with the application.…
- 335 Words
- 2 Pages
Good Essays -
C. It will move the contents of temp1 from directory temp to temp1 of current directory and when finished it will erase the contents of temp1 of temp directory…
- 529 Words
- 3 Pages
Satisfactory Essays -
6. A(n) ____ is a value that is written into the code of a program.…
- 2047 Words
- 9 Pages
Powerful Essays -
3) Look at the following pseudocode module header: Module myModule( Integer a, Integer b, Integer c) Now look at the following call to myModule: Call myModule( 3, 2, 1) When this call executes, what value will be stored in a? What value will be stored in b? What value will be stored in c?…
- 1580 Words
- 11 Pages
Better Essays -
What value is assigned to the String variable strSecond when the following code is executes?…
- 2759 Words
- 44 Pages
Powerful Essays -
3. In the forward() command, what does the number argument inside the parentheses do? (1.0 points)…
- 290 Words
- 2 Pages
Satisfactory Essays -
Answer: d. It redirects the output of one command to the input of another command.…
- 1099 Words
- 5 Pages
Good Essays -
C. It will move the contents of temp1 from directory temp to temp1 of current directory and when finished it will erase the…
- 480 Words
- 4 Pages
Satisfactory Essays -
What will be output of following c code? #include int main(){ int *p1,**p2; double *q1,**q2; clrscr(); printf("%d %d ",sizeof(p1),sizeof(p2)); printf("%d %d",sizeof(q1),sizeof(q2)); getch(); return 0; } (a)1 2 4 8 (b)2 4 4 8 (c)2 4 2 4 (d)2 2 2 2 (e)2 2 4 4 Answer: (d) Exp: Size of any type of pointer is 2 byte (In case of near pointer) (5) What will be output if you will compile and execute the following c code? #include int main(){ char huge *p=(char *)0XC0563331; char huge *q=(char *)0XC2551341; if(p==q) printf("Equal"); else if(p>q) printf("Greater than"); else printf("Less than"); return 0; }…
- 1011 Words
- 5 Pages
Good Essays