Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4 Computer Architecture.

Similar presentations


Presentation on theme: "Chapter 4 Computer Architecture."— Presentation transcript:

1 Chapter 4 Computer Architecture

2 Pep/9 virtual machine

3 Figure 4.1 The Pep/9 hardware consists of three major components at the instruction set architecture level, ISA3: The bus is a group of wires that connects the three major components. It carries the data signals and control signals sent between the blocks.

4 The CPU contains 6 registers.
Figure 4.2 The CPU contains 6 registers.  X, PC, and SP—help the CPU access information in main memory.  negative, zero, overflow, and carry bits An index register in a computer's CPU is a processor register used for modifying operand addresses during the run of a program, typically for doing vector/array operations. An accumulator is a register for short-term, intermediate storage of arithmetic and logic data in a computer's CPU

5 Main memory of Pep/9 Computer
Figure 4.3 65,536 eight-bit(byte) storage locations Each byte has an address (dec:0 to 65,535; hex:0000 to FFFF.) Main memory is sometimes called core memory. byte1 byte2 byte3 Main memory of Pep/9 Computer

6 Figure 4.4 Even though the lines have equal widths visually in the block, a single line may represent one or several bytes. The address on the side of the block is the address of the leftmost byte in the line. You can tell how many bytes the line contains by the sequence of addresses (3 bytes here). top  bottom

7 A Pep/9 word word is a certain number of bytes
In the Pep/9 computer, a word is two adjacent bytes (16 bits). Most of the registers in the Pep/9 CPU are word registers.

8 Figure 4.5 In main memory, the address of a word is the address of the first byte of the word.   Two adjacent bytes at addresses 000B and 000C. The address of the 16-bit word is 000B. To save space on the page, the content of a byte or word is usually written in hexadecimal

9 Input/Output Devices The Pep/9 system simulates two input/output (I/O) modes— interactive and batch. Before executing a program, you must specify the I/O mode. If you specify interactive: the input comes from the keyboard both input and output appear in a terminal window. If you specify batch: the input comes from an input pane and the output goes to an output pane. simulates input from a file because the input pane must have data in it before the program executes

10 Pep/9 use Memory-mapped I/O
input device is wired into main memory at one fixed address (FC15 in Pep/9) output device is wired into main memory at another fixed address (FC16 in Pep/9). DMA-Direct Memory Access allows data to flow between the disk and main memory directly without going through the CPU Pep/9 does not use this

11 Data and Control Data flow from the input device at address FC15 on the bus to the CPU. Data can also flow from the CPU on the bus to the output device at address FC16 FC15 FC16

12 Instruction Format Figure 4.6
Each computer has its own set of instructions wired into its CPU The Pep/9 computer has 40 instructions in its instruction set. Each instruction consists of either a single byte called the instruction specifier, or the instruction specifier followed immediately by a word called the operand specifier.  Instructions that do not have an operand specifier are called unary instructions. 

13 Figure 4.7

14 Instruction Format Figure 4.6
The Pep/9 computer has 40 instructions in its instruction set:

15 Figure 4.6 (continued)

16 Figure 4.6 (continued)

17 The opcode The eight-bit instruction specifier can have several parts:
Part1:operation code (opcode):  may consist of as many as eight bits and as few as four. E.g. instruction to move the stack pointer to the accumulator eight-bit opcode of five-bit opcode

18 Instructions with fewer than eight bits in the opcode
subdivide their instruction specifier into several fields depending on the instruction.  indicates these fields with the letters a, r, and n. Each one of these letters can be either 0 or 1. E.g. 2 versions of instruction: and How many version in following?:

19 letter a : addressing mode
Figure 4.8 letter a : addressing mode Pep/9 executes each nonunary instruction in one of eight addressing modes: Later chapters describe the meaning of the addressing modes. For now, it is important only that you know how to use the tables of Figures 4.7 and 4.8 to determine which register and addressing mode a given instruction uses

20 Figure 4.8 (continued)

21 letter r : register. Figure 4.8 (continued)
instruction operates on the accumulator  instruction operates on the index register

22 Question Determine the opcode, register, and addressing mode of the instruction

23 Answer Starting from the left, determine with the help of Figure 4.6 that the: opcode is 1100 r = 1   index register. aaa = 011  stack relative addressing Therefore, the instruction loads a word from memory into the index register using stack-relative addressing.

24 Instructions: operand specifier: are stored in main memory.
The address of an instruction in main memory is the address of the first byte of the instruction. operand specifier: For non-unary instructions, indicates the operand to be processed by the instruction.

25 Figure 4.9 Example two adjacent instructions stored in main memory at locations 01A3 and 01A6 The instruction at 01A3 is not-unary The instruction at 01A6 is unary

26 the instruction at 01A3 has
Opcode: 0111 subtraction 1101 = raaa Register-r field: 1 instruction operates on the index register Addressing-aaa field: 101 indexed addressing (to interpret operand specifier ) Operand specifier:

27 The unary instruction at 01A6 has
Opcode: arithmetic shift right Register-r field: 0 operation done on accumulator

28 Machine language binary sequence that CPU interprets according to the opcodes of its instruction set.  two instructions in hexadecimal, preceded by their memory addresses: 01A3 7D034E 01A6 0C

29 The stop instruction Instruction specifier: 0000 0000
Causes the computer to stop

30 Direct addressing An addressing-aaa field of 001 indicates direct addressing. The operand specifier is the memory address of the operand. In mathematical notation, Oprnd = Mem[OprndSpec]

31 The load word instruction
Instruction specifier: raaa Loads one word (two bytes) from memory to register r

32 Figure 4.10, 4.11 Example load word instruction: C1004A Address of operand in memory = 004A (where data read from) Load Word From memory Accumulator A Direct Addressing SEND_DATA DATA 1 in sign bit = negative The V and C bits are unaffected by the load word instruction. bit pattern is not all 0’s 92EF =

33 The store word instruction
Instruction specifier: raaa Stores one word (two bytes) from register r to memory

34 Address of memory where data needs
Figure 4.12, 4.13 Example store word instruction: E9004A Address of memory where data needs To be stored = 004A Store Word To memory Index Register X Direct Addressing

35 The add instruction Instruction specifier: 0110 raaa
Adds one word (two bytes) from memory to register r

36 Example add word instruction: 69004A
Figure 4.14, 4.15 Example add word instruction: 69004A Address of operand in memory = 004A (where data read from) Instruction Register X Add Word From memory Direct Addressing 5 + (–7) = –2(dec), = FFFE (hex) –7 (dec) = FFF9 (hex) N = 1 because the sum is negative. Z = 0 because the sum is not all 0’s. V = 0 because an overflow did not occur, C = 0 because a carry did not occur out of the most significant bit.

37 The subtract instruction
Instruction specifier: raaa Subtracts one word (two bytes) in memory from register r

38 Address of operand in memory = 004A
Figure 4.16, 4.17 Example subtract instruction: 71004A Address of operand in memory = 004A (where data read from) Accumulator A Subtract Word In memory from r Direct Addressing 3 – 9 = 3 = 0003(Hex) = -9 2’s comp = = FFF7(Hex) 3 + (-9) = FFF7 = FFFA(Hex)  3 – 9 = –6(dec) = FFFA (hex)

39 The and instruction Instruction specifier: 1000 raaa
ANDs one word (two bytes) from memory to register r

40 Address of operand in memory = 004A
Figure 4.18, 4.19 Example AND word instruction: 89004A Address of operand in memory = 004A (where data read from) Instruction Register X Bitwise AND To r Direct Addressing The N bit is 0 because the quantity in the index register is not negative when interpreted as a signed integer. The Z bit is 0 because the index register is not all 0’s. 5DC3 AND 00FF = 00C3

41 The or instruction Instruction specifier: 1001 raaa
ORs one word (two bytes) from memory to register r

42 Address of operand in memory = 004A
Figure 4.20 Example OR word instruction: 99004A Address of operand in memory = 004A (where data read from) Instruction Register X Bitwise OR To r Direct Addressing 1 9 5DC3 OR 00FF = 5DFF

43 The invert instruction
Instruction specifier: r Bit-wise NOT operation on register r Each 0 changed to 1, each 1 changed to 0

44 Figure 4.21, 4.22 Accumulator A Invert bits in r NOT 0003 = FFFC

45 The negate instruction
Instruction specifier: r Negate (take two’s complement of) register r

46 - 3(dec) = 1111 1111 1111 1101 (bin) = FFFD (hex)
Figure 4.23 Accumulator A negate r 8 - 3(dec) = (bin) = FFFD (hex)

47 The load byte instruction
Byte instruction: operate on a single byte of information Instruction specifier: raaa Loads one byte from memory to the right half of register r

48 92 loaded to right byte of A
Figure 4.24, 4.25 Load byte to r Accumulator A Memory address 4A Direct Addressing 92 loaded to right byte of A

49 The store byte instruction
Instruction specifier: raaa Stores one byte from the right half of register r to memory

50 F Figure 4.26 1 1 1 1 Accumulator A Store byte from r to mem
Memory address 4A Direct Addressing F

51 Load byte from input device
Figure 4.27 Load byte from input device input device(e.g. keyboard) at address FC15 To get user input (e.g. character from keyboard): execute the load byte instruction from address FC15.

52 Load byte from input device
Figure 4.27 Load byte from input device instruction = D1FC15 (hex) next character in the input stream is W. Load Byte from memory to A (0001 raaa) FC15 Input Device The character from the input stream can come from the keyboard or from a file. ASCII value of the letter W is 57 (hex)

53 Store byte to output device
Figure 4.27 Store byte to output device The output device(e.g. screen) at address FC16. To send a character to the output device: execute the store byte instruction to address FC16.

54 Store byte to output device
Figure 4.28 Store byte to output device instruction = F1FC16 (hex) ASCII value for the letter H FC16 Output Device Store Byte to memory from A (1111 raaa) ASCII value for the letter i

55 QUESTION  Answer the following questions for the machine language instructions 6AF82C and 623D0.  (a) What is the opcode in binary?  (b) What does the instruction do?  (c) What is the register-r field in binary?  (d) Which register does it specify?  (e) What is the addressing-aaa field in binary?  (f) Which addressing mode does it specify?  (g) What is the operand specifier in hexadecimal?

56 ANSWER

57 QUESTION  Answer the following questions for the machine language instructions 6AF82C.  (a) What is the opcode in binary?  (b) What does the instruction do?  (c) What is the register-r field in binary?  (d) Which register does it specify?  (e) What is the addressing-aaa field in binary?  (f) Which addressing mode does it specify?  (g) What is the operand specifier in hexadecimal?

58 ANSWER

59 Big Endian Versus Little Endian
In what order should the sequence of bytes be stored in main memory? CHOICE1: Big-endian Order The CPU store the most significant byte at the lowest address CHOICE2: Little-endian Order CPU store the least significant byte at the lowest address Pep/9 is a big-endian CPU. There is no dominant standard in the computing industry. Some processors use big-endian order, some use little-endian order, and some can use either order depending on a switch that is set by low-level software

60 A Big-endian CPU E.g The most significant byte of the register gets 92, (address004A) The next byte gets EF (next higher address at 004B)

61 A little-endian CPU Figure 4.29
The byte at the lowest address, 004A, is 92 and is put in the least significant byte of the register. The byte from the next higher address, 004B, is put to the left of the low-order byte in the register.

62 A 32-bit register load Figure 4.30
Effect of a load instruction in a CPU with 32-bit registers for both big-endian and little-endian ordering. A 32-bit register holds four bytes, which are loaded into the accumulator

63 QUESTION Suppose Pep/9 contains the following four hexadecimal values:
A: 19AC X: FE20 Mem[0A3F]: FF00 Mem[0A41]: 103D If it has these values before each of the following statements executes, what are the four hexadecimal values after each statement executes? (a) C10A3F (b) D10A3F (c) D90A41 (d) F10A41 (e) E90A3F (f) 790A41 (g) 710A3F (h) 910A3F (i) 07

64 ANSWER

65 Von Neumann Computers stored program concept:
In 1945, John von Neumann proposed to build a computer that would store in main memory not only the data, but the program as well. The stored-program concept was a radical idea at the time.  Practically all commercial computers today are based on the stored-program concept, with programs and data sharing the same main memory. The Pep/9 computer is a classic von Neumann machine.

66 The von Neumann execution cycle
Fetch instruction at Mem[PC]. Decode instruction fetched. Increment PC. Execute the instruction fetched. Repeat.

67 More detailed view Figure 4.31
first instruction is placed at address 0000 (hex). second instruction is placed adjacent to the first: (0001(hex) if first instruction is unary, 0003(hex) if not PC: To initialize the program counter and stack pointer, PC is set to 0000 (hex), and SP is set to Mem[FFF4]. The purpose of the program counter is to hold the address of the next instruction to be executed. Because the first instruction was loaded into main memory at address 0000, the PC must be set initially to The purpose of the stack pointer is to hold the address of the top of the run-time stack. A later section explains why SP is set to Mem[FFF4].

68 Figure 4.32 Initialize PC and SP PC :
- hold the address of the next instruction to be executed. SP: -hold the address of the top of the run-time stack

69 Figure 4.32 FETCH: first operation in the von Neumann execution cycle.
-CPU examines PC to get an address. It then goes to that address in main memory to fetch the instruction specifier (one byte) of the next instruction. and holds them in the first byte of the instruction register (IR).

70 Figure 4.32 DECODE: -The CPU extracts the opcode from the instruction specifier to determine which instruction to execute. -Depending on the opcode, the CPU extracts the register specifier if there is one and the addressing field if there is one. -Now the CPU knows from the opcode whether the instruction is unary. If it is not unary, the CPU fetches the operand specifier (one word) from memory and stores it in the last two bytes of the IR.

71 Figure 4.32 Increment PC (to next instruction to fetch)
The CPU adds 0001 to the PC if the instruction was unary. Otherwise it adds 0003.

72 Figure 4.32 The CPU executes the instruction that is stored in the IR.
The opcode tells the CPU which of the 40 instructions to execute.

73 Figure 4.32 CPU returns to the fetch operation unless the instruction just executed was the stop instruction. Pep/9 will also terminate at this point if the instruction attempts an illegal operation. (e.g. attempting execution of an instruction with a forbidden addressing mode)

74 A Character Output Program
Pep/9 system is a character I/O system: take its input from the keyboard and send its output to the screen I/O devices are based on the ASCII character set. input device at Mem[FC15] load byte instruction from Mem[FC15] to CPU register output device at Mem[FC16] Store byte instruction to Mem[FC16] from CPU register

75 Figure 4.33  simple machine-language program that outputs the characters Hi on the output device 1101

76

77 help Display settings CPU Write object code here in hex I/O

78 Run Program Memory dump Systemclear memory
Program (each byte separated by space, no leading / trailing spaces in a line) BuildLoadExecute = BuildRun Object

79 The Pep/9 loader is extremely particular about the format of your machine-language program. To work correctly: The very first character in your text file must be a hexadecimal character. No leading blank lines or spaces are allowed. There must be exactly one space between bytes. If you wish to continue your byte stream on another line, you must not leave trailing spaces on the preceding line.

80 Step through Build  start debugging object

81

82 Figure 4.34 (a) Initial state before loading.
(b) Program loaded into main memory.

83 Figure 4.34 (continued) (c) PC ← 0000 (hex).
(d) Fetch instruction at Mem[PC].

84 Figure 4.34 (continued) (e) Increment PC.
(f) Execute. Load byte for H to accumulator.

85 Figure 4.34 (continued) (g) Fetch instruction at Mem[PC].
(h) Increment PC.

86 Figure 4.34 (continued) (i) Execute. Store byte from accumulator to output device. (j) Fetch instruction at Mem[PC].

87 Figure 4.34 (continued) (k) Increment PC.
(l) Execute. Load byte for i to accumulator.

88 A Character Input Program
Figure 4.35 A Character Input Program FC15- Input Store byte from the accumulator to Mem[0013] FC16- Output Machine language program to input two characters and output them in reverse order

89

90 Terminal I/O input output

91 step4 step1 step2 step3 Address Algorithm Instruction Unary? 0000
Load word Non-U (3 bytes) 0003 A = + 3 Add Word 0006 Convert sum to character Bitwise OR with MASK 0009 Output the Character Store Byte 000C STOP stop U (1 byte) 000D Decimal 5 Data - word 2 bytes 000F Decimal 3 0011 Mask for ASCII character

92 step4 step1 step2 step3 Address Algorithm Instruction Unary? 0000
Load Word Non-unary (3 bytes) 0003 A = + 3 Add Word 0006 Convert sum to character Bitwise OR with Mask 0009 Output the Character Store Byte 000C STOP Stop Unary (1 byte) 000D Decimal 5 Data –word 2 bytes 000F Decimal 3 Data – word 0011 Mask for ASCII character Data -word

93 step5 step6 Address Algorithm Instruction Instruction –binary
Instruction-Hex 0000 A = 5 Load Word 0003 A = + 3 Add Word 0006 Convert sum to character Bitwise OR with Mask 0009 Output the Character Store Byte 000C STOP Stop 000D Decimal 5 Data –word 000F Decimal 3 0011 Mask for ASCII character

94 step5 step6 Address Algorithm Instruction Instruction –binary
Instruction-Hex 0000 A = 5 Load Word C1000D 0003 A = + 3 Add Word 61000F 0006 Convert sum to character Bitwise OR with Mask 910011 0009 Output the Character Store Byte F1FC16 000C STOP Stop 00 000D Decimal 5 Data –word 0005 000F Decimal 3 0011 Mask for ASCII character 0030

95 Converting Decimal to ASCII
Figure 4.36 Converting Decimal to ASCII 000D(hex)  Illustrates the inconvenience of dealing with output at the machine level. OR with MASK 3(dec) 5(dec) Works only if output is single digit  loads the 5 into the accumulator adds the 3  8 is interpreted as ASCII Backspace We need to print 8 instead So, the program must convert the decimal number 8, (bin), to the ASCII character 8, (bin) 8(dec) MASK “8” ASCII

96 From ASCII Table:

97

98 Question  Write a machine language program to add the three numbers 2, –3, and 6 and output the sum on the output device. Store the numbers in hexadecimal. Do not use the subtract, negate, or invert instructions. Write the program in a format suitable for the loader and execute it on the Pep/9 simulator.

99 Answer

100

101 Question Write a machine language program to input two one-digit numbers, add them, and output the one-digit sum. There can be no space between the two one-digit numbers on input. Write the program in a format suitable for the loader and execute it on the Pep/9 simulator.

102

103 Answer

104

105 Question  Write a machine language program to output the three characters Cat on the output device. Write it in a format suitable for the loader and execute it on the Pep/9 simulator.

106 Answer algorithm load byte A<- ‘C’ output value in A load byte A<- ‘a’ load byte A<- ‘t’ Stop ’C’ ‘a’ ‘t’

107 Answer algorithm 0000 load byte A<- ‘C’ 0003 output value in A 0006 load byte A<- ‘a’ 0009 output value in A 000C load byte A<- ‘t’ 000F output value in A 0012 Stop 0013 ’C’ ‘a’ ‘t’

108 Answer cat.pepo 0000 D ; load byte A<- Mem[0013] =43=‘C’ 0003 F1 FC 16 ; output value in A 0006 D ; load byte A<- Mem[0014]=61=‘a’ 0009 F1 FC 16 ; output value in A 000C D ; load byte A<- Mem[0015]=74=‘t’ 000F F1 FC 16 ; output value in A ;stop ;’C’ ‘a’ ‘t’ zz

109 QUESTION Determine the output of the following Pep/9 machine language program. The left column in each part is the memory address of the first byte on the line: (a) 0000 C1000A C 0006 F1FC A A94F 000C FFFD

110 ANSWER 0000 C1000A load word to A from mem[000A] =A94F
Answer: M 0000 C1000A load word to A from mem[000A] =A94F C Bitwise AND to A mem[000C] = FFFD(A94F AND FFFD = A94D) 0006 F1FC16 Store byte (4D = ‘M’) to output device from A Stop 000A A94F 000C FFFD

111 Programming at Level ISA3
To program at Level ISA3 is to write a set of instructions in binary. An operating system is a program.  In the Pep/9 computer, the bottom part of main memory—that is, the part with high memory addresses—is reserved for the operating system.

112 Figure 4.41

113 Pep/9 operating system consists of two programs
Figure 4.41  run-time stack for the operating system begins at memory location FC0F. Grows upwards. SP store  address of the top of the system stack when the operating system executes  user stack, is at memory location FB8F, just above the operating system. The stack pointer register in the CPU contains the address of the top of the stack’ stack “grows upward” in memory toward the smaller addresses (procedure call params,local vars, return addresses).  loads the application program into main memory On the Pep/9, you invoke the loader by choosing the loader option from the menu of the simulator program. Stack is used for static memory allocation and Heap for dynamic memory allocation Pep/9 operating system consists of two programs  machine vectors (6 words in ROM) instructions with opcodes through are unimplemented at Level ISA3. The trap handler implements these instructions for the assembly language programmer.

114 Memory devices Read/Write memory(RAM)
Also called Random-Access Memory (RAM) Can load from RAM and store to RAM Read-Only memory (ROM) Can load from ROM Cannot store to ROM

115 The load option When you choose the load option from the Pep/9 simulator menu, the following two events occur: SP ← Mem[FFF6] PC ← Mem[FFFC] After these , the execution cycle begins

116 Pep/9 load option  FC0F is the value the stack pointer should have when the system stack is empty FC17 is the address of the first instruction to be executed in the loader

117 The execute option After you write your machine-language program and load it with the loader option, you must select the execute option to run it.  The following events occur when you select the execute option: SP ← Mem[FFF4] PC ← 0000 Start the von Neumann cycle

118 Figure 4.43

119 Project Discussion


Download ppt "Chapter 4 Computer Architecture."

Similar presentations


Ads by Google