HW Day 7, Due
Monday
Day 8
Quiz Wednesday, closed book: see
notes below.
A) Use the program below comparing the Word and Byte ops. Change
the memory words to ABCD and EF12, and predict what the entries in the
6 bytes of used memory will be after the program has run. Then
run
it and check your results.
B, C, D Copied from last time
B) a) Make a program that will: study the
behavior of ASL and
ASR, including the flags. (ASR shifts right: fills in on the left
with 0 if MSB was 0, with 1 if MSB was 1. Check both kinds of
numbers)
b) And study the logical
ops And Or Not. (All in the same program? or not; your
choice). Check that
the ops and the flags operate as they are supposed to.
Hand in: Listing(s), What
numbers you operated on, the resulting numbers, and the resulting
flags.
C) CR(carriage return) and LF(line feed) are both used as
paragraph-enders by various programs. (Properly, you should need
both,
CRLF.) How does PEP8 interpret these when outputting?
What does PEP8 use if you use \n? Does it interpret any other of
the Ascii "control-characters"
as actions, and/or what does it do when you output them?
Write a simple program to find out: Fill some memory locations
with Ascii characters, interspersed with
the Hex bytes (use\x as p.194) for these: CR (Carriage return),
LF(linefeed), BS (backspace), HT (tab), VT (vertical tab), FF
(form feed= new page), DEL (delete). (Use the Ascii table
list I gave you, or the book's.)
Then write CHARO's for your whole list, step thru the program, and
write up what you found.
D) Program W (Day 6, bottom) has a VonNeumann bug , pp 172-3 (assuming you can get it to assemble!) Trace it and describe the bug.
E) Load (From CH05 folder, in PEP folder) Fig. 5.6, p.
196.
and run it, tracing it for each run, noting the memory changes at the
CHARI's.
--Use Batch input and the following inputs (they explore just
right,
too little, too much input situations):
Delete everything from the input window before each new reload and run.
a) Type ab (don't hit the <Enter>
key)
b) Type x (don't hit the <Enter>
key)
c) Type pqrs (don't hit the <Enter>
key)
d) Type <Enter>. type vw
For each run, write down and hand in:
The hex contents of the two memory locations 0xD and oxE, and the
contents
of the Output screen.
--Now repeat it with Terminal I/O. Don't try to trace. Just
reload and run. Where it says (don't hit the <Enter>
key) above, you will have to hit <Enter> or nothing
will happen.
HW questions?
Quiz Wednesday, closed book:
-- How many different numbers can be represented using an x-bit cell?
-- Hex<-->binary conversion
-- Binary--> decimal conversion (unsigned only, no more than 8
bits)
-- Decimal-->binary conversion (unsigned only, no more than 8 bits)
--Making a mask to force a certain bit or bits, leaving others
unchanged.
--Translating an instruction from binary to Assembly Language (given
Figures A7, A8)
Review instructions so far:
--Load from memory to register: LOADR,
LDBYTR
--Store to memory from register:
STORER, STBYTR
--1-operand instructions: Manipulate data within one
register:
ASLR, ASRR, NOTR
--2-operand instructions: Register OP memory location,
result placed in Register:ADDR, SUBR,
ANDR,
ORR
--input/output: to or from a Memory location only: CHARO
--Flow of control: STOP
All flag activity documented Appendix pp. A7-8, Fig A-ll
ORR oprndspec:
p OR q =1 (true) when one or both of p and q are 1,
=0
only if both are 0
(Think p+q with no carries & 1+1=1.
"Exclusive or", "XOR", one is 1, but not both are 1, is p+q with no
carries.
XOR is not in this instruction set).
Masking: To force certain bits to
become 0 or 1, leaving others unchanged.
(A<-->a,
"3"<-->3)
| Force to 0 | Force to 1 |
| 0<--b AND 0
b<--b AND 1 |
1<--b OR 1 b<--b OR 0 |
Memory addressing: (more) Every
Byte
has an address, but for most operations, we think of the memory in Word
(2-byte) size chunks, because that's what move in and out of registers,
mostly, and that's the size we store numbers in.
Weirdness. LDBYTE takes the most significant
byte of the Word at the address and loads it into the least
significant
byte in the register. STBYTE takes the least significant
byte
in the register and stores it in the most significant byte of
the
Word at the address.
(Oddities about tracing: Store ---, d: the operand is not the
number that's getting stored, but the memory contents before the
store.
The xxBYTE operands show up as words, though only the left hand byte is
in play )
Reinforcement for difference between the
Word-size
instructions (most) and the Byte-size ones (only LDBYTE and STBYTE):
- - - - - - - - - - - - - - - - - - - - - - - - -
;Program to emphasize differences: load and store words, or bytes.
;Refresh memory after each store instruction
LDA 0x0010,d
;load first word
LDBYTEA 0x0010,d ;load first byte of first word
STA 0x0012,d
;Store register right after first
LDA
0x0014,d ;load Second word
STBYTEA 0x0014,d ;Store lower (Least significant
byte)
;of reg. back OVER first byte of second word.
STOP
.WORD 0x50FA ;first word
.block
2
; 2 bytes= a word space
.WORD 0xF1D0 ;second word
.END
- - - - - - - - - - - - - - - - - - - - - - - - -
--What is -1?, -2? in Hex? Do they satisfy the mathematical
definition of a negative: 1 +( -1) = 0 2 +( -2 ) =
0. Sec. 3.2 next.
Read ahead: 3.2, pp. 95-104 (how to do negative
numbers)
CHARI gets a single character from the input source.
You
have two choices on the PC: Batch I/O or Interactive Input from
Keyboard.
Batch mode.
You put all your input into the input window before running. The
program reads the first Ascii character from the input
window. If you have more than one
CHARI in the program, the next CHARI reads the next character, and so
on.
Run Fig. 5.6, p. 196.
Terminal I/0 =Interactive Input from Keyboard (first news from the front): I couldn't make it work consistently while tracing. Still trying to figure that out.
Not tracing: As you run it, the first CHARI waits for
you to type. (Underline is the cursor where you are to type.) You type,
then hit the Enter key, and then the program
reads
your input string character by character with each CHARI, as in
batch
mode. BUT! When you hit Enter, you
add
a "terminal byte" to the string, which here is the LF linefeed, 0AH
(new line). This will get read and used by a CHARI if you type
fewer
characters than there are CHARI's in the program.
(Until you hit Enter, Pep doesn't "see" anything, tho you see the echo
on the screen. For instance, you can backspace and Pep will never
know. Some pre-processor is handling the keyboard input, sending
it in chunks to pep only at the Enters.)
If you move the mouse away, (like to refresh memory) you have to go
back and click on the underline to continue inputting.
How to clear the I/O window? Reload the program.
(Clears memory too?)
Representing Signed (positive and negative) integers in the
computer: -a = ?
Desire: a + (-a) = 0
Assume for simplicity we have a 4-bit cell computer, 16
possible values:
Can count from 0 to 15, in an unsigned integer system.
For signed, desire every number to have its negative, as far as
possible. Since 0 should = -0 , there will be an odd one left
over.
bin hex & dec bin
hex unsigned dec signed
dec
0000 = 0
1000
= 8 = 8 = -8
0001 = 1
1001
= 9 =
9 = -7
0010 = 2
1010
= A = 10 = -6
0011 = 3 1011 = B
= 11 = -5
0100 = 4
1100 = C = 12 =
-4
0101 =
5
1101 = D = 13 =
-3
0110 = 6
1110 = E =
14 = -2
0111 =
7
1111 = F =
15 = -1 Note the
negative interpretation = (unsigned interpretation
-16) 16=24
-0 should be 0. -1 should be 1111 since 0001+1111 = 0000 (with
a carry into somewhere else).
-2 should be 1110 since 0010+ 1110 = 0000 (with carry). Etc.
1000 would have to represent both 8 and -8 with this system.
Arbitrarily decide on -8: then a negative number can be
recognized by the leading 1.
With 4 bits, signed numbers go from -8 up to +7.
Notice to find the negative of a number, you have to know how
many bits are in the representation!
8 bits: NEG(2) = NEG (0000 0010) = (1111 1110)
No matter how many bits: (example, 8 bits) The 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)
| To Sievers Home Page |
CS225-Fall06/Daya7.htm
|
|