Uploaded by truong.nguyen1311

185090 Vũ-Quang-Minh (1)

advertisement
FINAL EXAM
Course title
UNIVERSITY OF TECHNOLOGY - VNUHCM Course ID
FACULTY OF EEE
Duration
1 2021-2022
Semester/Academic year
Date
Computer System Engineering
407406
90 mins.
21/12/2021
Question sheet code
Student name:
ID:
Notes: - Students submit the question sheet together with the answer sheet
Problem 1: (L.O.1) (10pts) Answer the following questions
1. x86-8086 processors have:
 EAX, EBX, ECX, EDX can be accessed by 8-bit registers.
 The two main components of the CPU are the ALU and FPU
 x86 processors are big-endian
 Interrupts typically indicate error conditions internally
 Virtual memory is ensured by paging technique.
True x False
True
False x
True
False x
True
False x
True x False
.
.
.
.
.
2. Suppose that you discover that RAM addresses 00125000 to 00526FFF are reserved for a PC
network adapter. How many bytes of memory is this? How many bits for this address is it?
00526FFF-00125000+1=402000 bytes= 22 bits address
Problem 2: (L.O.1) (10pts)
1. Given the data segment DS = 0x62AE.
The instruction “mov [0x2021], EAX” will store the content of EAX in which 20-bit address?
Address = 0x62AE: 0x2021= 62AE0+2021=64B01
2. Assume that we have the memory content as below.
Address
Content
0x0040
45
0x0041
7B
0x0042
FD
0x0043
21
What are the 32-bit data when we read a double-word at the address 0x0040 with Little Endian mode?
21FD7B45
Problem 3: (L.O.5) (10pts) Answer the value of registers after the instruction is executed.
Write student’s name and ID into your exam paper
Page 1
No.
1
Before
BX: 3D 7E
Instruction
mov CX, BX
After
BX: 3D 7E
CX: 0F 56
CX: 3D 7E
2
EAX: 45 AB E7 00
add ECX, EAX
ECX: 01 5A C2 FE
EAX: 45 AB E7 00
ECX: 47 06 A9 FE
SF:
3
BX: 23 98
mov BH, DL
DX: 75 D6
4
BX: 31 0E
EAX: 01 8A 08 5F
DX: 75 D6
sub BX, 12560
imul ECX, EAX
ECX: 80 F9 65 48
BX: FF FE
DX: E0 15
ECX: (C6840D) 88 86 D5 B8
sub DX, 168
EAX: 01 D8 6C 3A
or EBX, EAX
EBX: 34 21 6F 01
8
AX: 23 FE
EAX: 9B F8 28 CB
EBX: 35 F9 6F 3B
neg AX
AX: DC 02
sar EAX,4
ECX: 01 FE 90 41
sal ECX, 7
ZF: 0 CF: 1 OF: 0
EAX: F9 BF 82 8C
SF: 1
10
ZF: 0 CF: 0 OF: 0
EAX: 01 D8 6C 3A
SF:1
9
ZF: 0 CF: 1 OF: 1
DX: DF 6D
SF: 1
7
ZF: 0 CF: 1 OF: 0
EAX: 01 8A 08 5F
SF: 1
6
OF:
BX: 23 D6
SF: 1
5
ZF: 0 CF:
ZF: 0 CF: 1 OF: 0
ECX: FF 48 20 80
SF: 1
ZF: 0 CF: 0 OF: 0
Problem 4: (L.O.5) (10pts) Write 80x86 assembly language code for the following C procedure:
C procedure
ASM procedure
Assume that S is stored in EAX, n is store in EBX
int my_func(int n)
my_func:
{
int my_func(int n) {
int S = 1000;
int S=1000 ;
while (n ≠ 0)
_asm {
{
mov ebx,n
S--;
mov eax,S
n = n << 1;
L1:
}
Write student’s name and ID into your exam paper
Page 2
return S;
sub
shl
cmp
jne
mov
}
eax,1
ebx,1
ebx,0
L1
S,eax
}
return S;
}
Problem 5: (L.O.5) (10pts) Write 80x86 assembly language code for the following C function.
C procedure
ASM procedure
Assume that rval is stored in EAX; x, y, and z are stored in EBX,
ECX, and EDX
unsigned int Calc(unsigned int x,
unsigned int y, unsigned int z)
{
unsigned int t1 = x + z;
unsigned int t2 = 301*y;
unsigned int t3 = 126*x;
unsigned int t4 = t1 + t2;
unsigned int rval = t4 + t3;
return rval;
}
Calc: unsigned int Calc(unsigned int x, unsigned int y,
unsigned int z)
{
unsigned int t1, t2, t3, t4, rval;
_asm {
mov ebx,x
mov ecx,y
mov edx,z
mov eax,ebx
add eax,edx
mov t1,eax //t1=x+z
imul ecx,301
mov t2,ecx //t2=301*y
imul ebx,126
mov t3,ebx //t3= 126*x
add eax,ecx
mov t4,eax //t4= t1+t2
add eax,ebx
mov rval,eax //rval=t4+t3
}
return rval;
}
Problem 6: (L.O.2) (10pts) Given the Interrupt Vector Table below.
0
1
2
3
4
5
00000
3C
22
10
38
6F
13
00010
.........
00100
00110
.........
00250
8
9
A
B
2C 2A
33
22
21
67
11 3C 32 88 90 16
... ... ... ... ... ...
4A 33 3C 4A AA 1A
44
...
1B
32
...
A2
14
...
2A
C1
...
00
11
...
26
66
...
33
00260
20 4E 00 10 50 88
.........
... ... ... ... ... ...
Write student’s
name
and
into your
paper33
003E0
3A ID10
45 exam
2F 4E
003F0
22
58
...
10
3C
4E C1
... ...
10 20
80
01
4F
...
3F
3C
4F
6
7
C
D
E
F
EE F1
32
25
30
...
33
42 58 30 36
... ... ... ...
3C 4A AA 1A
34
...
3E
66
...
77
F4 C5
... ...
3C 20
58
...
26
4E 20
... ...
20 C1
4F
...
3F
11
...
10
F0
...
28
F4
...
32
22
...
6F
38
...
90
10
...
3A
5A
...
44
38
...
37
10
...
43
4C
...
3A
55 14 54
... ... ...
54 Page
54 37F
4E
88
22
3C
50
21
49
3F
F4
65
Determine the address of ISR of a device with the interrupt vector 9Ah.
Address in the table 4*9Ah= 268h
Offset low=10
Offset high=5A
Segment low=38
Segment high =10
Address= 10380+5A10=15D90
Problem 7: (L.O.5) (10pts) Given a function as below:
short isNumberEven (short n) {
if (n <= 0) return -1;
return ~(n&0x0001);
}
Rewrite this function in Assembly language (assume that n is stored in BX, the return value is stored in AX):
Write student’s name and ID into your exam paper
Page 4
isNumberEven:
isNumberEven:
cmp bx, 0;
jle lageer;
and bx, 0x0001;
not bx;
mov ax, bx;
ret
lageer:
mov ax, -1;
ret
Problem 8: (L.O.5) (10pts) Describe the interrupt processing flow?
When an interrupt is receive is detected, the processor considers whether the interrupt is allowed or not. If
the interrupt is accepted, the processor gets the interrupt vector and saves the current Pc. Then, the
currently running procedure or task is suspended while the processor executes an interrupt handler. When
execution of the handler is completed, the processor resumes execution of the interrupted procedure or
task by loading the Pc.
Problem 9: (L.O.5) (10pts) Answer the following questions about virtual memory.
No.
Question
1 Explain the need of privilege levels.
Write student’s name and ID into your exam paper
Answer
-
The need is to prevent
Users from interfering with one another
Users from examining secure data
Program bugs from damaging other programs
Program bugs from damaging data
Malicious attempts to compromise system integrity
Accidental damage to data
Page 5
2
Explain type checking.
-
3
Assume that a segment has type
checking: data, Read/Write, expanddown. What is type field?
Segment descriptors contain type information in
two places: The S (descriptor type) flag.
The type field.
The processor uses this information to detect
programming errors that result in an attempt to
use a segment or gate in an incorrect or
unintended manner.
E=1
W=1
A=0
Problem 10: (L.O.5) (10pts) What are memory problems with the following C codes? How to solve
the problems?
No.
C codes
1
int *my_table;
for (int i=0; i<50; i++)
*(my_table + i) = 0;
2
char *classroom = new char[10];
for (int i = 0; i < 35; i++)
{
classroom[i] = ‘A’ + i;
}
3
class student {};
student **s = new student*[100];
for (int i=0;i<100;i++)
s[i] = new student[20];
What are problems?
Forget to allocate for
my_table
Allocate only 10 characters
while using the space for 35
characters
Forget to free for the sub
pointer of s
// After using s
delete[] s;
Write student’s name and ID into your exam paper
How to solve the
problems?
int *my_table;
my_table= new int(50);
for (int i=0; i<50; i++)
*(my_table + i) = 0;
char *classroom = new
char[35];
for (int i = 0; i < 35;
i++)
{
classroom[i] = ‘A’
+ i;
}
class student {};
student **s = new
student*[100];
for (int i=0;i<100;i++)
s[i] = new
student[20];
for (int i=0;i<100;i++){
delete[] s[i];
}
// After using s
delete[]s;
Page 6
4
void error_func ()
{
int* ptr = new char(10);
return;
}
int main()
{
error_func();
return 0;
}
Forger to free memory of the
pointer prt delete[] ptr;
void error_func ()
{
int* ptr = new
char(10);
delete[]ptr;
return;
}
int main()
{
error_func();
return 0;
------------------------------------ END ------------------------------------------
Write student’s name and ID into your exam paper
Page 7
Download