Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Understanding Computer Organization: MARS Simulator Programming, Slides of Architecture

An introduction to computer organization, specifically the von Neumann architecture and machine language. It covers the concept of a fetch-decode-execute cycle, the need for interpreters and compilers, and the use of the MARS simulator for exploring machine-level instructions. Examples of simple programs and more complex algorithms are included.

What you will learn

  • What is the fetch-decode-execute cycle and how does it relate to computer organization?
  • What is the difference between interpreters and compilers in programming?
  • How can the MARS simulator be used to explore machine-level instructions?

Typology: Slides

2021/2022

Uploaded on 09/27/2022

ellen.robinson
ellen.robinson 🇬🇧

4.8

(8)

222 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
UNIT 8C
Computer Organization:
The Machine’s Language
15110 Principles of Computing,
Carnegie Mellon University - CORTINA 1
von Neumann Architecture
Most computers follow the fetch-decode-
execute cycle introduced by John von
Neumann.
Fetch next instruction from memory.
Decode instruction and get any data it needs
(possibly from memory).
Execute instruction with data and store results
(possibly into memory).
Repeat.
15110 Principles of Computing,
Carnegie Mellon University - CORTINA 2
pf3
pf4
pf5

Partial preview of the text

Download Understanding Computer Organization: MARS Simulator Programming and more Slides Architecture in PDF only on Docsity!

UNIT 8C

Computer Organization:

The Machine’s Language

Carnegie Mellon University - CORTINA^ 15110 Principles of Computing, 1

von Neumann Architecture

• Most computers follow the fetch-decode-

execute cycle introduced by John von

Neumann.

  • Fetch next instruction from memory.
  • Decode instruction and get any data it needs

(possibly from memory).

  • Execute instruction with data and store results

(possibly into memory).

  • Repeat.

Carnegie Mellon University - CORTINA^ 15110 Principles of Computing, 2

Programming a Machine

  • All instructions for a program are stored in computer

memory in binary, just like data.

  • A program is needed that translates human readable

instructions (e.g. in Ruby) into binary instructions

(“machine language”).

  • An interpreter is a program that translates one instruction at a time into machine language to be executed by the computer.
  • A compiler is a program that translates an entire program into machine language which is then executed by the computer. Carnegie Mellon University - CORTINA^ 15110 Principles of Computing, 3

MARS

Memory Array Redcode Simulator

• A simulated computer system that we can use

to explore how to run instructions at the

machine level.

  • To use this in Ruby, we need to run

include MARSLab

• We can program this virtual machine in

assembly language (a human readable form of

machine language) called Redcode.

Carnegie Mellon University - CORTINA^ 15110 Principles of Computing, 4

Running the Program in irb (cont’d)

Carnegie Mellon University - CORTINA^ 15110 Principles of Computing, 7

include MARSLab => Object m = make_test_machine(“simple.txt”) => #<MiniMARS mem = [DAT #0 #4,...] pc = [*2]> m.dump 0000: DAT #0 # 0001: DAT #0 # 0002: ADD -2 - 0003: DAT #0 # => nil

add the data 2 words back to the data 1 word back

Program starts at address 2 in “memory”

x DAT # y DAT # simple ADD x, y DAT #

“memory”addresses

Running the Program in irb (cont’d)

m.step => ADD -2 - m.dump 0000: DAT #0 # 0001: DAT #0 # 0002: ADD -2 - 0003: DAT #0 # => nil m.status Run: continue PC: [ *3 ]

Carnegie Mellon University - CORTINA^ 15110 Principles of Computing, 8

x DAT # y DAT # simple ADD x, y DAT #

y has been updated

PC = Program Counter The PC indicates where the next instruction is located (e.g. address 3).

Running the Program in irb (cont’d)

m.step => DAT #0 # m.dump 0000: DAT #0 # 0001: DAT #0 # 0002: ADD -2 - 0003: DAT #0 # => nil m.status Run: halt

Carnegie Mellon University - CORTINA^ 15110 Principles of Computing, 9

x DAT # y DAT # simple ADD x, y DAT #

nothing has changed

The MARS simulator executed an instruction with opcode 0 (halt) and has halted.

Looping Example

Multiply x * y.

Algorithm: Add x to an accumulator y times.

Example: Compute 5 * 9:

x DAT # y DAT # acc DAT # mult ADD x, acc ; add x to acc SUB #1, y ; subtract 1 from y JMN mult, y ; jump to label mult ; if y is not zero end mult Carnegie Mellon University - CORTINA^ 15110 Principles of Computing, 10

Example: Fahrenheit to Celsius

start MOV fahr, ftmp SUB #32, ftmp mult ADD ftmp, acc SUB #1, count JMN mult, count div SUB #9, acc SLT #0, acc DAT #0 ; halt ADD #1, cels JMP div end start Carnegie Mellon University - CORTINA^ 15110 Principles of Computing, 13

set ftmp = fahr - 32

add ftmp to acc 5 times (count starts off at 5) divide acc by 9: subtract 9 from acc and add 1 to cels to see how many times 9 divides into acc

skip next instruction if 0 is less than acc always jump to label div