Computers, data and programming

Snug
Topic4-ElementaryComputerProgramming.pdf

Chapter 4 MARIE: An Introduction to a Simple Computer

23

4.8 MARIE • We can now bring together many of the ideas that

we have discussed to this point using a very simple model computer.

• Our model computer, the Machine Architecture that is Really Intuitive and Easy, MARIE, was designed for the singular purpose of illustrating basic computer system concepts.

• While this system is too simple to do anything useful in the real world, a deep understanding of its functions will enable you to comprehend system architectures that are much more complex.

24

The MARIE architecture has the following characteristics:

• Binary, two's complement data representation. • Stored program, fixed word length data and

instructions. • 4K words of word-addressable main memory. • 16-bit data words. • 16-bit instructions, 4 for the opcode and 12 for the

address. • A 16-bit arithmetic logic unit (ALU). • Seven registers for control and data movement.

4.8 MARIE

25

MARIE’s seven registers are: • Accumulator, AC, a 16-bit register that holds a

conditional operator (e.g., "less than") or one operand of a two-operand instruction.

• Memory address register, MAR, a 12-bit register that holds the memory address of an instruction or the operand of an instruction.

• Memory buffer register, MBR, a 16-bit register that holds the data after its retrieval from, or before its placement in memory.

4.8 MARIE

26

MARIE’s seven registers are: • Program counter, PC, a 12-bit register that holds the

address of the next program instruction to be executed.

• Instruction register, IR, which holds an instruction immediately preceding its execution.

• Input register, InREG, an 8-bit register that holds data read from an input device.

• Output register, OutREG, an 8-bit register, that holds data that is ready for the output device.

4.8 MARIE

27

This is the MARIE architecture shown graphically.

4.8 MARIE

28

• The registers are interconnected, and connected with main memory through a common data bus.

• Each device on the bus is identified by a unique number that is set on the control lines whenever that device is required to carry out an operation.

• Separate connections are also provided between the accumulator and the memory buffer register, and the ALU and the accumulator and memory buffer register.

• This permits data transfer between these devices without use of the main data bus.

4.8 MARIE

29

This is the MARIE data path shown graphically.

4.8 MARIE

30

• A computer’s instruction set architecture (ISA) specifies the format of its instructions and the primitive operations that the machine can perform.

• The ISA is an interface between a computer’s hardware and its software.

• Some ISAs include hundreds of different instructions for processing data and controlling program execution.

• The MARIE ISA consists of only thirteen instructions.

4.8 MARIE

31

• This is the format of a MARIE instruction:

• The fundamental MARIE instructions are:

4.8 MARIE

32

• This is a bit pattern for a LOAD instruction as it would appear in the IR:

• We see that the opcode is 1 and the address from which to load the data is 3.

4.8 MARIE

33

• This is a bit pattern for a SKIPCOND instruction as it would appear in the IR:

• We see that the opcode is 8 and bits 11 and 10 are 10, meaning that the next instruction will be skipped if the value in the AC is greater than zero.

What is the hexadecimal representation of this instruction?

4.8 MARIE

34

• Each of our instructions actually consists of a sequence of smaller instructions called microoperations.

• The exact sequence of microoperations that are carried out by an instruction can be specified using register transfer language (RTL).

• In the MARIE RTL, we use the notation M[X] to indicate the actual data value stored in memory location X, and to indicate the transfer of bytes to a register or memory location.

4.8 MARIE

35

• The RTL for the LOAD instruction is:

• Similarly, the RTL for the ADD instruction is:

MAR X MBR M[MAR] AC AC + MBR

MAR X MBR M[MAR] AC MBR

4.8 MARIE

36

• Recall that SKIPCOND skips the next instruction according to the value of the AC.

• The RTL for the this instruction is the most complex in our instruction set:

If IR[11 - 10] = 00 then If AC < 0 then PC PC + 1 else If IR[11 - 10] = 01 then If AC = 0 then PC PC + 1 else If IR[11 - 10] = 11 then If AC > 0 then PC PC + 1

4.8 MARIE

37

4.9 Instruction Processing • The fetch-decode-execute cycle is the series of steps

that a computer carries out when it runs a program. • We first have to fetch an instruction from memory,

and place it into the IR. • Once in the IR, it is decoded to determine what

needs to be done next. • If a memory value (operand) is involved in the

operation, it is retrieved and placed into the MBR. • With everything in place, the instruction is executed.

The next slide shows a flowchart of this process.

38

4.9 Instruction Processing

39

• All computers provide a way of interrupting the fetch-decode-execute cycle.

• Interrupts occur when: – A user break (e.,g., Control+C) is issued – I/O is requested by the user or a program – A critical error occurs

• Interrupts can be caused by hardware or software. – Software interrupts are also called traps.

4.9 Instruction Processing

40

• Interrupt processing involves adding another step to the fetch-decode-execute cycle as shown below.

The next slide shows a flowchart of “Process the interrupt.”

4.9 Instruction Processing

41

4.9 Instruction Processing

42

• For general-purpose systems, it is common to disable all interrupts during the time in which an interrupt is being processed. – Typically, this is achieved by setting a bit in the flags

register. • Interrupts that are ignored in this case are called

maskable. • Nonmaskable interrupts are those interrupts that

must be processed in order to keep the system in a stable condition.

4.9 Instruction Processing

43

• Interrupts are very useful in processing I/O. • However, interrupt-driven I/O is complicated, and

is beyond the scope of our present discussion. – We will look into this idea in greater detail in Chapter 7.

• MARIE, being the simplest of simple systems, uses a modified form of programmed I/O.

• All output is placed in an output register, OutREG, and the CPU polls the input register, InREG, until input is sensed, at which time the value is copied into the accumulator.

4.9 Instruction Processing

44

• Consider the simple MARIE program given below. We show a set of mnemonic instructions stored at addresses 0x100 – 0x106 (hex):

4.10 A Simple Program

45

• Let’s look at what happens inside the computer when our program runs.

• This is the LOAD 104 instruction:

4.10 A Simple Program

46

• Our second instruction is ADD 105: 4.10 A Simple Program