Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
69 views6 pages

ECE391 Final 8-8-2021 Solution-1

This document contains an exam for the course "Computer System Engineering". The exam consists of 8 problems testing students' knowledge of computer architecture, assembly language, virtual memory, and other related topics. The exam provides multiple choice and short answer questions to assess students' understanding of key learning outcomes for the course.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views6 pages

ECE391 Final 8-8-2021 Solution-1

This document contains an exam for the course "Computer System Engineering". The exam consists of 8 problems testing students' knowledge of computer architecture, assembly language, virtual memory, and other related topics. The exam provides multiple choice and short answer questions to assess students' understanding of key learning outcomes for the course.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

(Date) (Date)

Lecturer: Approved by:


(Signature & Fullname) (Signature, Position & Fullname)

Dr. Trương Quang Vinh Dr. Trần Hoàng Linh


FINAL EXAM Date
Semester/Academic year 2 2020-2021

Course title Computer System Engineering


UNIVERSITY OF TECHNOLOGY - VNUHCM Course ID 407406
FACULTY OF CSE Duration 90 mins. Question sheet code
Student name: ID:
Notes - Can use 1 A4 paper with 2 sides for references
: - Can use pencils for drawing diagrams
- Submit the question sheet together with the answer sheet
(The above part must be hidden when copying for exam)

Problem 1: (L.O.1) (20pts) Answer the following questions

1. x86-8086 processors have:


 40 pin dual in-line package True False .
 32-bit wide data bus True False .
 8-bit register True False .
 20-bit external address bus provides a 1MB physical address space True False .
 The maximum linear address space is limited to 64 KB True False .
 Max CPU clock: 100 MHz True False .

2. Assembly language:
 Native to a processor: executed directly by hardware True False .
 Uses symbolic names to represent operations, registers and
memory locations True False .
 Slightly higher-level language True False .
 Readability of instructions is better than machine language True False .
 Instructions consist of binary: 1s and 0s True False .
 One-to-one correspondence with machine language instructions True False .

3. Find the five-hex-digit address that corresponds to each of these segment : offset pairs
85FE:9ABC => 8FA9C
D9FA:1000 => DAFA0

4. What are the purposes of interrupt:


 Interrupts are useful when interfacing I/O devices with low data-transfer rates, like a keyboard or a mouse, in
which case polling the device wastes valuable processing time.

 The peripheral interrupts the normal application execution, requesting to send or receive data.

 The processor jumps to a special program called Interrupt Service Routine to service the peripheral.

 After the processor services the peripheral, the execution of the interrupted program continues.

Write student’s name and ID into your exam paper Page 1/7
Problem 2: (L.O.5) (10pts) Answer the value of registers after the instruction is executed.

No. Before Instruction After


1 AX: D5 7E mov AX, BX AX: 9F E8
BX: 9F E8 BX: 9F E8
2 ECX: 58 F8 BA D1 dec ECX ECX: 58 F8 BA D0
EDX: 12 5A 8F 7E inc EDX EDX: 12 5A 8F 7F
3 BX: 12 B4 mov BL, 0x24 BX: 12 24
DX: 96 C2 mov DH, 0x48 DX: 48 C2
4 AX: 64 7F sub AX, 800 AX: 61 5F
SF: 0 ZF: 0 OF: 0
5 EAX: 00 96 A3 2B imul EAX, Double EAX: (92 C0) 4D 90 DB 18
Double: 00 F9 65 48 CF: 1 OF: 1
6 EAX: 00 00 CF 23 sub EAX, 53028 EAX: FF FF FF FF
SF: 1 ZF: 0 CF: 0 OF: 0
7 EAX: 35 F8 6C ED and EBX, EAX EAX: 35 F8 6C ED
EBX: 25 DC AA 20 EBX: 25 D8 28 20
8 AX: 8D C4 not AX AX: 72 3B
SF: 0 ZF: 0
9 EDX: 9B F8 28 CB neg EDX EDX: 64 07 D7 35
SF: 0 ZF: 0
10 ECX: 00 EB 89 4F shl ECX, 4 ECX: 0E B8 94 F0
SF: 1 ZF: 0

Problem 3: (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:


{ mov eax, 0
int S = 0; doLoop:
do inc eax
{ cmp eax, ebx
S++; jl doLoop
} ret
while (S < n);
return S;
}

Write student’s name and ID into your exam paper Page 2/7
Problem 4: (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

int Calc(int x, int y, int z) Calc:


{
int t1 = x - y; mov eax, ebx //rval = x
int t2 = z + t1; sub eax, ecx //rval = x - y = t1
int t3 = 10*x; add eax, edx //rval = z + x - y = z + t1 = t2
int t4 = 6*y; imul ebx, 10 //ebx = 10 * ebx = x * 10 = t3
int t5 = t3 * t4; imul ecx, 6 //ecx = ecx * 6 = y * 6 = t4
int rval = t2 + t5; imul ebx, ecx //ebx = ebx * ecx = t3 * t4 = t5
return rval; add eax, ebx // rval = ebx + eax = t2 + t5
} ret

Problem 5: (L.O.2) (10pts) Given the Interrupt Vector Table below.

Determine the address of ISR of a device with the interrupt vector FBh.

Address in table = 4 x 0xFB = 03 EC


(Multiply by 4 since each entry is 4 bytes)
Offset Low = [0x03EC] = 3A, Offset High = [0x03ED] = 54
Segment Low = [0x03EE] = 54, Segment High = [0x03EF] = 7F
Address = 7F54:543A = 0x7F540 + 0x543A = 0x8497A

Problem 6: (L.O.5) (10pts) Given a function as below:

Write student’s name and ID into your exam paper Page 3/7
bool isTwoPower (int n)
{
if (n <= 0)
return 0;
return !(n&(n-1));
}
Rewrite this function in Assembly language (assume that n is stored in EBX, the return value is stored in
EAX):

isTwoPower: cmp ebx, 0


jg greaterThanZero
mov eax, 0
ret
greaterThanZero: mov ecx, ebx
dec ecx
and ebx, ecx
not ebx
mov eax, ebx
ret

Problem 7: (L.O.3) (10pts) Given the data segment DS = 0x6789.


The instruction “mov [0xABCD], EAX” will store the content of EAX in which 20-bit address?

Data Segment = 0x6789


Data Offset = 0xABCD
Data Segment : Data Offset = 0x6789 : 0xABCD
The instruction will store the content EAX in:
Address = 0x67890 + 0xABCD = 0x7245D

Problem 8: (L.O.5) (10pts) Answer the following questions about virtual memory.

Write student’s name and ID into your exam paper Page 4/7
No Question Answer
.
1 Explain the principle of limit checking in Chapter 7, Slide 15:
protection mode. The limit checking is to prevents programs or
procedures from addressing memory locations
outside the segment.
The effective value of the limit depends on the
setting of the G (granularity) flag.
For data segments, the limit also depends on the E
(expansion direction) flag and the B (default stack
pointer size and/or upper bound) flag.
The E flag is one of the bits in the type field when
the segment descriptor is for a data segment type.
2 Consider the memory segments: This instruction causes violation, because the EAX
500 is 32-bit register, ie. 4-byte register. When 4-byte
EAX data move to ES:498, it will exceed the limit
CS 1000
of the segment ES.

ES 1500

2000
SS

Does the following instruction have a


problem? Explain.
MOV [ES:498], EAX

Problem 9: (L.O.5) (10pts) What are memory problems with the following C codes? How to
solve the problems?

No C codes What are problems? How to solve the


. problems?
1 int *my_code; The “my_code” has not been My_code = new int[10];
int i = 10; registered for a new memory
while (i > 0) { allocation
   my_code[i] = i--;
}

2 class student {}; In order to free allocated //After using s


student **s = new student*[100]; memory of an array, free for(int i=0;i<100;i++)
for (int i=0;i<100;i++) each element of the array delete s[i];

Write student’s name and ID into your exam paper Page 5/7
    s[i] = new student[20]; first, then free the array delete[] s;
pointer.
// After using s

delete[] s;

3 void mem_leak() The memory allocation of the delete ptr;


{ pointer ptr has not been
    int* ptr = new int(5); deleted after using
     return;
}
int main()
{
    mem_leak();
     return 0;
}
4 char *my_char = new char[10]; The index of FOR loop char *my_char = new
  for (int i = 0; i < 20; i++) exceeds the memory range of char[20];
{ the pointer my_char.
my_char[i] = 'A' + i;
}

------------------------------------ END ------------------------------------------

Write student’s name and ID into your exam paper Page 6/7

You might also like