Assemblers - 2 CSCI/CMPE 3334 David Egle.

Slides:



Advertisements
Similar presentations
Machine Independent Assembler Features
Advertisements

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.
The Simplified Instructional Computer (SIC/SICXE)
1: Background1 System Programming ( 系統程式 ) Main goal: r What is a system software? m Compiler m Assembler m Loader and Linker m Debugger… r To design and.
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.
1 The Simplified Instructional Computer (SIC) Hsiang-Fu Yu National Taipei University of Education.
System Software.
Chapter 6: Machine dependent Assembler Features
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.
Operating System Support Focus on Architecture
Chapter 2 Assemblers Assembler Linker Source Program Object Code
Assembler – Machine Dependent Features
CS2422 Assembly Language and System Programming Machine Dependent Assembler Features Department of Computer Science National Tsing Hua University.
Computer Organization and Architecture
CS2422 Assembly Language & System Programming December 7, 2006.
Machine Dependent Assembler Features
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)
CS364 CH08 Operating System Support TECH Computer Science Operating System Overview Scheduling Memory Management Pentium II and PowerPC Memory Management.
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
UNIT II ASSEMBLERS.
Review of Memory Management, Virtual Memory CS448.
A Simple Two-Pass Assembler
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
Assemblers.
Memory Management – Page 1 of 49CSCI 4717 – Computer Architecture Memory Management Uni-program – memory split into two parts –One for Operating System.
CS2422 Assembly Language and System Programming Machine Independent Assembler Features 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.
Machine Independent Assembler Features
G.Umamaheswari Lect/IT R.M.D.EC system software
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
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
Machine dependent Assembler Features
CC410: System Programming
Machine Independent Assembler Features
System Programming and administration
System Programming and administration
William Stallings Computer Organization and Architecture
System Software by Leland L. Beck Chapter 2
SYSTEM SOFTWARE - UNIT II
Machine Independent Assembler Features
THE sic mACHINE CSCI/CMPE 3334 David Egle.
Optional Assembler Features
Machine Independent Features
Simplified Instructional Computer (SIC)
Operating Systems.
Computer Architecture and the Fetch-Execute Cycle
Chapter 1 Background Professor Gwan-Hwan Hwang
Simplified Instructional Computer (SIC)
A Simple Two-Pass Assembler
Optional Assembler Features 2
System Programming by Leland L. Beck Chapter 2
Assemblers CSCI/CMPE 3334 David Egle.
Welcome to Systems Software
Machine Independent Assembler Features
Machine Independent Assembler Features
COMP755 Advanced Operating Systems
Lecture 1: SIC Architecture
Presentation transcript:

Assemblers - 2 CSCI/CMPE 3334 David Egle

Machine Dependent Features The algorithm presented in the previous lecture was based on the SIC machine What changes would be needed for other architectures – i.e., the SIC/XE New instruction formats Additional instructions Additional addressing modes Additional registers

SIC/XE Assembler Changes must be made to format of source code How do we indicate indirect addressing immediate addressing extended format (4 byte) mode How do we set up for base addressing Need to recognize when registers are used Need to determine whether PC relative addressing or base relative addressing are required

SIC/XE Assembler Changes also made to machine code handling Which format should be used How are registers numbered How are displacements calculated Which bits are set in formats 3 & 4 Truncation of opcode value

Programmer changes The programmer must revise their coding to take advantage of the new features Use registers whenever possible Be aware of the limitations of PC and base relative addressing Use immediate and indirect addressing when possible Don’t specify specific address in START – use START 0 With the increased memory, more than one program may be in memory at the same time – let the assembler and loader handle the details

SIC/XE sample program (1/3) COPY START 0 COPY FILE FROM INPUT TO OUTPUT FIRST STL RETADR SAVE RETURN ADDRES LDB #LENGTH ESTABLISH BASE REGISTER BASE LENGTH CLOOP +JSUB RDREC READ INPUT RECORD LDA LENGTH TEST FOR EOF (LENGTH = 0) COMP #0 JEQ ENDFIL EXIT IF EOF FOUND +JSUB WRREC WRITE OUTPUT RECORD J CLOOP LOOP ENDFIL LDA EOF INSERT END OF FILE MARKER STA BUFFER LDA #3 SET LENGTH = 3 STA LENGTH +JSUB WRREC WRITE EOF J @RETADR RETURN TO CALLER EOF BYTE C'EOF' RETADR RESW 1 LENGTH RESW 1 LENGTH OF RECORD BUFFER RESB 4096 4096-BYTE BUFFER AREA

SIC/XE sample program (2/3) . . SUBROUTINE TO READ RECORD INTO BUFFER RDREC CLEAR X CLEAR LOOP COUNTER CLEAR A CLEAR A TO ZERO CLEAR S CLEAR S TO ZERO +LDT #4096 RLOOP TD INPUT TEST INPUT DEVICE JEQ RLOOP LOOP UNTIL READY RD INPUT READ CHARACTER INTO REGISTAR A COMPR A,S TEST FOR END OF RECORD (X'00') JEQ EXIT EXIT LOOP IF EOF STCH BUFFER,X STORE CHARCTER IN BUFFER TIXR T LOOP UNLESS MAX LENGTH JLT RLOOP HAS BEEN REACHED EXIT STX LENGTH SAVE RECORD LENGTH RSUB RETURN TO CALLER INPUT BYTE X'F1' CODE FOR INPUT DEVICE

SIC/XE sample program (3/3) . . SUBROUTINE TO WRITE RECORD FROM BUFFER WRREC CLEAR X CLEAR LOOP COUNTER LDT LENGTH WLOOP TD OUTPUT TEST OUTPUT DEVICE JEQ WLOOP LOOP UNTIL READY LDCH BUFFER,X GET CHARCTER FROM BUFFER WD OUTPUT WRITE CHARACTER TIXR T LOOP UNTIL ALL CHARACTERS JLT WLOOP HAVE BEEN WRITTEN RSUB RETURN TO CALLER OUTPUT BYTE X'05' CODE FOR OUTPUT DEVICE END FIRST

Changes to tables Opcode table MUST include instruction format type Symbol table should include register names and values We may need further additions

Displacement calculation If extended mode is not specified, assume PC relative addressing as default If displacement out of range, try base relative addressing If that fails, generate an error message

Displacement calculation For either mode of displacement, the general form is target address = (reg) + displacement where reg is either PC or B So, to get the displacement, the assembler must calculate displacement = target address – (reg) BUT, how can the assembler know the value of PC or B???

PC relative addressing The assembler does not know the value of any register It must use the location counter (LOCCTR) and the knowledge of the instruction cycle: fetch instruction from location pointed to by PC update PC decode instruction execute instruction So, when an instruction is executed, the PC contains the address of the next instruction

PC relative addressing So, to compute the displacement using PC relative addressing, the assembler must compute displacement = address of target – (LOCCTR + size of instruction being executed) for the XE, the size is 3 Note that this displacement is a 12 bit signed integer range is -2048 to 2047

Base relative addressing This is a bit easier, BUT requires assistance from the programmer B register is under control of the programmer must be loaded with the correct value To let the assembler know the contents of B, a new directive is used BASE symbol There is also a directive NOBASE which tells the assembler that the content of the B register cannot be relied on for addressing NOTE: Assembler directives DO NOT produce executable code

Base relative addressing So, to compute the displacement using base relative addressing, the assembler must compute displacement = address of target – (address of symbol specified by BASE) Note that this displacement is a 12 bit unsigned integer range is 0 to 4095

Immediate operands Convert operand to its internal representation Operand may be a value, or a symbol If it does not fit in 12 bits, and extended format was not specified – Error if it does not fit in 20 bits, - Error another addressing form must be used Set the appropriate bits in the instruction

Indirect addressing Not much to do here other than to set the appropriate bits and hope the programmer knows what they are doing

Relocation SIC requires an absolute loader The program must be loaded in the specified address to execute properly If loaded in a different location, the address portions of the instructions need to change This would affect almost every instruction It is not practical to plan execution at a specific address A program should be loaded wherever there is room

Relocation The assembler cannot make the address changes itself It has no idea where the program will be loaded The assembler must tell the loader which parts of the program will require modification Produces a relocatable object file Note that there is no need to adjust operands when it is immediate or register PC or base relative addressing is used In these cases, there is no address to fix

Relocation To handle relocation start the location counter at 0 (START 0) generate object code where direct addresses are calculated relative to the load address (0) Note that these will only be found in format 4 instructions on the XE, but in most instructions on the SIC add information in the object file telling the loader which address fields require adjustment

Object file format Need a new type of record Modification record Maddress (note that this is different from the text) NOTE: This is not how modern computers handle this situation. But we will need this modification record later.

Paging (from Stallings) Split memory into equal sized, small chunks -page frames Split programs (processes) into equal sized small chunks - pages Allocate the required number page frames to a process Operating System maintains list of free frames A process does not require contiguous page frames Use page table to keep track

Allocation of Free Frames

Logical and Physical Addresses - Paging

Virtual Memory Demand paging Page fault Do not require all pages of a process in memory Bring in pages as required Page fault Required page is not in memory Operating System must swap in required page May need to swap out a page to make space Select page to throw out based on recent history

Thrashing Too many processes in too little memory Operating System spends all its time swapping Little or no real work is done Disk light is on all the time Solutions Good page replacement algorithms Reduce number of processes running Fit more memory

Bonus We do not need all of a process in memory for it to run We can swap in pages as required So - we can now run processes that are bigger than total memory available! Main memory is called real memory User/programmer sees much bigger memory - virtual memory