Lecture 15 Today’s lecture MARIE programming Assembler

Slides:



Advertisements
Similar presentations
Lecture 5: MIPS Instruction Set
Advertisements

Assembly Code Example Selection Sort.
IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
TK 2633 Microprocessor & Interfacing
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Chapter 5 The LC-3 LC-3 Computer Architecture Memory Map
Chapter 6 Programming in Machine Language The LC-3 Simulator
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Chapter 4 H1 Assembly Language: Part 2. Direct instruction Contains the absolute address of the memory location it accesses. ld instruction:
MARIE: An Introduction to a Simple Computer
Chapter 4: A Simple Computer
Lecture 13 - Introduction to the Central Processing Unit (CPU)
Assembly & Machine Languages
Computer Science 210 Computer Organization The Instruction Execution Cycle.
MARIE: An Introduction to a Simple Computer
1 4.2 MARIE This is the MARIE architecture shown graphically.
Lecture 16 Today’s topics: –MARIE Instruction Decoding and Control –Hardwired control –Micro-programmed control 1.
Computer Science 101 Assembly Language. Problems with Machine Language Uses binary - No English-like words to make it more readable Uses binary - No English-like.
Chapter 4 MARIE: An Introduction to a Simple Computer.
Computer Science 101 How the Assembler Works. Assembly Language Programming.
Chapter 4 MARIE: An Introduction to a Simple Computer.
Chapter 4 MARIE: An Introduction to a Simple Computer.
Lecture 14 Today’s topics MARIE Architecture Registers Buses
Chapter # 6 PROGRAMING THE BASIC COMPUTER.
MARIE: An Introduction to a Simple Computer. 2 MARIE Our model computer, the Machine Architecture that is Really Intuitive and Easy, MARIE, was designed.
Chapter 4 MARIE: An Introduction to a Simple Computer.
MARIE: An Introduction to a Simple Computer. Computer Organization and Architecture:Null,L. and Lobur, J CPU Basics The computer’s CPU fetches,
September 26, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 2: Implementation of a Simplified Computer Jeremy R. Johnson Wednesday,
Represents different voltage levels High: 5 Volts Low: 0 Volts At this raw level a digital computer is instructed to carry out instructions.
ECEG-3202 Computer Architecture and Organization Chapter 6 Instruction Sets: Addressing Modes and Formats.
Lecture Overview Introduction Instruction processing A simple program
1. 2 CHAPTER 3 MARIE: An Introduction to a Simple Computer.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Writing an Assembly-language program MIPS assembly language using MARS: MIPS Assembler and Runtime Simulator CS-2710 Dr. Mark L. Hornick 1.
PROGRAMMING THE BASIC COMPUTER
PROGRAMMING THE BASIC COMPUTER
Today’s Agenda Exam 2 Part 2 (11:15am-12:30pm)
Addressing Modes in Microprocessors
PROGRAMMING THE BASIC COMPUTER
A Discussion on Assemblers
Computer Science 210 Computer Organization
MARIE: An Introduction to a Simple Computer
Installing and Using MARIE
Chapter 7 LC-2 Assembly Language.
Computer Science 210 Computer Organization
MARIE Instruction Set Architecture
Assembler CASE Tool.
PROGRAMMING THE BASIC COMPUTER
A Discussion on Assemblers
Installing and Using MARIE
Instruction and Control II
MARIE: An Introduction to a Simple Computer
ECEG-3202 Computer Architecture and Organization
Installing and Using MARIE
Sequencing, Selection, and Loops in Machine Language
PROGRAMMING THE BASIC COMPUTER
MARIE: An Introduction to a Simple Computer
MARIE: An Introduction to a Simple Computer
CS Chapter 4 Dr. Clincy Professor of CS TODAY’S AGENDA
A Discussion on Assemblers
MARIE: An Introduction to a Simple Computer
Installing and Using MARIE
MARIE: An Introduction to a Simple Computer
CS334: MIPS language _Mars simulator Lab 2_1
CS501 Advanced Computer Architecture
William Stallings Computer Organization and Architecture 8 th Edition Chapter 11 Instruction Sets: Addressing Modes and Formats.
CPSC 171 Introduction to Computer Science
Location Counter (LC) = 0 while line of code <> END if ORG
Presentation transcript:

Lecture 15 Today’s lecture MARIE programming Assembler Extending the instruction set

A Simple Program Consider the simple MARIE program given below: add two numbers together and the sum in memory. The instructions stored at addresses 0x100 – 0x106 (hex):

A Simple Program What happens inside the computer when the program runs. This is the LOAD 104 instruction:

A Simple Program Our second instruction is ADD 105:

A Simple Program The third instruction is Store 106. After the program is done, the binary content of location 0x106 change to 0x000C (12 in decimal).

A Discussion on Assemblers Mnemonic instructions, such as LOAD 104, are easy for humans to write and understand. They are impossible for computers to understand. Assemblers translate assembly language that are comprehensible to humans into the machine language that is comprehensible to computers. The assembler reads a source file (assembly program) and produces an object file ( the machine code).

Creating an Object Program Files Assemblers create an object program file from mnemonic source code in two passes. During the first pass, the assembler assembles as much of the program as it can, while it builds a symbol table that contains memory references for all symbols in the program. During the second pass, the instructions are completed using the values from the symbol table.

Creating an Object Program Files - Example The first pass, creates a symbol table and the partially-assembles instructions. After the second pass, the assembly is complete.

Extending Our Instruction Set So far, all of the MARIE instructions that we have discussed use a direct addressing mode. This means that the address of the operand is explicitly stated in the instruction. It is often useful to employ a indirect addressing, where the address of the address of the operand is given in the instruction. If you have ever used pointers in a program, you are already familiar with indirect addressing. Six new instructions using indirect addressing.

LOADI and STOREI LOADI X (load indirect): go to address X, use the value at X as the actual address of the operand to load into the AC. STOREI X (Store indirect): go to address X, use the value at X as the destination address for storing the value in the AC. In RTL: MAR  X MBR  M[MAR] MAR  MBR AC  MBR MAR  X MBR  M[MAR] MAR  MBR MBR  AC M[MAR]  MBR LOADI X STOREI X

ADDI and JUMPI The ADDI instruction is a combination of LOADI X and ADD X. JUMPI instruction: go to address X, use the value at X as the actual address of the location to jump to. In RTL: MAR  X MBR  M[MAR] MAR  MBR AC  AC + MBR MAR  X MBR  M[MAR] PC  MBR ADDI X JUMPI X

JNS and CLEAR JNS: The jump-and-store instruction gives us limited subroutine functionality: store the PC at address X and jump to X+1 CLEAR: set AC to zero. In RTL: MBR  PC MAR  X M[MAR]  MBR MBR  X AC  1 AC  AC + MBR PC  AC AC  0 CLEAR JNS X

MARIE Programming Examples Example: using a loop to add five numbers: 100 | LOAD Addr 101 | STORE Next 102 | LOAD Num 103 | SUBT One 104 | STORE Ctr 105 |Loop LOAD Sum 106 | ADDI Next 107 | STORE Sum 108 | LOAD Next 109 | ADD One 10A | STORE Next 10B | LOAD Ctr 10C | SUBT One 10D | STORE Ctr 10E | SKIPCOND 000 10F | JUMP Loop 110 | HALT 111 |Addr HEX 117 112 |Next HEX 0 113 |Num DEC 5 114 |Sum DEC 0 115 |Ctr HEX 0 116 |One DEC 1 117 | DEC 10 118 | DEC 15 119 | DEC 2 11A | DEC 25 11B | DEC 30

MARIE Programming Examples Example: use of an if/else construct to allow for selection. if 𝑋=𝑌 then 𝑋=𝑋 × 2 else 𝑌 = 𝑌 – 𝑋; 400

MARIE Programming Examples Example: a simple subroutine to double the value stored at X.

Exercise 1 Consider the MARIE program below. Hex Address Label Instruction 100 Start, LOAD A 101 ADD B 102 STORE D 103 CLEAR 104 OUTPUT 105 ADDI D 106 STORE B 107 HALT 108 A, HEX 00FC 109 B, DEC 14 10A C, HEX 0108 10B D, HEX 0000 List the hexadecimal code for each instruction. Draw the symbol table. What is the value stored in the AC when the program terminates?

Exercise 1 - Solution Consider the MARIE program below. 1108 3109 Hex Address Label Instruction 100 Start, LOAD A 101 ADD B 102 STORE D 103 CLEAR 104 OUTPUT 105 ADDI D 106 STORE B 107 HALT 108 A, HEX 00FC 109 B, DEC 14 10A C, HEX 0108 10B D, HEX 0000 List the hexadecimal code for each instruction. Draw the symbol table. What is the value stored in the AC when the program terminates? 1108 3109 210B A000 6000 B10B 2109 7000 00FC 000E 0108 0000 AC = 0108 upon termination

Exercise 2 Write the following code segment in MARIE’s assembly language: if x <= y then y = y + 1; else if x != z then y = y – 1; else z = z + 1;

Exercise 2 - Solution if x <= y then y = y + 1; else if x != z then y = y – 1; else z = z + 1;