Proposed solution for Tutorial Series 2
Exercise 01:
1. Instruction LOAD A, 100: • Fetch: The control unit retrieves the instruction "LOAD
A, 100" from memory at the address indicated by the program counter. • Decode: The
control unit decodes the instruction and determines that it is a data loading operation
into register A from memory address 100. • Execute: The processing unit accesses
memory address 100, retrieves the data, and loads it into register A. • Write Back: The
loaded data is written into register A.
2. Instruction ADD B, A, 200: • Fetch: The control unit retrieves the instruction "ADD
B, A, 200" from memory at the next address in the sequence. • Decode: The control
unit decodes the instruction and determines that it is an addition operation between the
data in register A and the data at memory address 200, with the result stored in register
B. • Execute: The processing unit retrieves the data at memory address 200, adds it to
the data in register A, and then stores the result in register B. • Write Back: The result
of the addition is written into register B.
3. Instruction STORE B, 300: • Fetch: The control unit retrieves the instruction "STORE
B, 300" from memory at the next address in the sequence. • Decode: The control unit
decodes the instruction and determines that it is a data storing operation from register
B to memory address 300. • Execute: The processing unit retrieves the data from
register B and writes it to memory address 300. • Write Back: No write operation is
needed after this instruction.
This exercise illustrates the sequential operation of the execution cycle in the von Neumann
model for a given sequence of instructions.
Exercise 02:
1. Importance of the Operating System:
• Memory Management: The operating system manages the allocation of memory to
running processes, ensuring that each instruction has access to the necessary data and
instructions.
• Process Scheduling: The operating system decides the order of process execution and
manages context switches, ensuring efficient CPU utilization.
• Input/Output Management: The operating system coordinates I/O operations
between devices and memory, allowing instructions to transfer data between memory
and I/O devices.
• Protection and Security: The operating system implements protection mechanisms to
ensure that instructions cannot access memory areas or resources they are not
authorized to.
In summary, the operating system is essential for ensuring the smooth execution cycle of
instructions by providing efficient management of hardware resources and ensuring the
coordination of activities among different components of the system.
Exercise 03:
1. Linking Process: • Linking is the process of combining object files generated by the
compiler to form an executable program. • Its role is to resolve symbolic references
between different object files and to link the functions and variables used in the
program. • Linking also allows for the inclusion of external libraries and functions
defined in other source files.
2. Use of Header Files (.h): • Header files (.h) contain function prototypes and variable
declarations used in the program. • They provide information about the interfaces of
functions and data structures, thus allowing for better organization and modularity of
the source code. • Header files are included in source files using the #include directive,
enabling the compiler to validate function calls and variable references.
3. Commands for Compilation and Linking:
• Compilation of Source Files:
gcc -c main.c -o main.o
gcc -c fonctions.c -o fonctions.o
• Linking to Create the Executable:
gcc main.o fonctions.o -o program
• Explanation of Commands:
• The first command compiles the main.c file into an object file main.o.
• The second command compiles the fonctions.c file into an object file fonctions.o.
• The third command links the object files main.o and fonctions.o to create an executable
program named "program".
In summary, linking is a crucial step in the process of creating an executable program from
modular source files. It involves combining different parts of the program and resolving
symbolic references between them.
Exercise 04:
Translation Information:
In section code 6, addresses 4 bytes relative to code
In section code 12, addresses 4 bytes relative to data
If the linker decides to place the code section at hexadecimal address 012340, and the data
section at hexadecimal address 023220, the module must be modified accordingly. At relative
address 6 of the code section, the start address of the code section, i.e., 012340 (4 bytes), must
be added, and at relative address 012 of the code section, the start address of the data section,
i.e., 023220, must be added. We then obtain the following code, where we include the
assembly text to allow the reader to compare with the previous version.
Exercice 05 :
1. Module Contents:
math_functions.obj: This module contains compiled object code for
mathematical functions such as addition, subtraction, multiplication, and
division. Each function is implemented in machine code.
main_program.obj: This module contains compiled object code for the main
program logic. It may include function calls to the mathematical functions
defined in math_functions.obj.
Contents of math_functions.obj:
- add()
- subtract()
- multiply()
- divide()
Contents of main_program.obj:
- main() function utilizing functions from math_functions.obj
2. Linking Process Steps: a. Identification: The linker identifies all external references in
the main_program.obj module. b. Resolution: The linker locates the corresponding
definitions for these external references in the math_functions.obj module. c. Symbol
Resolution: The linker resolves any conflicts or ambiguities in symbol names. d.
Address Binding: The linker assigns memory addresses to all symbols, both internal
and external, to create a cohesive executable program. e. Relocation: If necessary, the
linker adjusts memory addresses in the code to account for the final memory layout.
Linking Process:
1. Begin the linker.
2. Input the object files: `math_functions.obj` and `main_program.obj`.
3. Analyze the symbols in each module and resolve any external references.
4. Create a symbol table for the entire program, incorporating symbols from both modules.
5. Resolve any conflicts or duplicates in symbol names.
6. Perform address resolution, assigning memory addresses to each symbol.
7. Generate the output file, typically an executable.
3. Detailed Explanation:
The linker reads the object files math_functions.obj and main_program.obj.
It identifies external references in main_program.obj and searches for their
definitions in math_functions.obj.
Once all references are resolved, the linker assigns memory addresses to
symbols.
Any memory address adjustments are made to ensure proper relocation.
Finally, the linker generates the executable program by combining the object
code from both modules.
Detailed Linking Process:
1. Start the linker.
2. Input the object files: `math_functions.obj` and `main_program.obj`.
3. The linker reads the symbol table of each module.
4. It identifies any external references:
- `main_program.obj` references functions from `math_functions.obj`.
5. Resolve these external references by linking them to the correct symbols.
6. Create a combined symbol table for the entire program:
- Include symbols from both modules.
- Resolve any conflicts or duplicates.
7. Assign memory addresses to each symbol.
8. Generate the output file:
- This could be an executable file, a shared library, or another object file, depending on the
linker options.
4. Output: The output of the linking process is an executable program file containing the
main program logic along with the linked mathematical functions. This executable file
can be executed to perform the desired operations defined in the main program.
5. Execution: To execute the generated executable program, the user needs to run it using
an appropriate command based on the operating system. For example, on Unix/Linux
systems, the user can execute the program by navigating to its directory in the terminal
and running ./program_name. On Windows, the user can double-click the executable
file or run it from the command prompt.
This completes the linking process, resulting in an executable program ready for execution.
Exercise 6:
Answer to Q1: The interrupt routine: This interrupt is called every 1/18 seconds
(approximately 0.05 seconds).
The variable "cpt" counts the number of interruptions.
Begin
Save-Context
cpt := cpt + 1
if cpt = 18 then
cpt_sec := (cpt_sec + 1) mod 60;
if cpt_sec = 0 then
cpt_min := (cpt_min + 1) mod 60;
if cpt_min = 0 then
cpt_h := (cpt_h + 1) mod 24;
endif;
endif;
cpt := 0
Display(cpt_h + ':' + cpt_min + ':' + cpt_sec)
endif;
Restore-Context
End
Answer to Q2: The period of IRQ 0 interruption is approximately 0.05 seconds (1/18 s).
Therefore, if the execution of the interrupt routine takes more than 0.06 s, the routine itself
will be interrupted.
Answer to Q3: Mask the interrupts at the beginning of the routine and unmask them at the
end.
Exercise 7:
Answers: Q1) The PIC operates by receiving interrupt requests from hardware devices and
prioritizing them for the CPU. It handles multiple interrupt requests by assigning them
specific interrupt numbers and allowing the CPU to respond to them accordingly. The PIC
communicates with the CPU through dedicated interrupt lines and ensures that interrupts are
serviced in a timely and orderly manner.
Q2) The names of 8 hardware interrupts supported by the PIC may include:
1. Timer interrupt (IRQ 0)
2. Keyboard interrupt (IRQ 1)
3. Serial port interrupt (IRQ 3)
4. Parallel port interrupt (IRQ 7)
5. Floppy disk drive interrupt (IRQ 6)
6. Network interface card interrupt (IRQ 9)
7. Sound card interrupt (IRQ 5)
8. SCSI controller interrupt (IRQ 10)