Title: CSI 1101 Lab
1CSI 1101Lab 11 April 4, 2003
- Romelia Plesa
- rplesa_at_site.uottawa.ca
2Agenda
- A9 discussion
- Assembly language
- Switching Algebra
- Assignment 10 discussion
3Assignment 9
- Any Questions?
- Solution
- http//www.site.uottawa.ca/turcotte/teaching/csi
-1101/assignments/09 -
4Assembly language
- High level language C, Java, etc
- Low level language
- Assembly language
- Close to the instruction set that the hardware
can execute. - Programs are highly dependent on the type of
processor, and cannot be ported to another
computer. - Situations where assembly language is used
- writing drivers
- mix with high level code, the critical parts are
written in assembly language directly to achieve
greater speeds (not so true with modern
compilers) - writing compilers (back-end) necessitates
knowledge of the assembly language of the machine
for which the compiler is written. - Machine code Number representation of
instruction and data
5TC-1101 Instruction Set
6Assembly language
- one instruction per line
- mnemonics replace instruction codes
- instructions can be designated by labels
- allows for comments generally prefixed by
- Format of a line
- starts with an optional label
- followed by the mnemonic of the instruction
- followed by a symbolic name for the operand
(optional, depends on the instruction)
7Machine code
- Reading programs
- Since the instructions and the data are both
represented as numbers (same format) we cannot
distinguish one from the other. - Some instructions have an operand others not,
this makes it difficult to identify the start and
end of an instruction. - Writing programs
- Instructions are using absolute addresses, any
change to a program implies several changes
elsewhere in the program. - Instruction codes are not easy to memorize.
8Machine code vs Assembly language
9ExampleMultiplying two numbers by succesive
additions
- Assembly language
- JMPÂ 1 XÂ Â Â BYTE 06 YÂ Â Â BYTE
12Prod BYTE 00 Cst1 BYTE 01 1Â
CLA           STA Prod    CLA     Â
    ADD Y   2 JZ  6   3Â
LDA Prod   ADD X       STA Prod
4Â LDAÂ YÂ Â Â Â Â Â Â Â SUBÂ Cst1 Â Â Â Â
STAÂ YÂ Â Â Â 5 Â JMPÂ 2Â Â Â 6
 DSP Prod     HLT       Â
- Java code
- public static int mult (int x, int y) Â Â Â int
res 0Â Â Â while (y gt 0) Â Â Â Â Â Â Â res res
x       y y - 1      return res -
- pseudo-code
- 1. set prod to 02. if y 0 goto 63. add x
to prod4. decrement y5. goto 26. halt
10Translating the assembly program to machine code
- There is a 1-to-1 correspondence between assembly
and machine language. - 2 steps process
- Translate the mnemonics to codes
- Translate the symbolic operands to absolute
addresses (need symbol table)
11Symbol table
- Its a table that associates to each symbol a
memory address. - The symbols correspond to the labels of the
statements, variables and constants.
- Mnemonic Opcode
- JMP 15
- CLA 08
- STA 39
- ADD 12
- JZ 15
- LDA 91
- SUB 61
- DSP 01
- HLT 64
-
Symbol Table Label Address 1 00 07 2 00
15 3 00 18 4 00 27 5 00 36Â Â Â Â
6 00 39 X 00 03 Y 00 04 Prod 00
05 Cst1 00 06
12Translating the assembly program to machine code
- Assembly-code Address OpCode OpAddr H-L
JMPÂ 1 00 00 15Â
     00 07 X  BYTE 06 00 03
    06Y   BYTE 12 00 04
   12Prod BYTE 00 00 05
     00Cst1 BYTE 01 00 06    Â
011Â CLAÂ Â Â Â Â Â Â 00 07
08Â Â Â Â STAÂ Prod 00 08
39Â Â Â 00 05Â Â Â Â
CLAÂ Â Â Â Â Â 00 11 Â Â Â Â Â Â 08Â Â Â Â
ADDÂ YÂ Â Â 00 12 Â Â Â Â Â Â 99
      00 042 JZ  6    00
15 17 Â Â Â Â Â 00
393Â LDAÂ Prod 00 18
91 Â Â Â Â 00 05Â Â Â Â ADDÂ
XÂ Â Â 00 21 99 Â Â Â Â
00 03Â Â Â Â STAÂ Prod 00 24
39Â Â Â Â Â Â 00 054Â
LDAÂ YÂ Â Â Â 00 27 91Â Â Â Â Â Â
00 04Â Â Â Â SUBÂ Cst1 Â 00 30 Â Â Â
61Â Â Â 00 06Â Â Â Â
STAÂ YÂ Â Â Â Â 00 33 39
  00 045 JMP 2   00 36
15 Â Â Â 00
156 DSP Prod  00 39
01 Â Â Â Â 00 05Â Â Â Â
HLTÂ Â Â Â Â Â Â Â Â 00 42 64
13Switching Algebra
- Definition
- A Boolean function of N variables (or inputs) is
a function that has N input variables and
produces 1 output. - "Boolean" means the variables and outputs can
have only two possible values - usually these are called FALSE and TRUE, but
because we want to use Boolean functions to do
Binary arithmetic, we equate FALSE with the value
0 and TRUE with the value 1. Â - We will look at 3 different ways of writing down
Boolean functions - a) functional notation, e.g. (X AND Y) OR (NOT
Z) - (exactly like a Boolean expression in Java,
except we use words for the operators, or math
symbols ( ) not the Java operators.) - b) truth tables
- c) logic circuits
- truth table --gt functional notation --gt logic
circuit
14Switching Algebra
- Propositional logic consists of an ensemble of
values, TRUE(1),FALSE(0) and the following 3
operators - AND, OR and NOT
15Truth Tables
- A truth table is a simple way of representing a
boolean function - it is very convenient as long as the function
does not have too many inputs. - A truth table has one column for every input
variable, and one extra column for the function
output. - It has one row for every possible combination of
inputs (2-to-the-N). - In the "input" columns you write down the
particular input values (for the particular
combination/row you're looking at) - in the function column you put the output of the
function given that input.
16Truth Tables
17Using truth tables to prove a property
18Using truth tables to prove a property
19Using truth tables to prove a property
2016 different 2-input Boolean functions
21Logic Gates
- 2-input boolean functions are the building blocks
out of which almost all computer circuits are
made. When we draw these circuits, we have
special ways of drawing the most important
functions
You dont have to memorize the symbols for the
final, there will be an appendix
22Logic Gates
- We imagine that the values flow along wires. So
if we want to make a more complex circuit we just
connect the output of one logic gate to the input
of another. - Example
- suppose we wanted to test if X and Y and Z were
all true. - Assuming we only have 2-input AND gates, we'd
have to use several gates. - We'd break the expression down into (X AND Y)
AND Z. - The AND in brackets would be done with one gate,
and its output would be connected to one of the
inputs of a second AND gate (Z would be connected
to the other input).
X
Y
Z
23Logic Gates Special Symbols
NOR gate
NAND gate
XOR gate
24Rules for Logic Circuits Drawing
- There is one vertical line per input variable
- The gates are connected to those lines with
horizontal lines       - A connection is shown as a dot at the
intersection of a vertical and horizontal line
25Rules for Logic Circuits Drawing
a a.b
a.b
aa.b
b
a
26Exercises
- a) Draw a circuit for the following expression
(a c)(b d)) - b) Simplify the circuit to have only single
variables inverted. - 2. Construct a circuit that implements the
expression AB CD using only NAND gates - 3. Using only NAND gates, construct the circuit
for the expression - A BC
27Assignment 10
- Question 1 For the giving Java code(adding the
odd numbers from 1 to 2N-1 ) - - write the line to line assembly
language program - - transform the assembly language into
machine code - Question 2 1. 3-way jump
- 2. translate the assembly code into machine
code