Objective 1 Distinguish between true and false statements concerning the terms which relate to Part 3 in the index for this block, or explain the terms in your own words.
Objective 2 Understand and use bitwise operators in a C program.
Bitwise operators allow individual bits of an integer or character variable to be manipulated, for example the following program segment:
| int a = 0x000F, b = 0x0055, c; |
| c = a & b |
In C, a constant beginning with 0x is taken by the comiler to be a hexadecimal number. So the statement c = a & b will perform the AND operation between the equivalent bits of the variables a and b.
SAQ 2 a) Write down the single C statement that will have the effect of setting bit 2 of a char variable called out_data to 1. (The least significant bit is bit 0).
out_data = out_data | 0x04;
b) Write down the single C statement which uses the exclusive OR bitwise operator to find the 1's complement (i.e. to invert each bit) of an int variable called light_data.
light_data = light-data ^ 0xFFFF;
Objective 3 Understand and use simple pointers in a C program.
Pointers allow variables to be accessed via their address as well as simply by their name. They can do two main things:
| 1 | change the value of an argument variable rather than just use its current value |
| 2 | return more than one value |
SAQ3 a) You have decided to use a pointer to an integer varaible in a C program and to call the pointer point. How should point be defined.
int *pointer;
b) You want point to hold the address of a variable called first_number. What C statement would you use to give point this value?
point = &first_number;
Objective 4 Understand how strings and arrays are referred to in a C program.
Arrays and strings are always referred to by a pointer to the address of the first element of the array or string.
SAQ5 a) Below is an incomplete function which will take an array of integers as its first argument and the nunber of integers in the array as the second argument. The function then adds 2 to each of the values in the array and replaces the array contents by these two values.
| array_add | (int *array_ptr, int) | |
| { | ||
| int i; | ||
| for (i=0, i<size; i++) | ||
| { | ||
| *array_ptr = *array_ptr + 2; | ||
| array_ptr++; | ||
| } | ||
| } |
b) Write down the prototype for the above function.
void array_add (int*, int)
c) If the above function is to be used to operate on an array called numbers which has 10 elements in it, write down the C statement that will do this.
array_add(numbers, 10);
Objective 5 List the main types of applications where assembly language is used.
There are three main types of applications where low-level programming or program segments is used. They are:
| 1 | Applications where the execution time of a section of program needs to be carefully controlled and known |
| 2 | Applications where the size of the program and hence the amount of main memory required has to be minimised |
| 3 | Subroutines or program segments that interface a high-level language program with an input-output device. Such routines are called driver routines. The BIOS (Basic Input Output System) part of an operating system contains some of these. |
Objective 6 Explain why some instructions take longer to execute than others.
The factors which determine the execution time of a program segment is the sum of time required for the execution of each individual instruction in the segment. The execution time of each individual instruction depends on tow factors
| 1 | The speed of the operation of the processor, which in turn depends on the rate of clock pulses arriving at the clock inpt |
| 2 | The number of pulses of the processor clock required to execute the particular instruction |
Different sequences require different numbers of clock pulses. For example, a one-word instruction will take less time than a two word instruction. Also, a jump instruction may take longer because as the processor has to locate the jump address and move it to the instruction pointer.
Objective 7 Given the execution times of instructions, calculate the execution time of an assembly-language program.
SAQ7 Calculate the execution time of the program segment for the 8051 microcontroller.
| load direct A 0200 |
| add immediate A 0001 |
| store direct A 0210 |
The program segment will take three cycles, which is 36 clock pulses.
If the clock frequency is 3.6 MHz, then the time for one clock pulse is 1(3.6 x 10^6). So the execution time is 10 millionths of a second.
Objective 8 Given the format of instructions, calculate the memory requirement for an assembly-language program.
Objective 9 Make simple modifications to a given segment of a low-level program so that it performs a specified function.
Objective 10 Describe the basic form of an assembly-language statement.
An assembly language statement contains 4 parts - an optional label; an operation; an operand; and an optional comment.
Another type of statement is an assembler directive. It's a control statement to be used by the processor, e.g. to set the address of the first of the memory locations to be loaded (origin directive); to define explicitly the value of a name (equate directive); to bring in other sections of the program (include directive); to reserve memory locations ( data byte and data word directives); to mark the end of an assembly-language program (end directive).
Objective 11 Describe the effect of, or answer questions about, a small segment of an assembly-language program given a description of the instructions used.
SAQ10 What is the effect of the following 8086 assembly-language statement?
ADD BX,200H
The instruction is an immediate one which will add 2000(hex) to the contents of the BX register and store the result in the BX register.
SAQ11 What values will the assembler assign to the names NUM1, NUM2 and NUM3 in the following assembly-language program segment?
| ORG | 3000H | |
| NUM1 | EQU | 50 |
| NUM2 | DB | *HELLO* |
| NUM3 | DW | 2000H |
NUM1 is 50, NUM2 is 3000, and NUM3 will be 3005.
Objective 12 Modify a small assembly-language program or write down the equivalent program in a different processor's assembly language given a description of all the required instructions.
Objective 13 Describe the types of assemblers available, and suggest the type required for a given application.
An assembler takes assembly-language (called the source code) and produces the actual op-codes and data, called the object code. An assembler can also produce a list of the original assembly-language program with the resulting op-code and addresses by the side. This is called a listing.
A resident assembler produces machine code for the same computer as the one that the resident assembler itself is designed to be executed on. A cross-assembler produces object code for a different computer. Assemblers usually produce object code whose precise execution addresses in memory can be defined later. This means that large programs can be developed in smaller sections.
Objective 14 List the basic steps required to implement a given function in sufficient detail to enable an assembly language program to be written containing one instruction.
In order to write an assembly-language program, it is necessary to have a detailed knowledge about the actual microprocessor used, in terms of its registers and instructions. In addition, the assembly-language programmer needs to have a knowledge of the hardware structure of the computer system that the program is to be executed on. The kind of things to be known, include the memory content (ROM, RAM and their address ranges) and the various input-ouput devices and how they are accessed. Assembly-language programs are generally not portable.
Objective 15 Describe the processes that occur between typing in a high-level language program, and its execution (compiling, linking and loading).
The linking stage takes a number of object-code modules which have been produced by a complier from a high-level lnguage program, or by an assembler from an assembly-language program. From them it produces a complete object-code program.
The loading stage takes a complete object-code program, loads it into memory and starts it running. The loader will first find an area of memory large enough to hold the program and any associated data space, and will then relocate the program to this area of memory and copy the resulting program into the memory ready for execution.
Objective 16 State the limitation on an assembly-language program if it is to be executed without the use of a linker or loader.
SAQ17 What assembler directive must an assembly-language program contain at the start so that an assembler can produce a complete and ready-to-execute object-code program?
The program must start with an origin directive, say ORG 1000H, to tell the assembler the address of the first iinstruction.
Objective 17 Given a specific example, determine what parts of an object-code module need to be declared as public and/or external.
In order for a linker to be able to combine the various object-code modules, each module must include or contain a list of the names of the program segments it contains. These names are known as public names. The object-code modules must also include or contain a list of names of the program segments that are required by any of the program segments in the module. These are known as external names.
SAQ18 An object module contains three functions (subroutines) named AVE_CALC, MAX_CALC and MIN_CALC. These functions require the use of modules contained in a maths function library called FLOAT_ADD and FLOAT_DIV. List the public and external names in this module.
Public names: AVE_CALC, MAX_CALC, MIN_CALC
External names: FLOAT_ADD, FLOAT_DIV
Objective 18 Describe and explain the reason for the contents of a relocatable object-code module.
A file with the extension EXE indicates that it is a relocatable object-code program, which is ready to be loaded and executed.
There are two parts to an EXE file:
| 1 | control and relocation data |
| 2 | the machine-code program (the actual instructions in binary format) |
The control and relocation data is held in a section called the header which is at the start of the file. The header includes information to give the operating system all the information it needs in order to perfom the relocating loader functions.
SAQ19 In a relocatable object module, what parts of the machine-code program need to be tagged in some way and why?
Any non-relative jump or subroutine call address have to be tagged so that the addresses can be adjusted during the relocation process.
Objective 19 Describe the loading and executing process for a relocatable object module.
The loader will find a free area of memory, relocate the machine code file to this area, copy the final complete program into memory, set any register initial values and then execute a jump to the first instruction in the program, thus causing the program to be executed.
A loader needs, in addition to the actual machine-code program, information on:
the addresses which require adjustment during the relocating process
the size of memory required for the program and any associated data and stack space
any register intial values and the start address of the program