CS2422 Assembly Language & System Programming November 30, 2006.

Slides:



Advertisements
Similar presentations
寫入 輸出紀錄(output record) 40 J 跳回CLOOP 45 LDA EOF 插入 檔案終結符號 50 STA BUFFER
Advertisements

Loader. Role of Loader Source Program Translator Object Program Loader Object program ready for execution Memory Translator – Assembler/Compiler.
Machine Independent Assembler Features
The assembler is the system program that translate source code written in assembly language to object code( Machine Language) and other information for.
CS2422 Assembly Language and System Programming Loader Department of Computer Science National Tsing Hua University.
Welcome to Systems Software The purpose of this course is to provide background in fundamental types of system software, particularly assemblers, loaders,
1 System Programming System Software, pp Chia-Hui Chang, Assistant Professor Dept. of Computer Science & Information Engineering National Central.
Simplified Instructional Computer (SIC). SIC Architecture Two versions: SIC and SIC/XE (extra equipments). SIC program can be executed on SIC/XE. Memory.
Machine-Dependent Assembler Features (SIC/XE Assembler) Instruction Formats, Addressing Modes, and Program Relocation.
System Software by Leland L. Beck chapter 1, pp.1-20.
1 Chapter 1 Background Professor Gwan-Hwan Hwang Dept. Computer Science and Information Engineering National Taiwan Normal University 9/17/2009.
System Software.
Assembler design.
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler I.
CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.
Chih-Hung Wang Chapter 2: Assembler (Full) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley,
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
System Software by Leland L. Beck Chapter 2
Chapter 2 Assemblers Assembler Linker Source Program Object Code
CS2422 Assembly Language & System Programming December 22, 2005.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
Assembler – Machine Dependent Features
1 Chapter 2 Assemblers Source Program Assembler Object Code Loader.
An introduction to systems programming
CS2422 Assembly Language and System Programming Machine Dependent Assembler Features Department of Computer Science National Tsing Hua University.
CS2422 Assembly Language & System Programming December 7, 2006.
Chih-Hung Wang Chapter 1: Background (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
CS2422 Assembly Language & System Programming December 26, 2006.
Assembler (Basic Functions)
UNIT II ASSEMBLERS.
Today’s Topic Assembler: Basic Functions
A Simple Two-Pass Assembler
Chapter 4 System Programming and Operating Systems -DM Dhamdhere
What is System Software? -a program that manages and supports the computer resources - manages operations of a computer system while it executes various.
Assemblers.
Chapter 1 Computer architecture Languages: machine, assembly, high
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler II.
CS2422 Assembly Language and System Programming Machine Independent Assembler Features Department of Computer Science National Tsing Hua University.
1 Assemblers System Software by Leland L. Beck Chapter 2.
Assemblers System Software by Leland L. Beck Chapter 2.
CS2422 Assembly Language and System Programming Assembler Design Options Department of Computer Science National Tsing Hua University.
1 Assemblers System Programming by Leland L. Beck Chapter 2.
Machine-Independent Assembler Features Literals, Symbol-Defining Statements, Expressions, Program Blocks, Control Sections and Program Linking.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
1 Assemblers System Software by Leland L. Beck Chapter 2.
Assemblers System Software by Leland L. Beck Chapter 2.
Assemblers System Software.
COMPILERS CLASS IV Er. Vikram Dhiman M.tech NIT jalandhar.
CPS4200 System Programming Spring 1 Systems Programming Chapter 1 Background I.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 4 - Assembler 1.
ADHIPARASAKTHI ENGINEERING COLLEGE
김길용 교수 분산처리연구실 시스템 프로그래밍 김길용 교수 분산처리연구실
CC410: System Programming
CC410: System Programming
System Programming and administration
System Software by Leland L. Beck Chapter 2
SYSTEM SOFTWARE - UNIT II
Assembler Design Options
Assemblers - 2 CSCI/CMPE 3334 David Egle.
Simplified Instructional Computer (SIC)
Chapter 1 Background Professor Gwan-Hwan Hwang
A Simple Two-Pass Assembler
System Programming by Leland L. Beck Chapter 2
Assemblers CSCI/CMPE 3334 David Egle.
Welcome to Systems Software
Machine Independent Assembler Features
Chapter 6 Programming the basic computer
Machine Independent Assembler Features
An introduction to systems programming
Lecture 1: SIC Architecture
Presentation transcript:

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

Role of Assembler Source Program Assembler Object Code Loader Executable Code Linker

Example Program Fig. 2.1 (1/3) LineSource statement 5COPYSTART FIRSTSTLRETADRSAVE RETURN ADDRESS 15CLOOPJSUBRDRECREAD INPUT RECORD 20LDALENGTHTEST FOR EOF (LENGTH = 0) 25COMPZERO 30JEQENDFILEXIT IF EOF FOUND 35JSUBWRRECWRITE OUTPUT RECORD 40JCLOOPLOOP 45ENDFILLDAEOFINSERT END OF FILE MARKER 50STABUFFER 55LDATHREESET LENGTH = 3 60STALENGTH 65JSUBWRRECWRITE EOF 70LDLRETADRGET RETURN ADDRESS 75RSUBRETURN TO CALLER 80EOFBYTEC’EOF’ 85THREEWORD3 90ZEROWORD0 95RETADRRESW1 100LENGTHRESW1 105BUFFERRESB BYTE BUFFER AREA

SUBROUTINE TO READ RECORD INTO BUFFER RDRECLDXZEROCLEAR LOOP COUNTER 130LDAZEROCLEAR A TO ZERO 135RLOOPTDINPUTTEST INPUT DEVICE 140JEQRLOOPLOOP UNTIL READY 145RDINPUT READ CHARACTER INTO REGISTER A 150COMPZEROTEST FOR END OF RECORD (X’00’) 155JEQEXITEXIT LOOP IF EOR 160STCHBUFFER,XSTORE CHARACTER IN BUFFER 165TIXMAXLENLOOP UNLESS MAX LENGTH 170JLTRLOOP HAS BEEN REACHED 175EXITSTXLENGTHSAVE RECORD LENGTH 180RSUBRETURN TO CALLER 185INPUTBYTEX’F1’CODE FOR INPUT DEVICE 190MAXLENWORD SUBROUTINE TO WRITE RECORD FROM BUFFER WRRECLDXZEROCLEAR LOOP COUNTER 215WLOOPTDOUTPUTTEST OUTPUT DEVICE 220JEQWLOOPLOOP UNTIL READY 225LDCHBUFFER,XGET CHARACTER FROM BUFFER 230WDOUTPUTWRITE CHARACTER 235TIXLENGTHLOOP UNTIL ALL CHARACTERS 240JLTWLOOP HAVE BEEN WRITTEN 245RSUBRETURN TO CALLER 250OUTPUTBYTEX’05’CODE FOR OUTPUT DEVICE 255ENDFIRST

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 LineLoc Source statementObject code 51000COPYSTART FIRSTSTLRETADR CLOOPJSUBRDREC LDALENGTH COMPZERO CJEQENDFIL FJSUBWRREC JCLOOP3C ENDFILLDAEOF00102A STABUFFER0C BLDATHREE00102D 60101ESTALENGTH0C JSUBWRREC LDLRETADR RSUB4C AEOFBYTEC’EOF’454F DTHREEWORD ZEROWORD RETADRRESW LENGTHRESW BUFFERRESB4096

SUBROUTINE TO READ RECORD INTO BUFFER RDRECLDXZERO CLDAZERO FRLOOPTDINPUTE0205D JEQRLOOP30203D RDINPUT D8205D COMPZERO BJEQEXIT ESTCHBUFFER,X TIXMAXLEN2C205E JLTRLOOP38203F EXITSTXLENGTH ARSUB4C DINPUTBYTEX’F1’F EMAXLENWORD SUBROUTINE TO WRITE RECORD FROM BUFFER WRRECLDXZERO WLOOPTDOUTPUTE JEQWLOOP ALDCHBUFFER,X DWDOUTPUTDC TIXLENGTH2C JLTWLOOP RSUB4C OUTPUTBYTEX’05’05 255ENDFIRST

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 OPCODEXAddress 8115

Examples Mnemonic code (or instruction name)  opcode. Examples: STL 1033  opcode LDA 1036  opcode

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. COPYSTART 1000 … LDALEN … LENRESW1

Two Pass Assembler Pass 1 –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 Pass 1Pass 2 Intermediate file Object codes Source program OPTAB 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 COPY1000 FIRST 1000 CLOOP1003 ENDFIL1015 EOF1024 THREE102D ZERO1030 RETADR1033 LENGTH1036 BUFFER1039 RDREC2039

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)

Object Program Header Col. 1 H Col. 2~7 Program name Col. 8~13 Starting address (hex) Col 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 ( )/6=10 instructions End Col.1 E Col.2~7 Address of first executable instruction (hex) (END program_name)

Fig. 2.3 H COPY A T E T 00101E 15 0C C F T E E0205D 30203F D8205D … T C C0000 F E … T C E  starting address