Day 5HW: Due Wed. Day 6.
(* problems/parts have answers in the back. )
Text p. 228 #7 (hand trace program)
Text p. 132 #22 a,b,c,d,f (and
or
not)
--remember N flag is set (1) when MSB is 1.
Make A and B due on Friday. Pep 8.01's
flags aren't functioning! (always =1). Pep800B8's flags work as
they're supposed to, but the saving is a mess. So to do this
properly you have to: Load it into pep801, debug if needed,
save, get the Assembler listing. Trace, recording everything but
the flags. Load the same program into pep800B8, and trace it
there to watch an record the flags. (pull down the edge of the
pane to find the single step button.)
A) Tracing: (Get templates
) a) Trace Program A below,
Memory
trace and Program trace, including flags (on the computer).
b) Note how Ldbyte and
Stbyte affect the registers, the memory locations, and the flags.
Hand in the trace.
c)Underline instructions
where N or Z were "set" (turned to 1) and check that each corresponds
to:
a number with 1 in the leftmost (Most significant) bit; a Zero number.
d) The Add instruction
adds 2 numbers with F's in the leftmost hex digit. If you do the
binary addition, you'll get a carry out of the left side. Does
the
C get set (= 1) at this instruction? Circle the C value for this
instruction.
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: What
numbers you operated on, the resulting numbers, and the resulting
flags.
C) Create a byte size Mask (on paper only) and an operation that
will
(different for each part)
a) change ASCII A to a (or any capital to its small letter)
b) change a to A (or any small to its capital)
c) change "3 " the character to 3 the number
d) change 3 the number to "3 " the character
D) Load or Type in program 5.7 (add 3 and 5, p. 197), run it and
check that the output
is as shown. Change the program so that the two numbers to be
added are 2 and 4. Check that the output is 6. Now change
it so that the two numbers to be added are 6 and 7. What is the
output now? Explain why the program gave this output.
E) .BLOCK reserves memory and puts 0's in it. When you declare a variable in C++, does the program just reserve a memory space for it or does it give it a default value (e.g. 0) if you don't give it a value? Write a C++ program to find out! (hint: just declare the variable, and then output it, without assigning anything to it.) What value did you get for an INT variable that you don't assign a value to?
F) Program F below will make a preliminary investigation into
how negative
numbers are handled in the PEP8. It should: Load the number 1
(0001H
) into A. Then repeatedly subtract 1 from it.
a) The program is not quite
finished;
the address for the memory location of 0001H is not
determined.
Determine the address and finish writing the program.
(Hint:
The from-scratch way is to count by hand how many bytes are used by the
program instructions, and thus find out where the .Word will
be. Or, the lazy way, you can also put in 00FF or something for
the
address, knowing it's wrong. Assemble the program and look at the
Assembler Listing to find the address you want. Go back and
change
the address to the correct one. Find is under the Edit menu in
PEP8 .
b) Run the program and write down the hex
and decimal results.
Hand in a
table:
Decimal Hex showing what the Hex equivalent of
the Decimal negative numbers is.
1 0001
0 0000
-1
?
etc. to -7
Also Program 1 is due at class
time:
Email me the source code. Hand in Assembler
Listing & output, with the same
cover stuff as for a C++ program:
Running? remaining bugs? Help from?
NOTES:
Last HW: ASL does the "same" thing as multiplying by 2;
adding a number to itself.
Abstractly: binary number anan-1...a2a1a0
= an2n + an-12n-1+...+a222+a121+a020,
where the a's are all either 0 or 1. Multiplying by 2 raises the
power
of all the 2i 's by one, so a0 is now the
coefficient of 21. The new coefficient of 20 is
0, and all the other bits have shifted left; the new number in binary
is anan-1...a2a1a00.
One bit longer than before.
Labeling bits in a word: a15a14....anan-1...a2a1a0
USUALLY the bits are labeled from "right to left": 0--Least
significant (a0
), to 15--Most significant (a15). So the bit
label is the power of 2 that that place represents. Warford,
bless his heart, labels them backward:
The most significant (leftmost) byte is bits 0...7, the least
significant (rightmost) is bits 8-15.
Flags: Op just executed resulted in a number that is:
(1
for true, 0 for false)
N negative. (Most Significant Bit MSB
=1. Explained
later, sec. 3.2. Acts only on Word in register)
Z zero (word is zero)
V oVerflow (for arithmetic with signed
numbers.
More later)
C carry--a carry out of the MSB when adding,
other places where a bit moves off either end of the "cell", (or is
borrowed)
Reread p.94 (Appendix A7-8 give all ops, including flag actions,
in RTL
Byte ops: only 2: LdbyteR, StbyteR Mainly
for moving characters around. pp. 163-4. Load
a byte only into the lower byte in the register (the upper byte stays
what
it was), Store the lower byte from the register to the memory byte of
the
operand.
.Block 5 reserves 5 bytes of memory (for you to store
things in). Pep8 puts in 00's; not all assemblers do. Cf.
declaring
a variable in C++. pp. 195-6
Tracing: Get templates
Trace program below, check out new ops and flags.
Logical Ops ("bitwise"--no carrys or borrows to
neighboring bits)
1=true, 0=false and usual truth tables work. Read NOT
p.96, AND OR &shifts 3.3 pp.105-109
NOTR: (unary)
"one's complement" 0-->1, 1-->0.
ANDR oprndspec:
p AND q =1 (true) only when both p and q are 1, otherwise =0
(think
p*q with no carries).
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).
Masking: To force certain bits to
become 0 or 1, leaving others unchanged.
(A<-->a,
"3"<-->3)
| Force to 0 "clear" |
Force to 1 "set" |
| 0<--b AND 0 b<--b AND 1 |
1<--b OR 1 b<--b OR 0 |
Look at ops: 2-argument ops all do something
like r<--r OP operand, and operand is in
memory.
Design choice.
No move directly from X to A. No
Add X to A. No add # in memory location 1 directly to # in memory
location
2. Etc.
We are working our way up to being able to proceed through 5.1 and on.
;Program A to investigate Status Registers Z, C,
N, Ldbyt &Stbyt HW Day5
;Sievers
;Sept 4, 2006
;This program uses Ldbyt, .block new
LDa 0x0016, d ;loads zeros into reg. A. Check flags.
LDa 0x0018, d ;loads F0f0 into A
ldbytea 0x0016,d ; loads a 00 byte into a
ldbytea 0x001d,d ;loads a not-0 byte into a (01)
stbytea 0x001a,d ; stores a byte from a to the memory saved for it
Adda 0x0018,d ; adds F0f0 to a
Suba 0x001e,d ; subtracts E0f1 from a
STOP ; STOP must be at the end of the instructions for the cpu to run
.word 0x0000
.word 0xF0F0
.BLOCK 2 ; reserves a block of "empty" space
.word 0x0001
.word 0xe0F1
.END ;END tells assembler we're done.
| To Sievers Home Page |
CS225-Fall06/Daya5.htm
|
|