CEG 320/520: Computer Organization and Assembly Language Programming1 Assembly Language Programming Assembler Directives and The Symbol Table.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

Intermediate Code Generation
1 ARM Movement Instructions u MOV Rd, ; updates N, Z, C Rd = u MVN Rd, ; Rd = 0xF..F EOR.
Assembly Language Programming
The 8051 Microcontroller and Embedded Systems
Chapter 10- Instruction set architectures
Stack Frames: Using LINK. CEG 320/5208: Stack frames and LINK2 Assembling source code One source file: –Use ORG statements for data and code –Assemble.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
The Assembly Language Level
MICRO-CONTROLLER MOTOROLA HCS12 Running assembly code Mechatronics Department Faculty of Engineering Ain Shams Univeristy.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
Introduction to a Programming Environment
Assembler When a source program is a assembly language and the target program is a numerical machine language then the translator is called as a assembler.
CEG 320/520: Computer Organization and Assembly Language ProgrammingFlow Control 1 Flow Control.
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 7: Assembly Language.
A Simple Two-Pass Assembler
The Assembly Language Level Part B – The Assembly Process.
CoE3DJ4 Digital Systems Design
Assemblers.
Chapter 2 Introduction to Computer Architecture and Assembly Language.
Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal.
Introduction to 8086 Assembly Language Assembly Language Programming University of Akron Dr. Tim Margush.
9/20/6Lecture 3 - Instruction Set - Al1 Project Description.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
Passing Parameters using Stack Calling program pushes parameters on the stack one element at a time before calling subroutine. Subroutine Call (jsr, bsr)
Ass. Prof. Dr Masri Ayob TK 6123 Lecture 13: Assembly Language Level (Level 4)
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Computer Science 210 Computer Organization More on Assembler.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
9/20/6Lecture 2 - Prog Model Architecture, Data Types and Addressing Modes.
1 Segments and Pseudo Operations Program Development.
Addressing Modes1 Addressing modes are concerned with how the CPU accesses the operands used by its instructions.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Machine Independent Assembler Features
Topics covered: Instruction Set Architecture CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Processor Fundamentals Assembly Language. Learning Objectives Show understanding of the relationship between assembly language and machine code, including.
1 EKT 225 MICROCONTROLLER I CHAPTER ASSEMBLY LANGUAGE PROGRAMMING.
Translating Assembly Language to Machine Language.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
PROGRAMMING THE BASIC COMPUTER
Computer Science 210 Computer Organization
Chapter 7 Assembly Language
Machine Independent Assembler Features
Assembly Language Ms. V.Anitha AP/CSE SCT
Data Types, Identifiers, and Expressions
The 8051 Microcontroller and Embedded Systems
Additional Assembly Programming Concepts
Chapter 7 Assembly Language
Chapter 3 Machine Language and Assembly Language.
Machine Independent Assembler Features
Chapter 3 Machine Language and Assembly Language.
Assembler Design Options
Assembler Design Options
Computer Science 210 Computer Organization
Assembler CASE Tool.
Data Types, Identifiers, and Expressions
COMP2121: Microprocessors and Interfacing
68000 Architecture, Data Types and Addressing Modes
Introduction to Micro Controllers & Embedded System Design
A Simple Two-Pass Assembler
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
Chapter 7 Assembly Language
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
Chapter 6 Programming the basic computer
Example 1: (expression evaluation)
Program Pass I LC Symbol Table Pass II Machine Code ORG $400
Introduction to 8086 Assembly Language
Location Counter (LC) = 0 while line of code <> END if ORG
Presentation transcript:

CEG 320/520: Computer Organization and Assembly Language Programming1 Assembly Language Programming Assembler Directives and The Symbol Table

CEG 320/520: Computer Organization and Assembly Language Programming2 Assembler Directives: Introduction Assembler directives give information to the assembler. They can be used to declare variables, create storage space for results, to declare constants, and to label locations in the code to be used as branch destinations. Most assemblers are ‘two-pass assemblers’. –They read through the code once, looking for labels, and use them to create the ‘symbol table’. The symbol table is a mapping between labels and values. –On the second pass, they replace each occurrence of a label with its value from the symbol table. Coding tip: Labels MUST be left justified, not indented. First character must be a letter (not a number). Assembler only looks at first 8 characters.

CEG 320/520: Computer Organization and Assembly Language Programming3 Assembler Directives: Origin (ORG) Tells the assembler where to place your code in memory. Operand given is the desired memory location. – ORG $ ; sets origin to be $ Generally, we’ll put our code at $ and our data (declared with DC, DS, etc) at $

CEG 320/520: Computer Organization and Assembly Language Programming4 Assembler Directives: Declare Constant (DC) Declares a named variable in memory. The term ‘constant’ is misleading, because the contents of that memory location can be changed. Use DC.B, DC.W, DC.L to declare different sizes of variables. Operand given is initial value of variable. –VAR DC.W $40 ; places $40 in memory location pointed ; to by VAR. Symbol table: the value of a label declared with DC is the memory location of the label.

CEG 320/520: Computer Organization and Assembly Language Programming5 Assembler Directives: Declare Storage (DS) Reserves space in memory for the result of a future operation or future variables. Use DS.B, DS.W, DS.L to declare different sizes of empty storage. Operand given is number of spaces to allocate, where the size of a space is determined by the extension (B,W,L) –ARR DS.W 5 ; reserves 5 words in memory for ARR Symbol table: the value of a label declared with DS is the memory location of the label.

CEG 320/520: Computer Organization and Assembly Language Programming6 Assembler Directives: equal to (EQU) Declares a constant value. No need for extension here, assembler will treat the number appropriately. Operand given is value to assign to label. –CONST EQU 5 ; sets the value of CONST to 5 Symbol table: the value of a label declared with EQU is the value, NOT THE MEMORY LOCATION. EQU does not cause anything to be stored in memory.

CEG 320/520: Computer Organization and Assembly Language Programming7 Assembler Directives: Code labels Labels an instruction in the program so that it can be used as a branch target. All instructions are indented; a code label is added by putting a left justified label on the same line. –LOOP ADD D1,D0 ; LOOP is the code label Symbol table: the value of a code label is the memory location of the instruction on that line.

CEG 320/520: Computer Organization and Assembly Language Programming8 Assembler Directives: end of code (END) Tells the assembler to stop looking for more code. This should be the last line in any code file you write.

CEG 320/520: Computer Organization and Assembly Language Programming9 The Symbol Table Most assemblers are two-pass assemblers. –On the first pass, any labels found in the program are put into the symbol table along with the corresponding numerical value. Code labels – memory location of instruction Variable labels (DS, DC) – memory location of reserved memory Constants (EQU) – value of constant –On the second pass, all labels in the code are replaced with their values from the symbol table. Why use two passes? –If the program contains a branch to a later location in the code (a forward branch), the assembler won’t know where to find the branch target because it would not have seen it yet.

CEG 320/520: Computer Organization and Assembly Language Programming10 Example: An Assembly Language Program ORG$ MOVE VAL1, D0 MOVE VAL2, D1 MUL D0, D1 ADD #CONST, D1 END ORG$ VAL1 DC3 VAL2 DC12 CONSTEQU5 What does the symbol table look like after the first pass of the assembler? What does the code look like after the second pass of the assembler?

CEG 320/520: Computer Organization and Assembly Language Programming11 Example: An Assembly Language Program ORG$ STARTCLR.LD0; sum = 0; MOVEA.L#ARRAY,A0; ptr points to the 1st array element MOVE.W#SIZE,D1; counter = SIZE; LOOPADD.W(A0)+,D0; sum += *ptr++; SUBQ.W#1,D1; counter -= 1; BGTLOOP; repeat while counter > 0; MOVE.WD0,SUM; Save the sum in memory MOVE.W#228,D7; Magic exit code TRAP#14; more magic exit code ; DATA AND CONSTANTS ORG$ SIZEEQU9; the size of the array ARRAYDC.W3,7,-5,12,23,15,-12,82,5; the array to sum SUMDS.W1; the final sum END What does the symbol table look like after the first pass of the assembler? What does the code look like after the second pass of the assembler?