Course Profile Computer Engineering (ICE4M), Grade 12, University/College Preparation, Combined
Unit 4: Computer Programming
Time: 20 hours
Activity
4.1 | Activity 4.2 | Activity 4.3 | Activity
4.4 | Activity 4.5
Unit Description
Students are
introduced to low-level programming by making comparisons with the more
familiar high-level programming. Concepts students need to understand in order
to compare, trace, and write low-level programs include registers, addressing
techniques, flags, repetition, and decision structures. Since low-level
programming contains no recognisable English words, reflective thinking and
creative problem solving are extremely important. In this unit, students
develop problem-solving and critical-thinking skills with the view of applying
these skills to global issues in the Catholic tradition.
|
Activity |
Time |
Learning Expectations |
Assessment Categories |
Tasks |
|
4.1 |
3 hours |
TF1.01, SP1.01 CGE2b, 3b, 3c |
Application Communication |
Base conversions
among decimal, binary, and hexadecimal number systems and binary arithmetic |
|
4.2 |
3 hours |
TFV.04, TF3.01,
TF3.03, ICV.03 CGE2e, 3c |
Thinking/Inquiry Communication |
Constructs include
assigning values to variables and incrementing numbers |
|
4.3 |
2 hours |
TF3.01, TF3.02 CGE3c, 7e |
Knowledge/
Understanding Thinking/Inquiry |
Techniques include
immediate, direct, and indirect addressing |
|
4.4 |
5 hours |
TF3.01, SP3.02 CGE2b, 3c |
Application Thinking/Inquiry |
Tracing includes
assignment statements, decision structures, and looping structures |
|
4.5 |
7 hours |
TF3.01, TF3.02,
SP3.03, IC1.05 CGE2c, 4g, 7j |
Communication Knowledge/
Understanding Application |
Low-level programs
include the addressing and low-level constructs traced in |
Time: 3 hours
To understand the
low-level programming structures and techniques introduced in this unit,
students study some of the relationships among the decimal-based number system
and the binary and hexadecimal number systems. Students also study arithmetic
operations in the binary number system that are developed and applied to
low-level programming and to signed and unsigned numbers. Students add to their
journals by listing ways that computer software technology can be used for the
common good.
Ontario Catholic
School Graduate Expectations
CGE2b - read, understand, and use written materials effectively;
CGE3b - create,
adapt, and evaluate new ideas in light of the common good;
CGE 3c - think
reflectively and creatively to evaluate situations and solve problems.
Strand(s): Theory and Foundation, Skills and Processes
Specific
Expectations
TF1.01 - describe
how signed and unsigned numbers are represented;
SP1.01 - convert
between decimal and binary numbers;
ICV.01 - identify
issues related to the ethical use of computers;
ICV.03 - describe
the use of computer technologies and their impact in the community;
·
Arithmetic
operations, including place value in base 10.
·
Review arithmetic
operations in binary with the goal of applying these operations to low-level
programming in future activities.
1. The teacher initiates class discussion about
the possible uses of computer software for helping solve global and community
problems. Students write in their journals about how computers can solve some
global and community problems. Ideas are used to develop a Code of Ethics in
Activity 5.
2. The teacher then initiates discussion about
the need for other number systems besides base 10.
3. The teacher demonstrates other numbering
systems.
4. Students develop a table to count in binary
and hexadecimal number systems and add the table to their portfolios.
5. Students compare these systems with the
base-10 number system and establish relationships.
6. The teacher reviews the conversion mechanisms
between base 10, the decimal system, and base 2, the binary system.
7. The teacher reviews the arithmetic operations
of addition and subtraction in binary and introduces the two’s-complement
method of subtracting.
8. Students discuss the advantages and
disadvantages of two subtraction methods.
9. Students pair up to establish the
two’s-complement method’s connection to signed and unsigned numbers.
·
Score student
answers on conversion table chart that relates binary and decimal number
systems (Appendix 4.1.1 – Binary and Decimal Number System Conversions).
·
Students are
assessed on their completed conversion charts (Appendix 4.1.2 – Binary and
Hexadecimal Number Conversions).
·
Students complete
the arithmetic operation question sheet (Appendix 4.1.3 – Adding and
Subtracting in Binary).
·
Students are
assessed on their ability to apply arithmetic operations to signed and unsigned
numbers (Appendix 4.1.4 – Signed and Unsigned Numbers).
·
Provide a
partially completed glossary that students complete on their own or with
assistance from their peers.
·
Appoint a safety
monitor or use the buddy system.
Print
Brey, Barry
B. Intel Microprocessors: Architecture,
Programming and Interfacing. Prentice Hall, 2000.
ISBN 0-13-995408-2
Gaonkar,
Ramesh S. Microprocessor Architecture,
Programming, and Applications with the 8085. Toronto: Collier Macmillan
Canada Inc., 1999. ISBN 0-13-901257-5
Haskell,
Richard E. Introduction to Computer Engineering:
Logic Design and the 8086 Microprocessor. Prentice Hall, 1993. ISBN
0-13-489436-7
Smyth, Graham and
Christine Stephenson. Computer
Engineering: An Activity-Based Approach. Toronto: Holt Software Associates,
2000. ISBN 0-921598-36-X
Websites
Microprocessor Simulator 8085 Ver3.2 – http://www.insoluz.com
Most mathematical,
scientific, and high-level programming is carried out in the base 10 (decimal)
number system. Computers, however, do not use the decimal system but rather the
binary number system. In order to understand how a computer really processes
numbers, binary-decimal conversions must be understood.
Example 1: Convert the binary number 10011000
to base 10. Check your answer using a calculator.
Since binary numbers
have place value, like the decimal number system, the fundamental operation is
multiplication where each successive binary digit is multiplied by 2. Writing
the number 10011000 vertically and multiplying by the appropriate binary place
value gives the following numbers.
1 X 27 = 128
0 X 26 = 0
0 X 25 = 0
1 X 24 = 16
1 X 23 = 8
0 X 22 = 0
0 X 21 = 0
0 X 20 = 0
Total = 152
Therefore 100110002
= 15210
Example 2: Convert the decimal number 56 to
binary. Check your answer using a calculator.
The fundamental
arithmetic operation in example 1 (conversion was from binary to base 10) was
multiplication. Here the fundamental operation is division since the conversion
is in the opposite direction.
|
Divisions: |
|
|
|
|
|
|
|
Remainders: |
0 |
0 |
0 |
1 |
1 |
1 |
The division stops
since the last quotient was 0. The binary answer is found in the remainders
collected in reverse. Therefore, 5610 = 1110002.
Complete the
following chart. Check your answers using a calculator. Add this work to your
portfolio.
|
Question |
Decimal Number |
Binary Number |
|
1 |
255 |
|
|
2 |
|
1100110 |
|
3 |
73 |
|
|
4 |
|
111011 |
|
5 |
5678 |
|
The conversion
between binary and hexadecimal is the easiest conversion. Writing binary
numbers and hexadecimal numbers out in a chart, you will recognize that the
4-bit binary number 1111 coincides with the hexadecimal digit F.
Conversion Chart
|
Decimal |
Binary |
Hexadecimal |
|
Decimal |
Binary |
Hexadecimal |
|
0 |
0000 |
0 |
|
8 |
1000 |
8 |
|
1 |
0001 |
1 |
|
9 |
1001 |
9 |
|
2 |
0010 |
2 |
|
10 |
1010 |
A |
|
3 |
0011 |
3 |
|
11 |
1011 |
B |
|
4 |
0100 |
4 |
|
12 |
1100 |
C |
|
5 |
0101 |
5 |
|
13 |
1101 |
D |
|
6 |
0110 |
6 |
|
14 |
1110 |
E |
|
7 |
0111 |
7 |
|
15 |
1111 |
F |
Converting between
binary and hexadecimal involves grouping all binary digits in sets of 4.
Example 1: Convert 11100001 to hex. Check your
answer using a calculator.
1110 0001, now
grouped in 4s, equals E1 in hex.
Example 2: Convert F5 hex to binary. Check your
answer using a calculator.
F5, translated to
groups of 4 binary digits, equals 1111 0101.
Convert the
following. Add this work to your portfolio.
|
Question |
Hexadecimal |
Binary Number |
|
1 |
A3 |
|
|
2 |
|
1100110 |
|
3 |
FF |
|
|
4 |
|
111011 |
|
5 |
|
1110 |
Example 1: Add the binary numbers 1101 and
1001. Check your answer using a calculator
![]()
Therefore 1101 +
1001 equals 10110. Adding and carrying a digit in binary is the same as adding
in base 10, but remember that the adding is in binary.
Subtracting in
binary can be carried out using two very different methods. The first method is
similar to subtracting in decimal; each column being subtracted has a borrow
from the next column.
Example
2: Subtracting by borrowing. Check your answer using a calculator.
In binary, subtract
1101 from 11101.

Therefore 111012 & 11012
= 100002
This method closely
resembles subtracting in base 10.
Example
3: Subtract the following two numbers using the two’s-complement method. Check
your answer using a calculator.
11101012
– 10111012
Follow the 4 steps:
Step 1 Align the two
numbers.
![]()
Step 2 Complement
the bottom number.

Step 4 Drop
the leading digit and add one. 10010111 becomes
Therefore 11101012 & 10111012 = 110002
Use the
two’s-complement method to subtract the following. Add this work to your
portfolio.
|
a) |
b) |
c) |
d) |
Unsigned Numbers
Binary numbers, as
with base 10 numbers, can either be unsigned (the number is always assumed to
be positive) or signed (the plus or minus sign must be included).
Binary
numbers are stored in a computer in groups of 8 digits. Each digit is a bit and
each group of 8 bits is a byte. Starting from the right, this bit is labelled
bit 0. The bit to the left is bit 1. The next bit is bit 2 and so on to bit 7.
All eight bits are displayed in these examples even when the leading bits are
0. Therefore, the base 10 number 8 is 1000 in binary but is written as 00001000
in byte format. When a byte is written in unsigned format, the number can be converted
to base 10 by the method discussed in Appendix 4.1.1 – Binary and Decimal
Number System Conversions.
Example 1:What is the decimal value of the
unsigned binary number 10011000? Check your answer using a calculator.
Following Appendix
4.1.1, Example 1, 100110002 = 15210. The leading bit,
which is called bit 7, is a 1. The value of that bit is 128 in base 10. The
value changes when the byte is signed.
Signed Numbers
Signed binary
numbers have a plus or minus sign within the number itself. In base 10, a
signed number will have a + or a – sign in front of the number. In binary
signed numbers, the + or – is incorporated into the number using the
two’s-complement method.
If the binary number
is signed, bit 7 (the left-most bit) indicates the sign. The bit 7 is also
referred to as the most significant bit (MSB). If the number is positive, bit 7
is a 0; if the number is negative, bit 7
is a 1.
Example 1: What is the decimal value of the
signed binary number 10011000? Check your answer using a calculator.
Immediately we know
that the signed number is negative since bit 7 (MSB) is a 1. To determine the
magnitude of this negative number, the two’s-complement method is used.
The steps to follow
are:
Take the complement
The complement of
10011000 is 01100111
Add 1
01100111 + 1 =
01101000
Converting 011010002
= 10410.
Therefore the signed
byte 100110002 = -10410
Convert the
following signed/unsigned numbers to base 10. Check your answer using a
calculator. Add this work to your portfolio.
|
Question |
Signed |
Binary Number |
Decimal Equivalent |
|
1 |
Yes |
011111100 |
|
|
2 |
No |
11001100 |
|
|
3 |
No |
11101100 |
|
|
4 |
Yes |
11111111 |
|
|
5 |
No |
11111111 |
|
Time: 3 hours
The hexadecimal
number system discussed in Activity 4.1 is now applied to low-level constructs.
These constructs are developed into simple programs that students compare with
more familiar high-level programming commands.
Students add to their journals on possible ways to use computer software
technology to contribute to global and community needs in the Catholic faith
tradition.
Ontario Catholic
School Graduate Expectations
CGE 3c - think
reflectively and creatively to evaluate situations and solve problems;
CGE2e - use and
integrate the Catholic faith tradition, in the critical analysis of the arts,
media, technology, and information systems, to enhance the quality of life.
Strand(s): Theory and Foundation
Overall
Expectations
TFV.04 - compare
high-level and low-level programming languages;
ICV.01 - identify
issues related to the ethical use of computers;
ICV.03 - describe
the use of computer technologies and their impact in the community.
Specific
Expectations
TF3.01 - describe
the constructs of a simple assembly or machine-level language;
TF3.03 - compare
high-level and low-level commands that perform similar operations.
·
Programming in a
high-level language;
·
Familiarity with
the registers in a microprocessor (from Unit 1).
·
Review the
hexadecimal number system as applied to low-level programming.
·
Choose an
assembler or simulator for programming low-level constructs. The 8085 assembler
is used for all examples. The same assembler is used to develop addressing
techniques in Activity 4.3, to trace low-level programs in Activity 4.4, and to
write low-level programs in Activity 4.5.
·
Review op codes,
operands, and mnemonics.
·
Select simple
low- and high-level constructs for comparison.
1. Students add to their journals regarding
possible uses of computer programming to solve issues both globally and in the
community. Students are given the following topics: the environment, the poor,
people with accessibility needs, and minority groups within the social context.
2. The teacher groups students to discuss the
need (if any) and role of high- and low-level programming. Groups report to the
class.
3. The teacher introduces the constructs of an
assembly or machine-level language, for example constructs to:
· Assign a number to a variable: MVI A F3 (moves F3 into the accumulator).
· Add a number to the accumulator: ADI 0C (adds hex number 0C to the accumulator).
· End a program: HLT (halts the program).
· Add to a register: INR C (adds 1 to register C).
4. Apply the hexadecimal number system to
low-level programming. All commands in low-level programming are translated to
hexadecimal format:
– MVI A
F3 (translates to 3E F3);
– ADI
0C (translates to C6 0C);
– HLT
(translates to 76).
5. Compare high- and low-level programming
languages, such as:
– assigning
a value to a variable (A := 5 translates to MVI A 05);
– incrementing
by 1 (C := C + 1 translates to INR C).
6. Students do practice exercises that relate
constructs of machine level language and their hexadecimal equivalent and
compare these to high level language
7. Students pair up to research career
opportunities relating to low-level programming, such as Intel’s 80XX series,
Motorola’s 68000 series, various PIC microcontrollers, or Programmable Loigic
Controllers (PLCs).
8. Students research the connection between
registers used in low-level programming and the registers discussed in Unit 1.
·
Students complete
and teacher evaluates the chart describing the constructs of a simple assembly
language (Appendix 4.2.1 – Developing Low-Level Constructs);
·
Students complete
and teacher evaluates the assignment comparing high-level and low-level
programming languages (Appendix 4.2.2 – Comparing High- and Low-Level
Languages).
Print
Brey, Barry
B. Intel Microprocessors: Architecture,
Programming and Interfacing. Prentice Hall, 2000.
ISBN 0-13-995408-2
Gaonkar,
Ramesh S. Microprocessor Architecture,
Programming, and Applications with the 8085. Toronto: Collier Macmillan
Canada Inc., 1999. ISBN 0-13-901257-5
Haskell,
Richard E. Introduction to Computer
Engineering: Logic Design and the 8086 Microprocessor. Prentice Hall, 1993.
ISBN 0-13-489436-7
Smyth, Graham and
Christine Stephenson. Computer
Engineering: An Activity-Based Approach. Toronto: Holt Software Associates,
2000. ISBN 0-921598-36-X
Websites
Microprocessor Simulator 8085 Ver3.2 – http://www.insoluz.com
The hexadecimal
number system is an integral part of low-level programming. Since this type of
programming involves no English-type words, all commands are given in
hexadecimal. The exact commands, as in high-level programming, depend on the
language being used. Intel’s 8085 instruction set is used. The first column
lists some assembly-level constructs. The second column gives the translated
(by the assembler) hexadecimal equivalent of the first column. The third column
documents the constructs.
|
Mnemonic Op Code (and operands if
any) |
Hex Op Code (and operands if
any) |
Documentation |
|
MVI A F3 |
3E F3 |
Move the hex value
F3 (i.e., 240 base 10) into the accumulator. This command is 2 bytes long. |
|
MOV A B |
78 |
Transfer the
contents of B register into the accumulator (A register). No operands. This
command is 1 byte long. |
|
ADI 0C |
C6 0C |
Add to the
accumulator the immediate value of 12 in base 10 or C in hex. C must be
written as 0C since all registers are 1 byte in size. This command is 2 bytes
long. |
|
STA F324 |
32 F324 |
Store the
accumulator at hex memory location F324. This command is 3 bytes long. |
|
HLT |
76 |
Break or end the
program. No operands. This command is 1 byte long. |
|
INR C |
0C |
Increment the
value of the C register by 1. This command is 1 byte long. |
|
DCR C |
0D |
Decrement the
value of the C register by 1. This command is 1 byte long. |
|
SUI 02 |
D6 02 |
Decrement the
accumulator (A register) by 2. This command is 2 bytes long. |
Complete the
following chart to relate the constructs of machine-level language and their
hexadecimal equivalents. Add this work to your portfolio.
|
Mnemonic Op Code (and operands if
any) |
Hex Op Code (and operands if
any) |
Documentation |
|
MVI A FF |
|
|
|
MOV A B |
|
|
|
MVI C EA |
|
|
|
INR C |
|
|
|
RAL |
|
|
|
STA 3F24 |
|
|
High- and
low-level languages can carry out similar operations. Individual commands do
not necessarily translate directly but there are similarities. There are
similar commands in high- and low-level languages to accomplish operations,
such as assigning a value to a variable; incrementing a variable by 1;
decrementing a variable by 1; and adding two variables.
The examples
demonstrate how a high-level command can be roughly translated into a low-level
command. All high-level commands are demonstrated in Turing and low-level
commands in Intel 8085 assembly code.
Example 1: Assign a value to a variable.
Solution (Turing):
var A: int
A := 5
Documentation:
A is an integer variable that is assigned a value of 5.
Solution (8085
assembler code):
MVI A 05
HLT
Documentation:
Line 1: MVI moves
the value, here 5, into the accumulator (A register).
Line2: HLT is the op-code
to tell the CPU that this is the end of the program.
Example
2: Assign a value to another variable.
Solution (Turing)
var counter: int
counter := 15
Documentation:
The integer variable counter is assigned a value of 15.
Solution: 8085
assembler code:
MVI C 0F
HLT
Documentation:
Line 1: The value of
15 must be translated into the hexadecimal number system (0F) since we are
dealing directly with the register in the CPU. The 0 is required in front of
the F since the A, B, C, D, E, H, and L registers are one byte long (two hex
digits). In a similar fashion, any number can be moved into these registers.
The number moved into the register is an integer and has a maximum base 10 size
of 255 (FF), the largest number that can be stored in 1 byte. Storing larger
numbers requires connecting bytes together.
Line 2: HLT is the
op-code to tell the CPU that this is the end of the program.
Example
3: Incrementing a variable by 1.
Solution (Turing)
var counter: int
counter := 10
counter := counter + 1
Documentation:
Initially, counter has a value of 10. The integer variable counter on the right
side of the equal sign is evaluated first, so counter equals 11 after being
incremented. The new value of counter
is 11.
8085 assembler code
MVI C 0A
INR C
HLT
Documentation:
Line 1: The value of
10, 0A in hex, is moved into the C register. INR is the mnemonic that
increments
by 1. The C register
is being incremented. In a similar fashion, any of the registers can be
incremented.
Line 2: HLT is the op-code
to tell the CPU that this is the end of the program.
Example
4: Adding two variables.
Solution (Turing):
var total, number : int
total :=3
number := 12
total := total + number
Documentation:
Initially, the variable total has a value of 3. After the variable number has
been added to total, total has a value of 15.
8085 assembler code
MVI A 03
ADI 0C
HLT
Documentation:
Line 1: The value of
3 is moved into the accumulator.
Line 2: ADI adds the
immediate value (0C in hex equals 12 in base 10) to the accumulator. The
accumulator now contains 0F (0F equals 15 in base 10).
Line 3: HLT is the
op-code to tell the CPU that this is the end of the program.
Assignment:
Comparing High-Level and Low-Level Programming Language
Complete the
programs in the chart. Documentation should include the meaning of each command
as well as the context of the command in the complete program. Add this work to
your portfolio.
|
Question |
High-Level Program |
Low-Level Program |
Documentation |
|
1 |
var counter : int counter := 32 counter := counter
/ 2 |
|
|
|
2 |
var total, count :
int total :=3count :=
12 total := total +
count |
|
|
|
3 |
|
MVI A 05HLT |
|
|
4 |
|
MVI C 18DCR CHLT |
|
|
5 |
|
MVI A 03ADI 0CHLT |
|
|
6 |
var initial: int initial := 52 initial := initial
- 2 |
|
|
Time: 2 hours
Several low-level
constructs, such as assigning numbers to variables and performing arithmetic
operations, were introduced in Activity 4.2. A further important construct
needed to write low-level programs is addressing. Addressing techniques that
students use to write low-level programs include direct, indirect, and
immediate addressing. Documenting the addressing techniques is introduced.
Students examine problem-solving techniques with the view of applying Christian
values.
Ontario Catholic
School Graduate Expectations
CGE4f - apply
effective communication, decision-making, problem-solving, time, and resource
management skills;
CGE7e - witness
Catholic social teaching by promoting equality, democracy, and solidarity for a
just, peaceful, and compassionate society.
Strand(s): Theory and Foundation
Specific
Expectations
TF3.01 - describe
the constructs of a simple assembly or machine-level language;
TF3.02 - identify
similarities and differences among memory addressing techniques.
·
Programming in a
high-level language;
·
Familiarity with
the registers in a microprocessor (from Unit 1);
·
Understanding of
basic low-level constructs of Activity 4.2.
·
Develop the
addressing concepts in the context that they will be used to write complete
programs in Activity 4.5.
·
Use the
assembler/ simulator chosen in Activity 4.2 to test all concepts.
1. Students are asked to consider the role they
will play as Catholic leaders in promoting social values. Students add to their
journals by correlating the issues already listed with how they, as computer
engineers, could promote a just and compassionate society.
2. Students then group to discuss the need and
possible methods to identify memory addresses
3. The teacher develops a chart to differentiate
between the four main addressing techniques. For example:
· Direct addressing puts the contents of an address in a register: LDA 1234 (puts the contents of address 1234 in the accumulator).
· Indirect addressing puts the contents of the address of two related registers in the accumulator: LDAX B (loads the accumulator with the contents of the address stored by registers B and C).
· Immediate addressing stores pairs of registers with immediate values: LXI B 1234 (loads the B register with 12 and the C register with 34).
4. Students pair up to discuss
the fundamental difference between the address of a byte of information and the
contents of an address.
5. Students practise addressing
techniques.
·
Students complete
and the teacher evaluates addressing chart (Appendix 4.3.1 – Memory Addressing
Techniques).
Print
Brey, Barry
B. Intel Microprocessors: Architecture,
Programming and Interfacing. Prentice Hall, 2000.
ISBN 0-13-995408-2
Gaonkar,
Ramesh S. Microprocessor Architecture,
Programming, and Applications with the 8085. Toronto: Collier Macmillan
Canada Inc., 1999. ISBN 0-13-901257-5
Haskell,
Richard E. Introduction to Computer Engineering:
Logic Design and the 8086 Microprocessor. Prentice Hall, 1993. ISBN
0-13-489436-7
Smyth, Graham and
Christine Stephenson. Computer
Engineering: An Activity-Based Approach. Toronto: Holt Software Associates,
2000. ISBN 0-921598-36-X
One of the principle
functions of the CPU is to communicate with memory. This communication is a
bi-directional operation (i.e., the CPU must be able to send information to
memory and also retrieve information from memory). To carry out this
communication, the CPU must be able to locate the required piece of
information. The location of a specific byte of information is called the
address of the byte. There are several different techniques that can be used to
locate a memory address. Memory addressing commands include Immediate
Addressing, Direct Addressing, and Indirect Addressing.
Immediate
Addressing
Immediate addressing
involves storing data pairs of registers with immediate values. Registers that
can act in pairs in immediate addressing are: B and C; D and E; and H and L.
Example
1: Load the B register with 12 and the C register with 34.
Solution:
LXI B 1234
HLT
Documentation:
Line 1: Register B
stores the byte 12 and the C register stores the byte 34.
Line 2: HLT is the op-code
to tell the CPU that this is the end of the program.
Example
2: Load the H register with 45 and the L register with 67.
Solution:
LXI H 4567
HLT
Documentation:
Line 1: Similar to
example 1, register H stores the byte 45 and the L register stores the byte 67.
Line 2: HLT is the
op-code to tell the CPU that this is the end of the program.
Direct Addressing
Direct Addressing
assigns the contents of a memory location to a register. Each byte has an
address (location) and a value (the number stored in the location). In our 64K
environment, 65 536 different addresses must be assigned; this requires two
bytes. Addresses are therefore two bytes in length.
Example
1: Load the accumulator with the contents of address 1234.
Solution:
LDA 1234
HLT
Documentation:
Line 1: LDA causes
the assembler to load the accumulator with the contents of address 1234.
Line 2: HLT is the
op-code to tell the CPU that this is the end of the program.
Example
2: Store the contents of the accumulator at address ABCD.
Solution:
STA ABCD
HLT
Documentation:
Line 1: The contents
of the accumulator are stored at address ABCD in memory. The accumulator still
contains the value stored at location ABCD. A copy has been now placed in
memory location ABCD.
Line 2: HLT is the
op-code to tell the CPU that this is the end of the program.
Indirect Addressing
Indirect addressing
involves loading and storing information into the accumulator. The information
is received from register pairs. For example, the command LDAX B takes a total
of two bytes information from the register pair B and C as an address and
stores the contents of that address in the accumulator.
Example
1: Store the contents of register B and C in the accumulator.
Solution:
LDAX B
HLT
Documentation:
Line 1: Indirect
loading command uses registers B and C. If B contains 23 and C contains 45, the
address pointed to is 2345. If the address 2345 contains FD, then FD is loaded
into the accumulator.
Line 2: HLT is the
op-code to tell the CPU that this is the end of the program.
Example
2: Load the accumulator with FF. Store the contents of the accumulator at
memory location 2040.
Solution:
MVI A FF
MVI B 20
MVI C 40
STAX B
HLT
Documentation:
Line 1 will move the
hex value FF into the accumulator.
Line 2: MVI B will
store the first half of the 2040 address, the 20, into the B register.
Line 3: MVI C will
move the second half of the 2040 address, namely the 40, into the C register.
Line 4: STAX will
store the FF from the accumulator into address 2040 in memory.
Line 5: HLT is the
op-code to tell the CPU that this is the end of the program.
Assignment: Memory
Addressing Techniques
For each question,
identify the type of addressing, the registers involved with the type of
addressing, and an explanation of the function of the addressing technique. Add
this work to your portfolio.
|
Question |
Construct |
Addressing Type |
Registers Involved |
Documentation |
|
1 |
STA 2040 |
|
|
|
|
2 |
STAX B |
|
|
|
|
3 |
LXI H 4567 |
|
|
|
|
4 |
LDA A345 |
|
|
|
|
5 |
LDAX B |
|
|
|
|
6 |
LXI D 5432 |
|
|
|
Time: 5 hours
The low-level
structures developed in Activities 4.1, 4.2, and 4.3 are extended to include
repetition and decision. By tracing existing programs, students examine and
explain these structures through documentation. Students list the moral and
ethical importance of proper documentation.
Ontario Catholic
School Graduate Expectations
CGE2b - read,
understand, and use written materials effectively;
CGE 3c - think
reflectively and creatively to evaluate situations and solve problems.
Strand(s): Theory and Foundation, Skills and Processes
Specific
Expectations
TF3.01 - describe
the constructs of a simple assembly or machine-level language;
SP3.02 - trace the
execution of simple machine-level programs;
SP3.04 - document
all programs to a specified standard.
·
Familiarity with
the registers in a microprocessor (from Unit 1);
·
Understanding of
basic low-level constructs from Activity 4.2 and addressing techniques from
Activity 4.3;
·
Tracing low-level
programs from Activity 4.4.
·
Use the
assembler/simulator chosen in Activity 4.2 to trace the execution of all
programs. Examples are demonstrated using an 8085 assembler. The same assembler
should be used for Activity 4.5.
·
Check the
execution of the programs using the assembler’s STEP as well as RUN function.
·
Review op codes,
operands, and mnemonics.
·
Select simple
low- and high-level constructs for comparison.
·
Write several
programs for the students in both high- and low-level languages so they can
compare the two types of programming.
1. Students list the reasons why it would be
important to provide proper and accurate documentation in all their projects
and the consequences for improper or inaccurate documentation. These ideas are
added to their journals.
2. The teacher reviews the registers introduced
in Unit 1
3. The teacher relates these registers to simple
assembly-level constructs, such as:
· MVI A F3 (moves the number F3 into the accumulator)
· STA 2AC4 (stores the contents of the accumulator at address 2AC4)
· STAX B (stores the accumulators contents at the stored in registers B and C)
· LHLD 1234 (loads the contents of location 1234 into L and loads the contents of location 1235 into register H)
· SBI 05 (subtracts 05 from the accumulator)
· ADI 0C (adds the number 0C to the accumulator)
· LDA 1234 (loads the accumulator with the contents of address 1234)
· INC C (increments register C by 1)
· MOV A B (transfers the contents of register B into A)
· CPI 04 (compares the value in the accumulator with 4)
· CMP M (compares the memory location M, which is stored in registers H and L, with the accumulator)
· JM 8002. JM is used in conjunction with the comparison command CPI. If the comparison is true the next command is executed. If the comparison is false the execution jumps to address 8002.
· JC 8011 can be used with the CMP M command. If the contents of the accumulator is greater than the contents of memory location M then execution jumps to 8011.
· JNZ 8002 will jump to the next line if the previous instruction equalled 0. If it is not 0 then the program jumps to 8002.
4. Students pair up to discuss how the jump and
compare commands are related.
5. The teacher demonstrates the use of the step
and run features to trace low level programs using the assembler/simulator in
Activity 4.2. Students practise tracing the execution of low level programs one
step at a time (Appendix 4.4.1 – Tracing Low-Level Programs).
·
In pairs, students
exchange and assess the documentation of a program based on completeness,
clarity of expression, and exactness when explaining the purpose of the entire
program and of each component
Print
Brey, Barry
B. Intel Microprocessors: Architecture,
Programming and Interfacing. Prentice Hall, 2000. ISBN 0-13-995408-2
Gaonkar,
Ramesh S. Microprocessor Architecture,
Programming, and Applications with the 8085. Toronto: Collier Macmillan
Canada Inc., 1999. ISBN 0-13-901257-5
Haskell,
Richard E. Introduction to Computer
Engineering: Logic Design and the 8086 Microprocessor. Prentice Hall, 1993.
ISBN 0-13-489436-7
Smyth, Graham and
Christine Stephenson. Computer
Engineering: An Activity-Based Approach. Toronto: Holt Software Associates,
2000. ISBN 0-921598-36-X
Websites
Microprocessor Simulator 8085 Ver3.2 – http://www.insoluz.com
Tracing low-level
programs requires communicating directly with the CPU through an assembler. The
exact assembler environment depends on the particular assembler being used; the
syntax used is the standard 8085 instruction set. Each low-level program should
be traced line by line. The function of each op code and operand as well as the
purpose of the line in the context of the program should be explained through
documentation. Also, the overall purpose of the program should be stated at the
conclusion of the program. Documentation habits developed here should be
included in all programs being written.
Example
1: Write a low-level program that will subtract 23 from FF.
Solution:
MVI A FF
SBI 23
HLT
Documentation:
Line 1: MVI moves
the immediate value given, here FF, into the accumulator. This value of FF will
be used in the next operation.
Line 2: SBI
subtracts the immediate value, here 23, from the accumulator.
Line 3: HLT halts
the program, indicating the end of the program.
The value in the
accumulator is now DC.
Note: All low or high
are always assembled somewhere in memory. In the previous examples the exact
address in memory has not been stated. Question 3 starts with, 8000 MVI A 00.
Address 8000 has been selected as the staring address to assemble the program.
The other addresses may be calculated manually but the assembler being used
will do the counting of bytes for you. The addresses must be stated explicitly
in programs that require decision or repetition structures. The addresses have
been left off in programs not requiring repetition or decision for ease of
reading.
Trace the program
by writing complete documentation for each of the following.
Question 1: Load
the accumulator with 5510. Add 5 to this number and store it at
location 4556.
Solution:
MVI A 37
ADI 05
STA 4556
HLT
Documentation:
Question
2: Load the contents of two memory locations into registers C and D. Add the
contents of these registers and store the answer at address 9ABC.
Solution:
LDA 1234
MOV C A
LDA 5678
MOV D A
ADD C
STA 9ABC
HLT
Documentation:
Question
3: Document each line of the program and then state the overall purpose of the
program.
8000 MVI A 00
8002 INR A
8003 CPI 05
8005 JM 8002
8008 HLT
Documentation:
Question
4: Document each line of the program and then state the overall purpose of the
program.
8000 MVI A 01
8002 MVI B 20
8004 MVI C 30
8006 STAX B
8007 INX B
8008 INR A
8009 CPI 06
800B JM 8006
800E HLT
Documentation:
Question
5: Document each line of the program and then state the overall purpose of the
program.
8000 MVI A 00
8002 MVI B 08
8004 MVI C 06
8006 ADD B
8007 INR B
8008 DCR C
8009 JP 8006
800C STA 8100
800F HLT
Documentation:
Question 6: Document each line of the program
and then state the overall purpose of the program.
LHLD 1234
MVI A 00
ADD H
SUB L
HLT
Question
7: The numbers presently stored in memory locations 0251 to 025B are sorted in
ascending order. Document the program.
8000 MVI B 0A
8002 LXI H 0251
8005 MOV C B
8006 MOV A M
8007 INX H
8008 CMP M
8009 JC 8011
800C MOV D M
800D MOV M A
800E DCX H
800F MOV M D
8010 INX H
8011 DCR C
8012 JNZ 8006
8015 DCR B
8016 JNZ 8002
8019 HLT
Documentation:
Time: 9 hours
After examining and
tracing many structures, students write low-level programs. The structures that
are included in their programs include register commands, arithmetic operations,
addressing techniques, repetition, and comparison. Unit 4 concludes with a
summative assignment in which students write low-level programs. Students
complete a personal Code of Ethics based on their journal entries in the
previous activities.
Ontario Catholic
School Graduate Expectations
CGE 2c - present
information and ideas clearly and honestly and with sensitivity to others;
CGE4g - examine and
reflect on one’s personal values, abilities, and aspirations influencing life’s
choices and opportunities;
CGE7j - contribute
to the common good.
Strand(s): Theory and Foundation, Skills and Processes
Specific
Expectations
TF3.01 - describe
the constructs of a simple assembly or machine-level language;
TF3.02 - identify similarities
and differences among memory addressing techniques;
SP3.03 - write
low-level programs;
IC1.05 - communicate
the results of projects effectively both orally and in writing.
·
Understanding of
basic low-level constructs from Activity 4.2 and addressing techniques from
Activity 4.3;
·
Tracing low-level
programs from Activity 4.4.
·
Review all
low-level constructs from Activities 4.1 to 4.4.
·
Select questions
for summative assignment using the low-level constructs from Activities 4.1
through 4.4.
1. Students collate the journal entries from the
previous activities into a personal Code of Ethics. This Code of Ethics is word
processed and included in their portfolio.
2. Students group to summarize the low-level
commands from the previous activities and include an example for each command.
Students include the summaries in their student portfolios.
3. Students write several low-level programs by
using the above structures as guides.
4. Students work in pairs to discuss and write a
brief report on the advantages and disadvantages of low-level programming.
·
Students write
and then submit complete programs, including documentation, for the questions in
Appendix 4.5.1 – Writing Low-Level Programs. Assessment could be split 20%
design, 50% content, and 30% documentation.
·
Grouped in pairs,
students design their own low-level programming question and exchange with a
partner who will develop a complete solution.
·
Include
enrichment-type assessment, such as questions 10 and 11 from Appendix 4.5.1 –
Writing Low-Level Programs.
Print
Brey, Barry
B. Intel Microprocessors: Architecture,
Programming and Interfacing. Prentice Hall, 2000. ISBN 0-13-995408-2
Gaonkar,
Ramesh S. Microprocessor Architecture,
Programming, and Applications with the 8085. Toronto: Collier Macmillan
Canada Inc., 1999. ISBN 0-13-901257-5
Haskell,
Richard E. Introduction to Computer
Engineering: Logic Design and the 8086 Microprocessor. Prentice Hall, 1993.
ISBN 0-13-489436-7
Smyth, Graham and
Christine Stephenson. Computer
Engineering: An Activity-Based Approach. Toronto: Holt Software Associates,
2000. ISBN 0-921598-36-X
Writing low-level
programs (e.g., Intel 8085) requires communicating directly with the CPU
through an assembler. Write complete programs with documentation to answer the
following questions. The documentation should be written in sentence form where
the commands themselves are clearly explained. As well the documentation should
explain the context of the commands in the overall program. Add this work to
your portfolio.
1. Add the hex number AB with 12.
2. Load the accumulator with 84 and then move
that value to the B register.
3. Load registers L and H with two numbers.
Subtract the contents of register L from H and store the answer in the
accumulator.
4. Load the accumulator with base 10 number 55.
Add 5 to this number and store it at location 4556.
5. Load the contents of two memory locations
into registers C and D. Add the contents of these registers and store the
answer at address 9ABC.
6. Add the hex values from 8 through E. Store
the answer at memory location 8100.
7. Add the 10 numbers that are stored in 10
consecutive memory locations starting at location 3000. Store the answer at
memory location 4000.
8. Move the 5 bytes that are stored at memory
location 0250 through 0254 to memory location 0300 through 0304.
9. Write a program that will store two hundred
and fifty-six Fs in 256 consecutive memory locations.
10. Take the numbers presently stored in memory
locations 0251 to 025B and sort these values in ascending order
11. Take the numbers presently stored in memory
locations 0251 to 025B and sort these values in descending order.
Overview | Unit 3 | Course Profiles Main
Menu