Computer Science 101 A Survey of Computer Science

Computer Science 210 Computer Organization More on Assembler Human-Readable Machine Language Computers work with 1s and 0s: 0001001001100001 People work with symbols: ADD R1, R1, #1 ; Increment R1

The assembler makes this happen! Example: diff = first - second ;; Author: Ken Lambert ;; This program subtracts the number in the variable SECOND from FIRST ;; and stores the result in DIFF ;; Pseudocode design: ; diff = first - second .ORIG x3000 ;; Register usage: ; R0 = first ; R1 = second ; R2 = diff ; Program code

LD R0, FIRST LD R1, SECOND NOT R1, R1 ADD R1, R1, #1 ADD R2, R0, R1 ST R2, DIFF HALT ; Data variables FIRST .BLKW 1 SECOND .BLKW 1 DIFF .BLKW 1

.END The Assembly Process Convert the program in the source (.asm) file to an executable file (.obj) for the LC3 simulator First pass: Scan program file Find all labels and calculate their addresses, creating a symbol table Second pass: Convert instructions to machine language, using the symbol table First Pass: Construct the Symbol Table

1. Find the .ORIG statement, which tells us the address of the first instruction. Initialize location counter (LC), which keeps track of the current instruction. 2. For each non-empty line in the program: a) If line begins with label, add label and LC to symbol table. b) Increment LC. NOTE: If statement is .BLKW or .STRINGZ, increment LC by the number of words allocated. 3. Stop when .END statement is reached. NOTE: A line that contains only a comment is considered an empty line. Example Symbol Table

Code in subtract.asm Table in subtract.sym LD R0, FIRST LD R1, SECOND NOT R1, R1 ADD R1, R1, #1 // Symbol table // Scope level 0: // Symbol Name // ---------------// FIRST // SECOND

// DIFF ADD R2, R0, R1 ST R2, DIFF HALT FIRST .BLKW 1 SECOND .BLKW 1 DIFF .BLKW 1 Page Address -----------3007 3008

3009 Second Pass: Generate Machine Code For each executable assembly language statement, generate the corresponding machine language instruction If operand is a label, look up the address from the symbol table Potential errors to detect and flag: Improper number or type of arguments ex: NOT R1,#7 ADD ADD R1,R2

R3,R3,NUMBER Immediate argument too large ex: ADD R1,R2,#1023 Address (associated with label) more than 256 from instruction; cant use PC-relative addressing mode Object File Format An LC-3 object file contains Starting address (location where program must be loaded), followed by Machine language instructions Multiple Object Files

An object file is not necessarily a complete program. system-provided library routines code blocks written by multiple developers For LC-3 simulator, we can load multiple object files into memory, then start executing at a desired address. system routines, such as keyboard input, are loaded automatically loaded into system memory, below x3000 user code should be loaded between x3000 and xFDFF each object file includes a starting address be careful not to load overlapping object files In LC3, first file contains the program Remaining files contain data (run lc3convert b16 or b2) The Loader

Loading is the process of copying an executable image into memory more sophisticated loaders are able to relocate images to fit into available memory must readjust branch targets, load/store addresses The Linker Linking is the process of resolving symbols between independent object files suppose we define a symbol in one module, and want to use it in another some notation, such as .EXTERNAL, is used to tell assembler that a symbol is defined in another module linker will search symbol tables of other modules to resolve

symbols and complete code generation before loading For Friday Input and Output Operations Chapter 8

Recently Viewed Presentations

  • Visualizing the Protein Sequence Universe ECMLS 2012 18 June 2012

    Visualizing the Protein Sequence Universe ECMLS 2012 18 June 2012

    Proximity measure: sequence alignment % scores Scores calculated using Needleman-Wunsch Scores "sqrt 4D" transformed and fed into MDS Analytic form for transformation to 4D ijn decreases dimension n > 1; increases n < 1 "sqrt 4D" reduced dimension of distance...
  • Economic Benefits of Rare and Endangered Species

    Economic Benefits of Rare and Endangered Species

    Economic Benefits of Rare and Endangered Species Loomis, J.B., White, D.S. "Economic Benefits of Rare and Endangered Species: Summary and Meta-Analysis." Ecological Economics 18(1996): 197-206. Lauren Goschke Questions #1- What kinds of economic costs and benefits are provided by Threatened...
  • Rotkppchen oder Goldlckchen 1) Es gibt ein Wolf.

    Rotkppchen oder Goldlckchen 1) Es gibt ein Wolf.

    ER/SIE. Grimmsmärchen. Freitag, den 26sten April. I will revise the verbs HABEN and SEIN. Rotkäppchen. Sie hat grüneAugen. Sie hat kurze, rote Haare. Sie hat kleineOhren. Sie hat kleine, blaueAugen. Sie hat lockige, weißeHaare. Er hat gelbeAugen. Er hat graueHaare.
  • Basic DC Generator - Faculty Pages

    Basic DC Generator - Faculty Pages

    Arial Symbol Default Design MathType 5.0 Equation Elementary Two-Pole Motor Elementary Two-Pole Generator Voltage induced in the coil, e Directions of induced voltage and current Basic DC Generator Slide 6 Generator Action From a Circuit Point-of-View Motor Action From a...
  • Louisiana Cancer Facts & Figures, All Cancer Sites

    Louisiana Cancer Facts & Figures, All Cancer Sites

    All Cancer Sites. Between 2010 and 2014, the average annual incidence rate#of all cancer sites in Louisiana was the 5th highest and the mortality rate was the 4th highest in the U.S.1
  • DISCOVER STUDY for HIV Pre-Exposure Prophylaxis (PrEP): F/TAF ...

    DISCOVER STUDY for HIV Pre-Exposure Prophylaxis (PrEP): F/TAF ...

    Honoraria for speakers bureau and/or advisory boards from Gilead, AbbVie, Janssen, MSD, Teva/Hexal, and ViiV Healthcare
  • Fast facts: dm and people with pet insurance

    Fast facts: dm and people with pet insurance

    April 2011 Author: John Bliss, media insight manager, MMC Source: Ebiquity, Royal Mail, Nielsen The Charity Sector in 2010 Marketing to the Travel Sector The Finance Sector in 2010 The Mail Order Sector in 2010 The Retail Sector in 2010...
  • Unilateral Change Bargaining The Federal Service LaborManagement Relations

    Unilateral Change Bargaining The Federal Service LaborManagement Relations

    Educ. Ass'n, 22 FLRA 235 (1986). What is a change? A change may be a management-initiated change in policy or a change in a past practice. ... Advanced Statutory Training Collective Bargaining. LIMITS ON FERERAL SECTOR BARGAINING Proposals that are...