Assembly Language part 2. Program example 2 BR 0x0008.ASCII "#?".ASCII "\n".BLOCK 2 CHARO 0x0003, d CHARO 0x0004, d DECI 0x0006, d CHARO 0x0005, d DECO.

Slides:



Advertisements
Similar presentations
Introduction to Computing Systems from bits & gates to C & beyond Chapter 7 LC-2 Assembly Language.
Advertisements

There are two types of addressing schemes:
SPARC Architecture & Assembly Language
I/O: SPARC Assembly Department of Computer Science Georgia State University Georgia State University Updated Spring 2014.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
Cpe 252: Computer Organization1 Lo’ai Tawalbeh Programming The Basic Computer Chapter 6:
IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Ch5b BR 0x0009 ;Branch around data 0003 FFFE.WORD 0xFFFE ;First BYTE 0x00 ;Second BYTE 'U' ;Third WORD 1136 ;Fourth.
The Assembly Language Level
The Little man computer
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
Chapter 10.
Chapter 3 Assembly Language: Part 1. Machine language program (in hex notation) from Chapter 2.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Chapter 7 Low-Level Programming Languages. 2 Chapter Goals List the operations that a computer can perform Discuss the relationship between levels of.
Chapter 4 H1 Assembly Language: Part 2. Direct instruction Contains the absolute address of the memory location it accesses. ld instruction:
Dale & Lewis Chapter 5 Computing components. Let’s design a computer Generic CPU with registers −Program counter (PC) – 5 bits (size of addresses) −Instruction.
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
Assembly & Machine Languages
Assembly Language Part 5. Reference parameter/global variable model C++ reference parameters are references to the actual arguments (as opposed to copies.
Assembly Language part 1.
Computer Organization - Syscalls David Monismith Jan. 28, 2015 Based on notes from Patterson and Hennessy Text and from Dr. Bill Siever.
CPS120: Introduction to Computer Science
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Implementation of a Stored Program Computer ITCS 3181 Logic and Computer Systems 2014 B. Wilkinson Slides2.ppt Modification date: Oct 16,
CSC 2400 Computer Systems I Lecture 5 Pointers and Arrays.
VARIABLES & CONSTANTS. Objective By the end of the lesson students should be able to:  Define a constant  Define a variable  Understand the rules for.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Kirk Scott Computer Science The University of Alaska Anchorage 1.
© GCSE Computing Candidates should be able to:  describe the characteristics of an assembler Slide 1.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Integers/Characters Input/Output Integers and Characters Input/Output System Calls. syscall Trap Handler Services for Integers and Characters Read Integer,
MIPS Architecture Topics –What resources MIPS assembly manipulates –CPU (Central Processing Unit) –ALU (Arithmetic & Logical Unit), Registers –Memory –I/O.
Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6.
Chapter 16 Pointers and Arrays Pointers and Arrays We've seen examples of both of these in our LC-3 programs; now we'll see them in C. Pointer Address.
Assembly Language Lecture 2. Lecture Outline Program Structure Memory models Data Segment Stack Segment Code Segment Input and Output Instructions INT.
EE345 Chapter 2 Lecture 3 April 4. Quiz every Wednesday 1 quiz = 1% extra credit five quizzes before midterm  5% for midterm. five quizzes before final.
Computer Science 210 Computer Organization Machine Language Instructions: Control.
The Little man computer
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Integers/Characters Input/Output
CHAPTER 6: The Little Man Computer
Chapter 3 Machine Language and Assembly Language.
Chapter 3 Machine Language and Assembly Language.
L7 – Assembler Directives
Computer Organization and Assembly Language (COAL)
BIC 10503: COMPUTER ARCHITECTURE
Chapter 7 LC-2 Assembly Language.
Ken D. Nguyen Department of Computer Science Georgia State University
Computer Programming Machine and Assembly.
Assembler CASE Tool.
CSCE Fall 2013 Prof. Jennifer L. Welch.
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Chapter 7 LC-2 Assembly Language.
ECEG-3202 Computer Architecture and Organization
Computer Architecture
Chapter 16 Pointers and Arrays
Chapter 7 Assembly Language
ECEG-3202 Computer Architecture and Organization
CSCE Fall 2012 Prof. Jennifer L. Welch.
The Von Neumann Machine
Computer Systems and Assembly Language Input and output operations
The .ASCII and .END Assembler Input ;Stan Warford ;January 13, 2005
Generalities for Assembly Language
Ken D. Nguyen Department of Computer Science Georgia State University
Presentation transcript:

Assembly Language part 2

Program example 2 BR 0x0008.ASCII "#?".ASCII "\n".BLOCK 2 CHARO 0x0003, d CHARO 0x0004, d DECI 0x0006, d CHARO 0x0005, d DECO 0x0006, d STOP.END go past data – minimizes offset calculations (contrast with data after code) “constant” declarations “variable” declaration output prompt read number output newline character output number

Data declaration & storage The previous example included two different types of data declaration instructions: –the.ASCII pseudo-op is used to allocate a contiguous set of bytes large enough to hold the specified data; as with Java & C++, the backslash character (\) is used as the escape character for control codes, like newline –the.BLOCK pseudo-op allocates the specified number of bytes and initializes their values to 0

Data declaration & storage Two other pseudo-ops provide data storage: –the.WORD instruction allocates two bytes, suitable for storage of integers –the.BYTE instruction allocates one byte, suitable for storage of characters –like.ASCII (and unlike.BLOCK), both of these instructions allow the programmer to specify initial values, as shown on next slide

Initialization examples.WORD 7; allocates 2 bytes, with ; decimal value 7.BYTE 0x2B; allocate 1 byte, with hex ; value 2B (‘+’)

I/O instructions The DECI and DECO instructions considerably ease the process of reading and writing numbers Each one deals with word-size data, and represent instructions not available in the underlying machine language – thus they are part of the set of unimplemented op codes The actual I/O is performed by the operating system; the instructions generate program interrupts that allow the OS to temporarily take over to provide a service to the program

I/O instructions The CHARI and CHARO instructions are simply assembly language versions of the machine language input and output instructions: –read or write a byte of data –data source (for output) and destination (for input) are memory (not registers)

I/O instructions STRO is yet another example of an unimplemented op code Outputs a string of data –String can be predefined with the.ASCII pseudo-op –Predefined string must be terminated with a null character: “\x00”

Arranging instructions and data In the first program example (see Monday’s notes), as with all of the machine language examples, instructions were placed first, ended with a STOP code, and data followed Problems with this approach: –requires address calculations based on the number of instructions (which may not be known as you’re writing a particular instruction) –addresses may have to be adjusted if even minor changes are made to the program

Putting the data first An easy solution to the problems described on the previous slide was illustrated by the program example; the solution is twofold: –declare the data first –place an unconditional branch instruction at the beginning of the program, pointing to the first instruction after the data –the following example provides another illustration

Program example 3 br 0x0020 ; bypass data.block 4 ; space for 2 ints.ascii "Enter a number: \x00".ascii " + \x00".ascii " = \x00" stro 0x0007,d ; prompt deci 0x0003,d ; get 1st number stro 0x0007,d ; prompt deci 0x0005,d ; get 2nd number deco 0x0003,d ; output 1st number stro 0x0018,d ; output ascii string " + " deco 0x0005,d ; output 2nd number stro 0x001c,d ; output string " = " lda 0x0003,d ; put the first # in A adda 0x0005,d ; add 2nd # to first sta 0x0003,d ; store sum deco 0x0003,d ; output sum stop.end

Program example 4: using labels br code pirate:.ASCII "Arrr!\x00" code: stro pirate,d STOP.END