1 Classical Universal Computer 3



Similar documents
MICROPROCESSOR AND MICROCOMPUTER BASICS

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

Central Processing Unit (CPU)

CHAPTER 7: The CPU and Memory

Administrative Issues

Instruction Set Architecture (ISA)

MACHINE ARCHITECTURE & LANGUAGE

Notes on Assembly Language

CPU Organisation and Operation

(Refer Slide Time: 00:01:16 min)

CPU Organization and Assembly Language

Lecture 3 Addressing Modes, Instruction Samples, Machine Code, Instruction Execution Cycle

Summary of the MARIE Assembly Language

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

8085 INSTRUCTION SET

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

PART B QUESTIONS AND ANSWERS UNIT I

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

CS101 Lecture 26: Low Level Programming. John Magee 30 July 2013 Some material copyright Jones and Bartlett. Overview/Questions

Z80 Instruction Set. Z80 Assembly Language

OAMulator. Online One Address Machine emulator and OAMPL compiler.

UNIVERSITY OF CALIFORNIA, DAVIS Department of Electrical and Computer Engineering. EEC180B Lab 7: MISP Processor Design Spring 1995

Instruction Set Architecture

PROBLEMS (Cap. 4 - Istruzioni macchina)

Computer Architecture Lecture 2: Instruction Set Principles (Appendix A) Chih Wei Liu 劉 志 尉 National Chiao Tung University

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Computer organization

Instruction Set Design

İSTANBUL AYDIN UNIVERSITY

Computer Organization and Architecture

CHAPTER 4 MARIE: An Introduction to a Simple Computer

Compilers I - Chapter 4: Generating Better Code

Central Processing Unit Simulation Version v2.5 (July 2005) Charles André University Nice-Sophia Antipolis

Chapter 7D The Java Virtual Machine

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

Chapter 01: Introduction. Lesson 02 Evolution of Computers Part 2 First generation Computers

A3 Computer Architecture

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

EC 362 Problem Set #2

Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:

2) Write in detail the issues in the design of code generator.

High level code and machine code

Microprocessor & Assembly Language

Machine Architecture and Number Systems. Major Computer Components. Schematic Diagram of a Computer. The CPU. The Bus. Main Memory.

Chapter 2 Topics. 2.1 Classification of Computers & Instructions 2.2 Classes of Instruction Sets 2.3 Informal Description of Simple RISC Computer, SRC

How It All Works. Other M68000 Updates. Basic Control Signals. Basic Control Signals

1 Description of The Simpletron

MICROPROCESSOR BCA IV Sem MULTIPLE CHOICE QUESTIONS

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Chapter 5 Instructor's Manual

The previous chapter provided a definition of the semantics of a programming

BASIC COMPUTER ORGANIZATION AND DESIGN

2011, The McGraw-Hill Companies, Inc. Chapter 3

EE282 Computer Architecture and Organization Midterm Exam February 13, (Total Time = 120 minutes, Total Points = 100)

M6800. Assembly Language Programming

Chapter 4 Register Transfer and Microoperations. Section 4.1 Register Transfer Language

Computer Science 281 Binary and Hexadecimal Review

MACHINE INSTRUCTIONS AND PROGRAMS

LC-3 Assembly Language

LSN 2 Computer Processors

LABORATORY MANUAL EE0310 MICROPROCESSOR & MICROCONTROLLER LAB

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

COMPUTERS ORGANIZATION 2ND YEAR COMPUTE SCIENCE MANAGEMENT ENGINEERING JOSÉ GARCÍA RODRÍGUEZ JOSÉ ANTONIO SERRA PÉREZ

BCD (ASCII) Arithmetic. Where and Why is BCD used? Packed BCD, ASCII, Unpacked BCD. BCD Adjustment Instructions AAA. Example

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

Systems I: Computer Organization and Architecture

CPU Sim 3.1: A Tool for Simulating Computer Architectures for CS3 classes

Z80 Microprocessors Z80 CPU. User Manual UM Copyright 2014 Zilog, Inc. All rights reserved.

Introduction to Microcontrollers

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

HC12 Assembly Language Programming

Chapter 2 Assemblers

Computer Architecture Lecture 3: ISA Tradeoffs. Prof. Onur Mutlu Carnegie Mellon University Spring 2013, 1/18/2013

Chapter 2 Logic Gates and Introduction to Computer Architecture

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

8051 MICROCONTROLLER COURSE

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

ASSEMBLY LANGUAGE PROGRAMMING (6800) (R. Horvath, Introduction to Microprocessors, Chapter 6)

An Overview of Stack Architecture and the PSC 1000 Microprocessor

B.Sc.(Computer Science) and. B.Sc.(IT) Effective From July 2011

l C-Programming l A real computer language l Data Representation l Everything goes down to bits and bytes l Machine representation Language

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Unpacked BCD Arithmetic. BCD (ASCII) Arithmetic. Where and Why is BCD used? From the SQL Server Manual. Packed BCD, ASCII, Unpacked BCD

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

X86-64 Architecture Guide

Instruction Set Architecture. Datapath & Control. Instruction. LC-3 Overview: Memory and Registers. CIT 595 Spring 2010

Addressing The problem. When & Where do we encounter Data? The concept of addressing data' in computations. The implications for our machine design(s)

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Assembly Language Programming

IBCM: The Itty Bitty Computing Machine

Central Processing Unit

1 Computer hardware. Peripheral Bus device "B" Peripheral device. controller. Memory. Central Processing Unit (CPU)

CSCI 4717 Computer Architecture. Function. Data Storage. Data Processing. Data movement to a peripheral. Data Movement

We will use the accumulator machine architecture to demonstrate pass1 and pass2.

CSE 141L Computer Architecture Lab Fall Lecture 2

The stack and the stack pointer

Basic Computer Organization

In this Chapter you ll learn:

Transcription:

Chapter 6: Machine Language and Assembler Christian Jacob 1 Classical Universal Computer 3 1.1 Von Neumann Architecture 3 1.2 CPU and RAM 5 1.3 Arithmetic Logical Unit (ALU) 6 1.4 Arithmetic Logical Unit (ALU) 7 2 Machine Language 10 2.1 Hypothetical Machine 12 2.2 Machine Language 13 2.3 Execution of Machine Programs 15 3 Assembler Language 16 3.1 Structure of Assembler Commands 17 3.2 From Assembler to Machine Code 19 3.3 Operand Addressing 20 3.4 Stack 27 3.5Symbolic Names 29 TOC 1 Back

Chapter 6: Machine Language and Assembler Christian Jacob 4 Programming in Assembler 31 4.1 Alternatives 31 4.2 Loops 32 4.3 Sub-routines 34 4.4 Macros 39 4.5Registers 41 TOC 2 Back

Classical Universal Computer Chapter 6: Machine Language and Assembler Christian Jacob 1 Classical Universal Computer 1.1 Von Neumann Architecture Control Unit Input Unit Memory Output Unit ALU Burks, Goldstine, von Neumann (Princeton, 1946/47) First Back TOC 3 Prev Next Last

Classical Universal Computer Chapter 6: Machine Language and Assembler Christian Jacob Von Neumann Architecture The computer architecture is problem-independent. --> Universal Computer: - Arithmetic Logical Unit - Memory - Control Unit - Input / Output Unit Program and data both reside in memory. Each memory location has an address, through which its contents can be accessed. In general, program commands are stored in consecutive memory locations. There are jump commands. There are conditional jumps. The binary number system is used. First Back TOC 4 Prev Next Last

Classical Universal Computer Chapter 6: Machine Language and Assembler Christian Jacob 1.2 CPU and RAM RAM Random Access Memory RAM contains data and instructions (programs) how to process the data Data bus transports data from RAM to the CPU for processing Data bus transports the processed data to RAM, so it can be displayed, output, or stored on disk CPU Central Processing Unit The CPU processes data First Back TOC 5 Prev Next Last

Classical Universal Computer Chapter 6: Machine Language and Assembler Christian Jacob 1.3 Arithmetic Logical Unit (ALU) Data RAM Result ALU Register 1 Register 2 Control Unit op Accumulator First Back TOC 6 Prev Next Last

Classical Universal Computer Chapter 6: Machine Language and Assembler Christian Jacob 1.4 Arithmetic Logical Unit (ALU) Data RAM Result ALU Register 1 Register 2 4 5 Control Unit Addition + 9 Accumulator First Back TOC 7 Prev Next Last

Classical Universal Computer Chapter 6: Machine Language and Assembler Christian Jacob ALU / RAM Performance: 1. The data to be processed arrives from RAM and is held in registers. 2. A signal from the Control Unit indicates which arithmetic or logical operation to perform. 3. The ALU performs the operation and places the result in the accumulator. 4. The results are usually sent to RAM so that they can be output or stored on disk. First Back TOC 8 Prev Next Last

Classical Universal Computer Chapter 6: Machine Language and Assembler Christian Jacob A more detailed look at a von Neumann architecture machine Control Unit Memory Unit Arithmetic Logical Unit I/O Unit Command IP ALU Unit MR MSR MR OP AP LC IOR OD Memory ACC QR OC RAM Feedback / Control Signals OP: operator part OC: operation control LC: logical circuits AP: address part MR: memory register ACC: accumulator IP: instruction pointer MSR: memory selection reg. QR: quotient register OD: operator decoding MR: multiplier register IOR: input/output reg. First Back TOC 9 Prev Next Last

Machine Language Chapter 6: Machine Language and Assembler Christian Jacob 2 Machine Language Elementary operations: - data transfer - program control - arithmetic and logic operations - move operations - interrupt handling Binary command representation regular structure of all the commands First Back TOC 10 Prev Next Last

Machine Language Chapter 6: Machine Language and Assembler Christian Jacob command formats: - 1-address command Operation Address of Operand 2-2-address command Operation Address of Operand 1 & Result Address of Operand 2-3-address command Operation Address of Operand 1 Address of Operand 2 Address of Result First Back TOC 11 Prev Next Last

Machine Language Chapter 6: Machine Language and Assembler Christian Jacob 2.1 Hypothetical Machine Word length: 16 bit Structure of a memory cell (1-address command) 1512 11 10 8 7 0 Op Code D Mod Address / Value Op Code: command code for an operation D: label for a double word Mod: Address/value: modification part (using index registers) contains address or value of the operand First Back TOC 12 Prev Next Last

Machine Language Chapter 6: Machine Language and Assembler Christian Jacob 2.2 Machine Language Opcode dual hex. Description of the Operation Mnemo. 0000 0 Halt. End of program execution HLT 0001 1 Load operand to accumulator LOA 0010 2 Store accumulator at designated address STI 0011 3 Add operand to accumulator ADD 0100 4 Subtract operand from accumulator SUB 0101 5 Multiply operand with accumulator MUL 0110 6 Divide accumulator by operand DIV 0111 7 Unconditional jump JMP 1000 8 Jump if accumulator = 0 JEZ 1001 9 Jump if accumulator > 0 JGZ 1010 A Jump if accumulator < 0 JLZ 1100 C Stack commands - 1101 D Jump to subroutine JSR 1110 E Return from subroutine RET 1111 F Index commands - First Back TOC 13 Prev Next Last

Machine Language Chapter 6: Machine Language and Assembler Christian Jacob Example: The word 0011 0100 1001 1101 in a memory cell can be decimal number: 13469 command: 0011 0 100 10011101-0011: add operand to accumulator - 0: one word command - 100: constant operand ( immediate operand ) - 10011101: 157 10 --> Add 157 to the contents of the accumulator. First Back TOC 14 Prev Next Last

Machine Language Chapter 6: Machine Language and Assembler Christian Jacob 2.3 Execution of Machine Programs Load jump address Instruction Pointer Program address 1 Load data address Fetch opcode and mod Increment instruction pointer Memory Addressing Control Unit 3 3 5 RAM ALU Accu 4 Load constant Load/store data Load instruction 2 Address / Operator Constant Instruction Register First Back TOC 15 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob 3 Assembler Language Disadvantages of machine language: - Binary / hexadecimal representation of operations and operands - Use of fixed addresses - No commentary Assembler - Mnemo-technical names of operations - Various number systems - Commentaries - Macros Example machine language: 0011 0100 1001 1101 assembler: ADD, #157 First Back TOC 16 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob 3.1 Structure of Assembler Commands Label - characterizes an assembler command - jump commands can use this label as destination - usually a string consisting of 4 to 8 letters - is not inserted into the (generated) machine code Operation - mnemo-technical representation of the Op-code Operand(s) - contains the operands of the assembler command (value of the operand or an address) - (constant) expressions may be allowed Register field - for machines with 2-address commands: reference to a register which contains one of the operands First Back TOC 17 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob Index field - refers to the register, the contents of which is to be added to the operand address. Commentary - remarks and comments on the program text - not inserted into the (generated) machine code Formating of assembler code fixed structure, column-oriented or fields separated by special characters (example: labels by :, comments by ; ) or field separators (tabs, space, ) First Back TOC 18 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob 3.2 From Assembler to Machine Code Assembler: label operator operand register field commentary index register Machine code: operator mod operand(s) First Back TOC 19 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob 3.3 Operand Addressing Effective address = address generated by interpreting (or by address calculation) or the modification field Immediate operand commands - the address field contains the operand as a constant - labelled by # - machine code: Mod = 100-8 bit (24 bit for 2-word commands) --> integer numbers between -128 and 127 - Example: ADD, #26 ; add 26 to accumulator Accumulator x Accumulator x+26 First Back TOC 20 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob Direct address - effective address = contents of address field - labelled by @ - machine code: Mod = 0 - bits 8 and 9 (Mod) are used as additional address bits --> 2 10 = 1024 memory cells are directly addressable - Example: STI, @649 ; store accu at address 649 Accumulator 123 649 123 RAM First Back TOC 21 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob Relative addressing - effective address = command address + address field --> the program is relocatable in memory without any recalculation of the addresses - no labelling - machine code: Mod = 101 - Example: ADD, 148 ; add value at relative address 148 Accumulator x+123 RAM 100 ADD, 148 248 123 First Back TOC 22 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob Indirect addressing - effective address = value at the address given in the address field - labelled by (...) - machine code: Mod = 110 - Example: STI, (148) ; indirect addressing Accumulator 123 148 250 RAM 250 123 First Back TOC 23 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob Index register addressing - effective address = address field + contents of index register --> Without any program changes, all effective addresses can be changed by modifying the contents of the index register. - labelled by % - machine code: Mod = 111 - Example: LOA, %128 ; use index register Accumulator 123 Index Register 100 + 128 228 123 RAM First Back TOC 24 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob - special index register commands: Opcode Mod Ass. Description 1111 000 CLI Load 0 to index register. 1111 001 LDI Load accu into index register. 1111 010 LIA Load index register into accu. 1111 011 INC Increment index register by 1. 1111 100 DEC Decrement index register by 1. 1111 111 LDX Load operand into index register. First Back TOC 25 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob Example: Programming with an index register LDX, @1030 ; load index register with contents ; of memory cell 1030 LOA, #15 ; load 15 to accumulator ADD, %3 ; add the contents of memory cell ; 3+index register to the accu STI, (1031) ; store the result at the address ; contained in memory cell 1031 HLT ; end of program Step Index reg. Accu Memory 1 1050-1030: 1050 1031: 1039 1053: 17 2 15 3 32 4 1039: 32 First Back TOC 26 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob 3.4 Stack LIFO principle (Last In, First Out) Push A Push B Push C Pop Pop Pop C B B B A A A A A For binary operations: - first operand is the second element from the top of stack - second operand is the top of stack element - the operation result replaces the two top-most stack elements First Back TOC 27 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob Stack Commands: Opcode Mod Ass. Description 1100 0001 PUSHAC Load accumulator to stack 1100 0010 POPAC Load top stack element to accumulator and remove from stack 1100 0011 ADDST Addition 1100 0100 SUBST Subtraction 1100 0101 MULST Multiplication 1100 0110 DIVST Division 1100 1011 PUSH Load operand to stack 1100 1100 POP Store top stack element at designated address and remove from stack First Back TOC 28 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob 3.5 Symbolic Names Symbolic names can be associated with an address: Value The name is associated to a numerical value. Example: NUMB EQUIVALENT 1073... LOA, @NUMB Labels Labels are symbolic names associated to an assembler command. Example: START: LOA, #5 JMP, @START First Back TOC 29 Prev Next Last

Assembler Language Chapter 6: Machine Language and Assembler Christian Jacob Data definitions and memory allocation Example: LOA, @CONST MUL, #2 STI, @ARRAY HLT CONST: DATA, #300; memory cell initialized ; with a value of 300 ARRAY: BLOCK,20 ; array of 20 memory cells First Back TOC 30 Prev Next Last

Programming in Assembler Chapter 6: Machine Language and Assembler Christian Jacob 4 Programming in Assembler 4.1 Alternatives if ( <condition> ) <command A> else <command B> Example: if ( x < y ) A else B Assembler: LOA, @x ; accu = x SUB, @y ; accu = x-y JLZ, @LABELA ; x-y < 0? <B> LABELA: <A> CONTINUE: First Back TOC 31 Prev Next Last

Programming in Assembler Chapter 6: Machine Language and Assembler Christian Jacob 4.2 Loops Example: C++: do { x = 4*a; a = a+k; } while ( a <= endvalue ); First Back TOC 32 Prev Next Last

Programming in Assembler Chapter 6: Machine Language and Assembler Christian Jacob Assembler: LOOP: LOA, #4 ; accu = 4 MUL, @a ; accu = 4*a STI, @x ; x = 4*a LOA, @a ; accu = a ADD, @k ; accu = a+k STI, @a ; a = a+k SUB, @endvalue; accu = a-endvalue JLZ, @LOOP ; a < endvalue? JEZ, @LOOP ; a = endvalue? do { x = 4*a; a = a+k; } while ( a <= endvalue ); First Back TOC 33 Prev Next Last

Programming in Assembler Chapter 6: Machine Language and Assembler Christian Jacob 4.3 Sub-routines main program... call of subroutine JSR... end of program RET sub routine... return to main Two Problems: Where to store the return address? Passing of parameters and return of results First Back TOC 34 Prev Next Last

Programming in Assembler Chapter 6: Machine Language and Assembler Christian Jacob Return Addresses: - store in memory cell before or after the subroutine code - use a stack First Back TOC 35 Prev Next Last

Programming in Assembler Chapter 6: Machine Language and Assembler Christian Jacob 1000 Using a stack for storing return addresses main program... 1310 1385 1415 1430 1470 1507 call of A... sub routine A... call of B... return sub routine B... call of C Command Instruction Pointer Stack Start main program 1000 - Call subroutine A 1310 - Jump to subroutine A 13851311 Call subroutine B 14151311 Jump to subroutine B 1470 1416 1311 Return from subroutine B 1550 1416 1311 Continue in subroutine A 1416 1311 Return from subroutine B 1430 1311 Continue in main program 1311-1550... return Note: Intermediate commands not related to subroutine calls are not listed in this table. First Back TOC 36 Prev Next Last

Programming in Assembler Chapter 6: Machine Language and Assembler Christian Jacob Passing of Parameters and Return of Subroutine Results Parameter passing using the accumulator or another register --> number of parameters is limited Store parameters at specific memory addresses and reading in from within the subroutine --> complex memory management, hard to keep up with used memory space Use memory section prior to the subroutine --> enables relative addressing of the parameters within the subroutine Use memory section after the subroutine --> enables relative addressing, too Parameter passing using a stack First Back TOC 37 Prev Next Last

Programming in Assembler Chapter 6: Machine Language and Assembler Christian Jacob Parameter Passing Using a Stack ; Main program PUSH, @PARAM1 PUSH, @PARAM2 PUSH, #7 ; return address JSR, @UP1 POP, @RESULT1 UP1: POP, @RETURNADDR ; subroutine POP, @UPPARAM2 POP, @UPPARAM1 ; subroutine calc. PUSH, @UPRESULT PUSH, @RETURNADDR RET First Back TOC 38 Prev Next Last

Programming in Assembler Chapter 6: Machine Language and Assembler Christian Jacob 4.4 Macros Macros perform textual substitutions Macros are expanded before the assembler is started Program Text Macro Generator Assembler Commands Assembler Program in Machine Code Example: MACRO, sum ; macro head LOA, @OP1 ; macro body ADD, @OP2 STI, @RESULT MACROEND First Back TOC 39 Prev Next Last

Programming in Assembler Chapter 6: Machine Language and Assembler Christian Jacob Application of the macro sum: SPI, @OP1 LOA, #1024 STI, @OP2 sum LOA, @RESULT SPI,@OP1 LOA, #1024 STI, @OP2 LOA, @OP1 ADD, @OP2 SPI, @RESULT LOA, @RESULT First Back TOC 40 Prev Next Last

Programming in Assembler Chapter 6: Machine Language and Assembler Christian Jacob 4.5 Registers Today s computers have many more registers --> The assembler must be able to address these registers. Extension of assembler language: Example: LOA, R5, @300 First Back TOC 41 Prev Next Last