Presentation is loading. Please wait.

Presentation is loading. Please wait.

19-1 Programming…. 19-2 The Pencil and Paper Computer The Pencil & Paper Instruction Set: (table 5.4.2 on p148) The Operand specifies a memory location.

Similar presentations


Presentation on theme: "19-1 Programming…. 19-2 The Pencil and Paper Computer The Pencil & Paper Instruction Set: (table 5.4.2 on p148) The Operand specifies a memory location."— Presentation transcript:

1 19-1 Programming…

2 19-2 The Pencil and Paper Computer The Pencil & Paper Instruction Set: (table 5.4.2 on p148) The Operand specifies a memory location (variable) whose value will be printed to the screen (displayed to output units). PRINT 110 The Operand (the last 5 bits of the instruction) specifies a location within the current program (i.e., line number) that will be executed next if the Accumulator is greater than zero. Otherwise, the PJUMP instruction is skipped and the next instruction is executed “normally” PJUMP 111 The Operand specifies a memory location (variable) whose value will be replaced by a numerical value read from the keyboard (input units) READ 101 The Operand specifies a memory location (variable) whose value will be replaced by the current value in the Accumulator. STORE 100 The Operand specifies a memory location (variable) whose value will replace the current value in the Accumulator. LOAD 011 The Operand specifies a memory location (variable) whose value will be subtracted from the Accumulator. SUB 010 The Operand (the last 5 bits of the instruction) specifies a memory location (variable) whose value will be added to the Accumulator. ADD 001 The computer stops interpretation of the current program.STOP000 The action taken by the CPU, in English mnemonic Opcode

3 19-3 Working with the P&P Computer –Addition & Subtraction are done via the Accumulator –Reading and Printing are done via Memory –Decision and Repetition (PJUMP) are done via the Accumulator –We will write our programs with Mnemonics and assume there's an Assembler to translate our program into binary/machine code we can use “named” memory slots (variables) instead of “numbered” memory slots. –In essence, we don't care which specific memory slot we use, as long as its use is consistent READ X ==assembler==> 101 10001 –We wish to read a value from the keyboard (user) and store it in a named slot “X” -- the assembler decides “X” is slot 17, so all other references to “X” should be turned into 17.

4 19-4 The Pencil and Paper Computer Process for writing Pencil & Paper Computer programs: 1. Determine the requirements What is the input? What is the desired output? What needs to be computed? 2. Determine the algorithm. Break the problem down into steps. How do we computer what needs to be computed? Write an outline of the steps. 3. Write the program. 4. Test/Debug (Trace through the program)

5 19-5 The Pencil and Paper Computer Problem: Write a program that prints the counting numbers from 5 down to 1. ONE = 1 COUNT = 5 0 PRINT COUNT 1 LOADCOUNT 2 SUBONE 3 STORECOUNT 4 PJUMP0 5 STOP Memory: Accumulator: Output: CountOne

6 19-6 The Pencil and Paper Computer The count down from 5 program in machine code... Memory Address Value 0 11011001 1 01111001 2 01011000 3 10011001 4 11111010 5 00000000.... 24 00000001 25 00000101 ONE = 1 COUNT = 5 0 PRINT COUNT 1 LOADCOUNT 2 SUBONE 3 STORECOUNT 4 PJUMP0 5 STOP


Download ppt "19-1 Programming…. 19-2 The Pencil and Paper Computer The Pencil & Paper Instruction Set: (table 5.4.2 on p148) The Operand specifies a memory location."

Similar presentations


Ads by Google