Postpone A. p. 103-4, Examples
3.17 (and the last one of example 3.18. The first two are repeats
from 3.17).
Convert each of these binary numbers into an unsigned decimal number
and
into a signed decimal number. Observe when the sums "go wrong"
and
check that the C and V flags work correctly. Note a 6-bit cell
can
represent 64 different numbers.
For example, look at the last addition of
Ex.
3.17:
convert binary values to unsigned: 38+ 34=8
Unsigned:
38+34
should = 72, too large. Answer 8 = 72 mod 64, C flag is set.
Signed: -26
+
-30 should = -56, out of range. Answer 8 = -56 mod 64, V flag is
set.
Textbook p. 136, 19c,f , 20
d,e.
Also translate
each binary number to its unsigned and signed decimal equivalent.
DO B. Run the program (day 8) to examine negatives, using these inputs: 65536, 65537, 65538, 40000, 85536, -40000. For each, examine and record the (dec) value in the CPU just after the number is loaded into A. Also record the first output number, which is supposed to be the "echo" of the input number. Check that the decimal--binary converter used by PEP8 is doing arithmetic mod 216 = 65536 on the input, using the "Signed" two's complement representation for output.
Program 2, DueQUIZ today
.
Notes: Signed numbers, continued.
No matter how many bits: (example, 8 bits) Most
negative number: 1000 0000 (leading 1, rest 0's), -1 = 1111 1111
(all 1's), 0 = 0000 0000, Biggest positive number: 0111 1111 (leading
0, rest 1's) In Hex,(if cell is multiple of 4 bits) Most neg. =
80.....0, -1 = FFF...F, Biggest positive = 7FF...F.
In an n-bit cell, the number of different items which can be
expressed is 2n .
If you keep adding 1, the numbers "roll over" from 1111 ...1111 to
0000...0000.
In effect, you are doing arithmetic mod 2n.
(The
unsigned integers are the "remainders" after dividing by 2n
. ) The text uses the number line to demonstrate this: here's the
"clock" version. n = 4, 2n = 16.
All the numbers in the same place ( they are called congruent
mod 16) differ from one another by (a multiple of) 16. So
you can find directly from the decimal representation of a number
what
its representation will be in an n-bit cell, in unsigned or signed
form,
by subtracting (or adding) 2n till you get in the correct
range.
Got to here.
OVERFLOW: When a calculation
results in a number that
is
out of range in the representation you are using.
(The number goes further around the "clock" than the single circle
of numbers you're allowed.) Look at 4-bit.
C flag is set on unsigned overflow.
V flag is set on signed overflow.
* ok x wrong:
Un
Sign
Un Sign
0111
carry 1110
0011
3
3 1010
10
-6
+0111 +7
+7
+0111 +7 +7
0c 1010 10* 1v -6x 1c
0001 1x 0v 1*
Un
Sign
Un Sign
1010
carry 1100
1010 10
-6
1101 13 -3
+1011 +11 -5
+1100 +12 -4
1c 0101 5x 1v 5x
1c 1001 9x 0v -7*
Find a sum with 0c and 0v: 3+4
Find one with (pos + neg), with c0. (Can pos+neg ever overflow?): -7+2=-5,
9+2=11
Computer loads the Carry bit from carry out from MSBit.
How does it set V? Set iff carry IN to MSBit and carry OUT from
MSBit are different.
(Takes a little thinking...)
(For human: did pos+pos=neg? did neg+neg= pos?)
-p-p-p-p-p-p-p-p-More
PEP-p-p-p-p-p-p-p-p-p-p-p
Branching, unconditional, again:
BR 0x000A puts 000A into the Program Counter, so the
next instruction to execute is the one at address 000A!
Put your Data first and branch around it; then when you add or delete
instructions, your data addresses won't change (hurrah!)
Immediate addressing p.201-3, addressing mode
specifier 000,
assembly language i
Direct addressing: the operand specifier was the address
of
the operand. Oprnd = Mem[OprndSpec]
Immediate addressing: the operand specifier is
itself the operand. Oprnd = OprndSpec
LDA 0x001B, d ; loads the word at memory location 001b into A.
LDA 0x001B, i ; loads the
word 001B into A.
Saves computer work: Direct
addressing:
Fetch the operand specifier. Then fetch the word at that address,
load it into A.
Immediate
addressing: Fetch the operand specifier. Load it into A.
Saves programmer work: Adding 1 to register
A? AddA 1, i .
Don't have to store data with .word 1.
Charo 0x0041, i == Charo 0x41, i == Charo 'A', i == 50 0041 outputs A.
Charo 0x0A, i outputs
linefeed.
Easier for now for outputting a string than making all the individual
byte addresses.
' ' character data. Contains 1byte (e.g. for
Charo)
LDA 'B',
i loads 0x0042 into
A. (fills in upper byte with 0's.)
Immediate operands are like Const values in C++. Cannot
change as the program runs.
Also, C++ shows its C lowlevel origins:
a++ Assembly level,
AddA 1, i
Fig. 5.11 p. 202, examples of immediate addressing.
BR 0x0009 == BR 0x0009,
i
Branching usually uses immediate addressing, so that's default if no
mode given.
| To Sievers Home Page |
CS225-Fall06/Daya9.htm
|
|