CS2422 Assembly Language & System Programming

Similar documents

CS2422 Assembly Language & System Programming

Assemblers. System Software by Leland L. Beck. Chapter 2

Unit 2 -- Outline. Basic Assembler Functions Machine-dependent Assembler Features Machine-independent Assembler Features Assembler Design Options

Chapter 2 Assemblers Machine-Dependent Assembler Features

Chapter 3 Loaders and Linkers -- Machine-Dependent Loader Feature

2.1. Basic Assembler Functions:

Gechstudentszone.wordpress.com

INTERNAL TEST (SCHEME AND SOLUTION)

Gechstudentszone.wordpress.com

Chapter 1. Introduction

Chapter 1: Background

Chapter 2. Assembler Design

1.Program to find factorial of a given number

UNIT II ASSEMBLERS. Figure Assembler

DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


Chapter 1 Background. Professor Gwan-Hwan Hwang Dept. Computer Science and Information Engineering National Taiwan Normal University

UNIT 1: MACHINE ARCHITECTURE

CS2304-SYSTEM SOFTWARE 2 MARK QUESTION & ANSWERS. UNIT I INTRODUCTION

Chapter 3 Loaders and Linkers

UNIT 1: MACHINE ARCHITECTURE

Chapter 3 Loaders and Linkers

PESIT SOUTHCAMPUS 10CS52: SYSTEM SOFTWARE QUESTION BANK

TRB-COMPUTER INSTRUCTOR COMPUTER SCIENCE UNIT IV. SYSTEM SOFTWARE 10% DISCOUNT FOR ALL PGTRB MATERIALS WITH QUESTION BANK.

UNIT III - LOADERS AND LINKERS

Machine dependent Assembler Features

Systems Programming Assemblers Part 4 Control Sections

UNIT I - INTRODUCTION

LOADERS AND LINKERS 1. BASIC LOADER FUNCTIONS 2. DESIGN OF AN ABSOLUTE LOADER 3. A SIMPLE BOOTSTRAP LOADER 4. MACHINE DEPENDENT LOADER FEATURES

CSI 402 Lecture 5 (Assemblers Continued) 5 1 / 18

AS-2883 B.Sc.(Hon s)(fifth Semester) Examination,2013 Computer Science (PCSC-503) (System Software) [Time Allowed: Three Hours] [Maximum Marks : 30]

PESIT Bangalore South Campus Department of MCA Course Information for. System Programming (13MCA24)

Chapter 2 Assemblers Assembler Design Options

System Programming. System Software: An Introduction to Systems Programming. Leland L. Beck 3rd Edition Addison-Wesley, 1997

Introduction. Chapter 4 Macro Processors -- Basic Macro Processor Functions. Macro expansion. Basic macro processor functions

Chapter 3 Loaders and Linkers

UNIT III LOADERS AND LINKERS

Prepared By : Ms. Sanchari Saha ( Asst. Professor) Department : Computer Science & Engineering

COMPILERS BASIC COMPILER FUNCTIONS

CS1203-SYSTEM SOFTWARE UNIT I-INTRODUCTION

國立嘉義大學資訊工程學系系統程式期中考考卷

Assembler Design Options

8.7 TM: A SIMPLE TARGET MACHINE

Chapter 2 Assemblers. PDF created with FinePrint pdffactory Pro trial version

An Assembler Written in SAS Ed Heaton, Westat, Rockville, MD

Compiler, Assembler, and Linker

UNIT-IV: MACRO PROCESSOR

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

UNIT III LOADERS AND LINKERS PART A

William Stallings Computer Organization and Architecture 8 th Edition. Chapter 11 Instruction Sets: Addressing Modes and Formats

Loaders. Systems Programming. Outline. Basic Loader Functions

Tutorial 1: Programming Model 1

Chapter 3: Loaders and Linkers

This contains the following three processes, and they are,

Systems Programming Assemblers Part 3-3 Program Blocks

2. Arithmetic Instructions addition, subtraction, multiplication, divison (HCS12 Core Users Guide, Sections 4.3.4, and ).

Monday, October 26, 2015

ASSEMBLERS. Prof. S.J. Soni, SPCE, Visnagar

Assembly Language Programming of 8085

Programming Model 2 A. Introduction

Assembly Language Programming of 8085

Wednesday, April 16, 2014

SOEN228, Winter Revision 1.2 Date: October 25,

COSC 243. Instruction Sets And Addressing Modes. Lecture 7&8 Instruction Sets and Addressing Modes. COSC 243 (Computer Architecture)

It also defines interaction between the above components. It is this low level programming model which makes programmed computations possible.

The Assembly Language Level. Chapter 7

3.3 Machine-Independent Loader Features

4.2 Machine-Independent Macro Processor Features

MC9S12 Assembler Directives A Summary of MC9S12 Instructions Disassembly of MC9S12 op codes. Summary of HCS12 addressing modes ADDRESSING MODES

STEVEN R. BAGLEY THE ASSEMBLER

JUMP, LOOP AND CALL INSTRUCTIONS

Microcontroller Systems

the SAP-2 I. Intro cmpt-150-arc Sections 8-8, 8-9, 9-4, 9-5, 9.6, We ll do this in bits and pieces, doing the beginning of each section first.

1 Little Man Computer

Wednesday, November 15, 2017

Practical Malware Analysis

Chapter 2A Instructions: Language of the Computer

SCRAM Introduction. Philipp Koehn. 19 February 2018

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

EXPERIMENT NO. 1 THE MKT 8085 MICROPROCESSOR TRAINER

Extra-credit QUIZ Pipelining -due next time-

Department of Computer and Mathematical Sciences. Lab 4: Introduction to MARIE

Overview. EE 4504 Computer Organization. Much of the computer s architecture / organization is hidden from a HLL programmer

Monday, April 15, We will lead up to the Analysis and Synthesis algorithms involved by first looking at three simpler ones.

Blog -

Machine Code and Assemblers November 6

Orange Coast College. Business Division. Computer Science Department CS 116- Computer Architecture. The Instructions

Introduction to Computer Organization. Final Exam Summer 2017

CHAPTER SEVEN PROGRAMMING THE BASIC COMPUTER

Wednesday, October 17, 2012

ORG ; TWO. Assembly Language Programming

Lecture 6: Assembly Programs

Q. P. Code : b. Draw and explain the block dig of a computer with microprocessor as CPU.

Lecture 5 Assembly Programming: Arithmetic

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Chapter 3 Loaders and Linkers -- Loader Design Options

Notes: The Marie Simulator

A Technical Overview of Commodore Copy Protection. Glenn Holmer ( ShadowM ) World of Commodore Expo, 12/01/2007

Transcription:

CS2422 Assembly Language & System Programming November 30, 2006 Today s Topic Assembler: Basic Functions Section 2.1 of Beck s System Software book. Reading Assignment: pages 43-52.

Role of Assembler Source Program Assembler Object Code Linker Executable Code Loader Line Example Program Fig. 2.1 (1/3) Source statement 5 COPY START 1000 10 FIRST STL RETADR SAVE RETURN ADDRESS 15 CLOOP JSUB RDREC READ INPUT RECORD 20 LDA LENGTH TEST FOR EOF (LENGTH = 0) 25 COMP ZERO 30 JEQ ENDFIL EXIT IF EOF FOUND 35 JSUB WRREC WRITE OUTPUT RECORD 40 J CLOOP LOOP 45 ENDFIL LDA EOF INSERT END OF FILE MARKER 50 STA BUFFER 55 LDA THREE SET LENGTH = 3 60 STA LENGTH 65 JSUB WRREC WRITE EOF 70 LDL RETADR GET RETURN ADDRESS 75 RSUB RETURN TO CALLER 80 EOF BYTE C EOF 85 THREE WORD 3 90 ZERO WORD 0 95 RETADR RESW 1 100 LENGTH RESW 1 105 BUFFER RESB 4096 4096-BYTE BUFFER AREA

110. 115. SUBROUTINE TO READ RECORD INTO BUFFER 120. 125 RDREC LDX ZERO CLEAR LOOP COUNTER 130 LDA ZERO CLEAR A TO ZERO 135 RLOOP TD INPUT TEST INPUT DEVICE 140 JEQ RLOOP LOOP UNTIL READY 145 RD INPUT READ CHARACTER INTO REGISTER A 150 COMP ZERO TEST FOR END OF RECORD (X 00 ) 155 JEQ EXIT EXIT LOOP IF EOR 160 STCH BUFFER,X STORE CHARACTER IN BUFFER 165 TIX MAXLEN LOOP UNLESS MAX LENGTH 170 JLT RLOOP HAS BEEN REACHED 175 EXIT STX LENGTH SAVE RECORD LENGTH 180 RSUB RETURN TO CALLER 185 INPUT BYTE X F1 CODE FOR INPUT DEVICE 190 MAXLEN WORD 4096 195. 200. SUBROUTINE TO WRITE RECORD FROM BUFFER 205. 210 WRREC LDX ZERO CLEAR LOOP COUNTER 215 WLOOP TD OUTPUT TEST OUTPUT DEVICE 220 JEQ WLOOP LOOP UNTIL READY 225 LDCH BUFFER,X GET CHARACTER FROM BUFFER 230 WD OUTPUT WRITE CHARACTER 235 TIX LENGTH LOOP UNTIL ALL CHARACTERS 240 JLT WLOOP HAVE BEEN WRITTEN 245 RSUB RETURN TO CALLER 250 OUTPUT BYTE X 05 CODE FOR OUTPUT DEVICE 255 END FIRST Example Program Fig. 2.1 (2/3) Purpose Reads records from input device (code F1) Copies them to output device (code 05) At the end of the file, writes EOF on the output device, then RSUB to the operating system

Example Program Fig. 2.1 (3/3) Data transfer (RD, WD) A buffer is used to store record Buffering is necessary for different I/O rates The end of each record is marked with a null character (00 16 ) The end of the file is indicated by a zero-length record Subroutines (JSUB, RSUB) RDREC, WRREC Save link register first before nested jump Assembler Directives Pseudo-Instructions Not translated into machine instructions Providing information to the assembler Basic assembler directives START END BYTE WORD RESB RESW

Functions of a Basic Assembler Mnemonic code (or instruction name)! opcode. Symbolic operands (e.g., variable names)! addresses. Choose the proper instruction format and addressing mode. Constants! Numbers. Output to object files and listing files. Example Program with Object Code Line Loc Source statement Object code 5 1000 COPY START 1000 10 1000 FIRST STL RETADR 141033 15 1003 CLOOP JSUB RDREC 482039 20 1006 LDA LENGTH 001036 25 1009 COMP ZERO 281030 30 100C JEQ ENDFIL 301015 35 100F JSUB WRREC 482061 40 1012 J CLOOP 3C1003 45 1015 ENDFIL LDA EOF 00102A 50 1018 STA BUFFER 0C1039 55 101B LDA THREE 00102D 60 101E STA LENGTH 0C1036 65 1021 JSUB WRREC 482061 70 1024 LDL RETADR 081033 75 1027 RSUB 4C0000 80 102A EOF BYTE C EOF 454F46 85 102D THREE WORD 3 000003 90 1030 ZERO WORD 0 000000 95 1033 RETADR RESW 1 100 1036 LENGTH RESW 1 105 1039 BUFFER RESB 4096

110. 115. SUBROUTINE TO READ RECORD INTO BUFFER 120. 125 2039 RDREC LDX ZERO 041030 130 203C LDA ZERO 001030 135 203F RLOOP TD INPUT E0205D 140 2042 JEQ RLOOP 30203D 145 2045 RD INPUT D8205D 150 2048 COMP ZERO 281030 155 204B JEQ EXIT 302057 160 204E STCH BUFFER,X 549039 165 2051 TIX MAXLEN 2C205E 170 2054 JLT RLOOP 38203F 175 2057 EXIT STX LENGTH 101036 180 205A RSUB 4C0000 185 205D INPUT BYTE X F1 F1 190 205E MAXLEN WORD 4096 001000 195. 200. SUBROUTINE TO WRITE RECORD FROM BUFFER 205. 210 2061 WRREC LDX ZERO 041030 215 2064 WLOOP TD OUTPUT E02079 220 2067 JEQ WLOOP 302064 225 206A LDCH BUFFER,X 509039 230 206D WD OUTPUT DC2079 235 2070 TIX LENGTH 2C1036 240 2073 JLT WLOOP 382064 245 2076 RSUB 4C0000 250 2079 OUTPUT BYTE X 05 05 255 END FIRST SIC Instruction Set (Review) Load/Store: LDA/STA, LDX/STX etc. Arithmetic: ADD, SUB, MUL, DIV Compare: COMP Jump: J Conditional Jump: JLT, JEQ, JGT See Appendix A for the complete list.

SIC Instruction Format (again) Opcode: 8 bits Address: one bit flag (x) and 15 bits of address 8 1 15 OPCODE X Address Examples Mnemonic code (or instruction name)! opcode. Examples: STL 1033! opcode 14 10 33 0001 0100 0 001 0000 0011 0011 LDA 1036! opcode 00 10 36 0000 0000 0 001 0000 0011 0110

Symbolic Operands We re not likely to write memory addresses directly in our code. Instead, we will define variable names. Other examples of symbolic operands: Labels (for jump instructions) Subroutines Constants Converting Symbols to Numbers Isn t it straightforward? Isn t it simply the sequential processing of the source program, one line at a time? Not so, if we have forward references. COPY START 1000 LDA LEN LEN RESW 1

Pass 1 Two Pass Assembler Assign addresses to all statements in the program Save the values assigned to all labels for use in Pass 2 Perform some processing of assembler directives Pass 2 Assemble instructions Generate data values defined by BYTE, WORD Perform processing of assembler directives not done in Pass 1 Write the object program and the assembly listing Two Pass Assembler Read from input line LABEL, OPCODE, OPERAND Source program Intermediate Pass 1 Pass 2 file Object codes OPTAB SYMTAB SYMTAB

Two Pass Assembler Pass 1 Two Pass Assembler Pass 2

Data Structures Operation Code Table (OPTAB) Symbol Table (SYMTAB) Location Counter(LOCCTR) OPTAB (operation code table) Content Mnemonic, machine code (instruction format, length) etc. Characteristic Static table Implementation Array or hash table, easy for search

SYMTAB (symbol table) Content Label name, value, flag, (type, length) etc. Characteristic Dynamic table (insert, delete, search) Implementation Hash table, non-random keys, hashing function COPY 1000 FIRST 1000 CLOOP 1003 ENDFIL 1015 EOF 1024 THREE 102D ZERO 1030 RETADR 1033 LENGTH 1036 BUFFER 1039 RDREC 2039 One-Pass Assemblers Forward references can be resolved in One- Pass Assemblers too! Add a linked list to the Symbol Table to keep track of unresolved references. (See p.95) We will discuss 1-pass assembler again in the future (Section 2.4.1)

Header Object Program Col. 1 H Col. 2~7 Program name Col. 8~13 Starting address (hex) Col. 14-19 Length of object program in bytes (hex) Text Col.1 T Col.2~7 Starting address in this record (hex) Col. 8~9 Length of object code in this record in bytes (hex) Col. 10~69 Object code (69-10+1)/6=10 instructions End Col.1 Col.2~7 E Address of first executable instruction (hex) (END program_name) Fig. 2.3 H COPY 001000 00107A T 001000 1E 141033 482039 001036 281030 301015 482061... T 00101E 15 0C1036 482061 081044 4C0000 454F46 000003 000000 T 002039 1E 041030 001030 E0205D 30203F D8205D 281030 T 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064 T 002073 07 382064 4C0000 05 E 001000 "starting address