Docstoc

Getting started with PEP CS Fall

Document Sample
Getting started with PEP CS Fall Powered By Docstoc
					Machine Language (Ch. 4) with PEP8 (PC instructions) CS225, Fall 2008corrected
You may copy the folder containing the PEP8 files (Pep804Win) from a lab computer (Mac 110: Drive F:
Class Material> CS225 Lab) to your own (PC) computer. Zipped version is Pep804Win.. It doesn‟t need
“installing”—can run from inside that folder. The file named Pep8 (extension exe if extensions show) is
the executable file. (Double) click on it to open the Pep8 interactive window.

It‟s blank, with menus and labeled windowpanes. Edges of panes can be dragged. Click in a windowpane
to make it “active.”
Source code pane: You will type, paste, or load Assembly language programs in here. (Ch. 5, 6…)
Object code pane: You will type, paste, or load Machine language programs in here (Ch. 4—details pp.
181-2) When you assemble a Source program, the Machine language program appears here (in hex).

In these two panes you can do the usual editing things. You can save (it will save with the extension
shown), print, cut, copy, paste. If you load a file it will load into the active (blue head) pane. If you save,
the active pane contents will be saved.

Assembler listing pane: When you assemble an Assembly language program (correctly), a listing appears here showing memory
locations of instructions, the Hex version of them, and data storage.
Assembler listing contents can be saved, but not copied or changed.
Running a Machine Language program:
File> New, Click the Object code pane to make it active. Paste or type in your program. (Or File> Open) It
    must have no leading spaces, be in pairs of hex digits with a single space between each, end in zz.
    I suggest running the simplest program: 00 zz to get Pep waked up.
Save As a different name, for yourself, in some other directory. Will have extension .pepo; it‟s an ASCII
     (text) file, and can be examined in Notepad.
View >Code/ CPU/ Memory to open the Memory pane on the right. Empty to start with. Refresh every time
     you change something.
Build> Load This loads the object file (machine language) into memory. You should see Calling Loader
     appear in the lower left corner. Do Refresh and you should see the Hex program appear in the Memory
     window in sequential bytes. (If you have an Assembler Listing it should match that too.) Note—the
     memory starts out (unrealistically) with 0‟s. Then as you write programs, it (realistically) stays as
     leftover junk which is written over as space is needed.
 (Didn’t work? --You may need to Execute before memory shows its contents. I find it is cranky about
     showing memory when it starts up. It settles down, like a horse, after you‟ve been going a while.
     --It‟s pretty cranky about format; doesn‟t tell you if it fails to load. If you copied and pasted, try just
     typing the program in instead. )
   In the Memory window: Do Refresh, and widen this pane so you can see 8 columns and the right hand
     side of dots. (Edit>Font to a smaller font helps.)
   The “dots” section translates any Hex pair that is in the ASCII range into ASCII.
To step through the program one instruction at a time, mark the Trace program box in the CPU pane.
Build>Execute It runs, unless you‟re Tracing. If Tracing, Single Step through the program using the
     button in the CPU pane. (Resume stops stepping, goes till end.) The first 8 bits of the operation just
     done shows in Binary in the OpCode box.
  !!The Memory window does not refresh automatically. After each potential change to memory, do
     Refresh to see the result.
For subsequent runs: Repeat Load, Execute. To change: type changes in the Object Code pane, Load,
     Refresh Memory to make sure changes happened, Execute.


To hand in from a Machine language program:         Object code, followed by the Input and Output if any,
    any question answers. Preferably give the mnemonics and descriptions with the instructions. Label
    input/output. If memory is an issue, cut and paste the chunk of memory into the file.

                                                                                                  Pep8Machine1.doc 3/21/2011
What are the Rectangular boxes with numbers in menu bar? Number converter:
Decimal hex binary ASCII. Decimal is unsigned. 0x85 means 85hex. Type in any box and see the
corresponding equivalents in the other boxes.

First Machine language.
Memory stores bits; the same bits can be interpreted as instructions or as data.
Machine language instructions are “really” in binary; we convert to hex for human readability.
Pep instructions are 1 byte (8 bits), of instruction (the instruction specifier), followed by a
   possible 2 bytes (the operand specifier) that can contain data, or an address for data, etc.
All the instructions are inside the front cover, & p. A5, Fig. A8 in the back.
Here are some to start with. Ch. 4 does some more; we‟ll do some, postpone some to Ch. 5.                            For
   simplicity, all use “direct” addressing mode (001) (except NOT and STOP, which don‟t have addressing modes)
Binary     Hex Mnemonic It does:
0000 0000 00 STOP            Stops the program. P.156
1100 0001 C1 LDA             Loads into the Accumulator register, the 2-byte contents of
                                memory starting at the address in the operand specifier. P. 157
1100 1001 C9 LDX             Loads into the IndeX register, the 2-byte contents of memory
                                starting at the address in the operand specifier. P. 157
1110 0001 E1 STA             Stores from the Accumulator to the 2 bytes of memory starting at
                                the address in the operand specifier. P. 158
1110 1001 E9 STX             Stores from the IndeX register, as above…
0111 0001 71 ADDA            Adds to the Accumulator (0) or IndeX(1) register contents, the
0111 1001 79 ADDX              2-byte contents of memory starting at the address in the operand specifier. P. 157
0001 100r 18, 19 NOTr        Changes all 0‟s to 1‟s, and vice versa, in the (r) register.
Input/Output: Basic I/O is ASCII, one character at a time. The implementation of Input with PEP is a
   little tricky; we‟ll just do output now.
0101 0001 51 CHARO                    Outputs the single byte in memory at the address in the operand
                                        specifier, interpreted as an ASCII character.

Example: Program to output 2 characters from memory, Fig. 4.32, pp. 169, 181-2
 Grouped by instructions, with comments
Address Machine language (hex) Mnemonic ; comments
0000 510007           CHARO ;character output—character is in memory location 0007
0003 510008           CHARO ;character output—character is in memory location 0008
0006 00               STOP       ;Stop
0007 48               ;ASCII H character
0008 69               ;ASCII i character

Object code as you enter it into Pep: 51 00 07 51 00 08 00 48 69 zz

Memory display: Address is leftmost 4-digit number + 0 to 7 across. (Leftmost address labels
  go up by 8‟s)
     Address 0005 holds 08. Address 0007 holds 48 („H‟). Address 0005 holds 69(„i‟).
Address + 0 1 2 3 4 5 6 7
0000 | 51 00 07 51 00 08 00 48 |Q..Q...H
0008 | 69 00 00 00 00 00 00 00 |i.......

                                                                                                 Pep8Machine1.doc 3/21/2011
HOMEWORK in Machine Language:
Some programs to run, understand, change. Unless notated otherwise, all numbers are in Hex.

ML-A) Simplest program. 00 48 65 6C 6C 6F 21 21 21 21 01 02 03 04 zz
“Does” nothing (only instruction is 00), but loading it stores a bunch of bytes in memory. Enter
  it, Load, Execute, examine memory and see what it stores. Change the program to store the
  ASCII for Jello?!!! Followed by the hex bytes A2 B2. This program will be two bytes
  shorter than the original. Load it (and execute it if necessary to update memory). Hand in
  the memory for locations 0000 through 000F (first 2 lines).

ML-B) Modify the example program, Fig.4.32 p. 169, p. 182 so that it outputs How instead of
 Hi. Caution! Be sure the addresses of your characters are correct. Save your modification
 for use in ML-E.

ML-C) This program loads 0A4A into A, Adds 0001, stores the result in the next “word.” Then
  outputs the second byte of that word. Enter it, Save it to your own medium, Load,
  Assemble, Execute. Repeat, examining memory before and after running.
Repeat, Stepping (Trace) through it. Observe the Accumulator row, the Program Counter, the
  Instruction Register on down, at each step.
 Note the Program Counter gives address of NEXT instruction.
 Instruction Register gives instruction specifier for instruction just completed, and opcode stuff
  matches.
 Registers (Accumulator, IndeX for now) show results of instruction just completed.

Address Machine language (hex) Mnemonic ; comments
0000 C1000D          LDA ;Loads into A the 2 bytes at 000D
0003 71000F          ADDA ;Adds to A the 2 bytes at 000F
0006 E10011          STA ; stores from A into 2 bytes at 0011
0009 510012          CHARO ; outputs the BYTE at 0012
000C 00              STOP       ;Stop
000D 124A              ;Number (2-byte space)
000F 0001              ;Number 1
0011 FEFE              ;Space for result

a) Modify this program so that it loads 1244 into the IndeX register, adds 0002, stores the result,
   outputs it.

b) i) Modify the original program so that the sum is stored back over the original Number.
   (This implements the C++ instruction Number = Number + 1 (or Number++) (Leave the
   CHARO as it is.) Check Memory after running to be sure it has worked.
    ii) Now fix the CHARO so it outputs the “right hand” (“least significant”) byte of your result.

c) In the original program: What happens if at address 0006 you have E1 0009 instead of
   E10011? Substitute and Trace.


                                                                               Pep8Machine1.doc 3/21/2011
ML-D)
Address Machine language (hex) Mnemonic ; comments
0000 C1000B          LDA ;Loads into A the 2 bytes at 000B
0003 18              NOTA ;Does NOT to each of the bits in A
0004 E1000D          STA      ; stores from A into 2 bytes at 000D
0007 71000B          ADDA ; Adds the “original” to the NOT-ed
000A 00              STOP        ;Stop
000B 2222              ;Number (2-byte space)
000D 0000              ;Space for NOT-ed

a) This program loads 2222 into A, does NOT to it, stores the result, then adds the two numbers.
   Result is in the Accumulator register A. Trace the program to STOP and examine the
   Accumulator. What is the result? (Storing is not necessary to accomplish the result; but does
   preserve the NOT-ed number to check on.)
 b) Run it with 1234. With FACE. What are the results? Paper and pencil: Change each of the
   3 numbers you ran to binary, do NOT to it, add the two, and explain why we get what we get.

ML-E) Lower ASCII values are used for control signals. 0A in ASCII is LF (line feed) (new
 line). Does it do that when Pep does CHARO? Go back to your solution to ML-B and modify
 it to (hopefully) output H <line feed> w . Output should look like
 H
 w
 Report whether it works.

ML-F) c9 00 08 E9 00 0A 19 00 71 00 09 12 zz
This is a Mystery program: translate the codes and fill in this template:
Address Machine language (hex) Mnemonic ; comments

------------------------
 Textbook HW: p. 183ff:
1. Size of memory. To count bits in CPU, use the picture in fig. 4.2, p. 149
2. How many instructions? (Note: unary have only an instruction specifier. All non-unaries
   also have the 2-byte Operand Specifier)
3. Only 7AF82C.
5 a, e only (What effect does an operation have?)

A. Decode these instruction specifiers. Use p. 153-4. Give the opcode, the register affected (if
   any), the addressing mode (if any). Give the mnemonic. Tell if it‟s unary or if it requires an
   Operand Specifier. Then turn it into Hex.
Some of these will be operations we haven‟t studied: give the mnemonic shown on the front
   flyleaf or p. 153. Some will have addressing modes we haven‟t studied: use the table(s) p.
   154.
   a) 0011 0101        b) 1010 1000
   c) 0110 1001        d) 1001 0111
   e) 1110 0000        f) 0001 1100
                                                                               Pep8Machine1.doc 3/21/2011

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:3
posted:3/21/2011
language:English
pages:4