Introduction to Computing Systems from bits & gates to C & beyond Chapter 7 LC-2 Assembly Language.

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

Chapter 5 The LC-3.
Chapter 7 Introduction to LC-3 Assembly Language Assembly Language Assembly Process Using the Editor & Simulator for Assembly Language Programming.
Introduction to Computer Engineering ECE 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin –
PART 6 Programming 1.Decomposition 2.Three Constructs 3.Counting Example 4.Debugging.
Chapter 9 TRAP Routines and Subroutines. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 Subroutines.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 7 LC-2 Assembly Language.
Chapter 7 Assembly Language. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 7-2 Human-Readable Machine Language.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
Chapter 7 Assembly Language. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 7-2 Human-Readable Machine Language.
Introduction to LC-3 Assembly Language. LC-3 Assembly Language Syntax Each line of a program is one of the following: –an instruction –an assember directive.
Choice for the rest of the semester New Plan –assembler and machine language –Operating systems Process scheduling Memory management File system Optimization.
Chapter 4 H1 Assembly Language: Part 2. Direct instruction Contains the absolute address of the memory location it accesses. ld instruction:
Introduction to LC-3 Assembly Language
Overview Projects The Assembly Process Programmed I/O Interrupt Driven I/O.
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
Chapter 5 The LC-3. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 5-2 Instruction Set Architecture ISA.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 8 Input/Output Basic organization Keyboard input Monitor output Interrupts DMA.
Chapter 7 LC-3 Assembly Language. 2 College of Charleston, School of Science and Mathematics Dr. Anderson, Computer Science CS 250 Comp. Org. & Assembly.
Assembly Language.
Introduction to Computing Systems and Programming Assembly Language.
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
Introduction to Computing Systems from bits & gates to C & beyond Chapter 5 The LC-2 Instruction Set Architecture Operate instructions Data Movement instructions.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 4 The Von Neumann Model Basic components Instruction processing.
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
Introduction to Computing Systems from bits & gates to C & beyond Chapter 5 The LC-3 Instruction Set Architecture ISA Overview Operate instructions Data.
Chapter 5 The LC-3. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 5-2 Data Movement Instructions Load --
Computer Science 210 Computer Organization Overview of Assembly Language.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 10 The Stack Stack data structure Activation records and function invocation.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
The LC-3. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 5-2 Instruction Set Architecture ISA = All of the.
Computer Science 210 Computer Organization More on Assembler.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 4 The Von Neumann Model Basic components Instruction processing.
Chapter 7 Assembly Language. 7-2 Human-Readable Machine Language Computers like ones and zeros… Humans like symbols… Assembler is a program that turns.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 10 The Stack Stack data structure Interrupt I/O (again!) Arithmetic using a stack.
Computer Science 210 Computer Organization
Introduction to Computer Engineering
PROGRAMMING THE BASIC COMPUTER
Computer Science 210 Computer Organization
Chapter 7 Assembly Language
Chapter 7 & 9.2 Assembly Language
Computer Science 210 Computer Organization
Assembly Language Ms. V.Anitha AP/CSE SCT
PROGRAMMING THE BASIC COMPUTER
Chapter 7 Assembly Language
Chapter 5 The LC-3.
Computer Science 210 Computer Organization
Chapter 7 LC-2 Assembly Language.
Assembler CASE Tool.
Introduction to Computer Engineering
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Chapter 7 Assembly Language
Chapter 9 TRAP Routines and Subroutines
Chapter 7 LC-2 Assembly Language.
COSC121: Computer Systems
Introduction to Computer Engineering
Chapter 7 Assembly Language
Chapter 9 TRAP Routines and Subroutines
Chapter 7 Assembly Language
TRAP Routines Privileged Instructions Subroutines
Introduction to Computer Engineering
Chapter 7 Assembly Language An Hong 2016 Fall
Introduction to Computer Engineering
Introduction to Computer Engineering
Introduction to Computer Engineering
Introduction to Computer Engineering
Chapter 7 Assembly Language
Presentation transcript:

Introduction to Computing Systems from bits & gates to C & beyond Chapter 7 LC-2 Assembly Language

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside It’s hard to write code in 1’s & 0’s! Assembly language makes it possible to write Machine Language code  each line of assembly language is translated into a single ML instruction A program called the Assembler does the translation and provides useful tools:  use of labels - symbolic names for address locations  automatic conversion of binary / hex / decimal  pseudo-ops

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside A sample program 01; 02; Program to multiply an integer by the number 6 03; 04.ORIGx LDR1, SIX 06 LDR2, NUMBER 07 ANDR3, R3, #0 ; clear R3 to hold the product 08; 09; The inner loop 0A; 0BAGAIN ADDR3, R3, R2 0C ADDR1, R1, #-1 ; keep track of iterations 0D BRpAGAIN 0E; 0F HALT 10; 11NUMBER.BLKW1 12SIX.FILLx ; 14.END

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside Assembly Language Instructions Formats  LABEL OPCODEOPERANDS; COMMENTS  LABEL PSEUDO-OPS; COMMENTS Opcode  Symbolic name for the 4-bit ML opcode Label  Symbolic name for a memory location. It is used to:  indicate the target of a branch instruction, e.g. AGAIN in location 0B  indicate the location of a stored value or array, e.g. NUMBER and SIX Comments  intended for humans only: explanation of code, visual display

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside Pseudo-Ops …  … are directives to the assembler  they are not translated into ML instructions  LC-3 Pseudo-Ops: . ORIG address Tells assembler where to locate the program in memory (starting address). .FILL value Store value in the next location in memory. .BLKW n Set aside a block of n words in memory. .STRINGZ stringStore the string, one character per word, in memory. Add a word of x0000 after the string. .ENDMarks the end of the source program (not to be confused with the instruction HALT!) .EXTERNALThe label so indicated is allocated in another module.

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside A partial assembly sample.ORIG x3000 AND R1, R1, #0 ADD R1, R1, #10 LD R2, Twenty LD R3, Ess HALT TwentyFILLx0014.BLKW2 Ess.FILL“S”.STRINGZ “Hi”.BLKW 3.END x3000:AND R1, R1, b x3001:ADD R1, R1, b x3002:LD R2, b x3003:LD R3, b x3004:TRAP b x3005: b ; x0014 x3006: x3007: x3008:b ; x0053 x3009:b ; x0048 = ‘H’ x300A:b ; x0069 = ‘i’ x300B:x0000 ; null terminator x300C: x300D: x300E:

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside The Assembly Process Objective  Translate the AL (Assembly Language) program into ML (Machine Language).  Each AL instruction yields one ML instruction word.  Interpret pseudo-ops correctly. Problem  An instruction may reference a label.  If the label hasn’t been encountered yet, the assembler can't form the instruction word Solution  Two-pass assembly

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside Two-Pass Assembly - 1 First Pass - generating the symbol table  Scan each line  Keep track of current address  Increment by 1 for each instruction  Adjust as required for any pseudo-ops (e.g..FILL or.STRINGZ, etc.)  For each label  Enter it into the symbol table  Allocate to it the current address  Stop when.END is encountered

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside Symbol Table example  Using the earlier example: ; ; Program to multiply a number by six ;.ORIGx3050 x3050LDR1, SIX x3051LDR2, NUMBER x3052ANDR3, R3, #0 ; ; The inner loop ; x3053AGAINADDR3, R3, R2 x3054ADDR1, R1, #-1 x3055BRpAGAIN ; x3056HALT ; x3057NUMBER.BLKW1 x3058SIX.FILLx0006 ;.END

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside Another example - Parity checking Parity is a function that returns a 1 when the number of 1s in a word is odd and 0 when it is even..ORIGx AND R2, R2, x0 ; clear R2 3001LDI R1, Input ; load word into R1 3002CountBRz Report ; if 0, done counting 3003BRp Shift ; if >0, skip ADD 3004ADD R2, R2, x1 ; increment count 3005ShiftADD R1, R1, R1 ; shift left 1 bit 3006BRnzp Count ; go back up 3007ReportAND R3, R2, x1 ; LSB 1 or 0? 3008STI R3, Output ; store results 3009TRAP x25 ; halt program 300AInput.FILL x3200 ; address of input 300BOutput.FILL x3201 ; address of output

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside Two-Pass Assembly - 2 Second Pass - generating the ML program  Scan each line again  Translate each AL instruction into ML  Look up symbols in the symbol table instruction  Ensure that labels are no more than +256 / -255 lines from instruction  Determine operand field for the instruction  Fill memory locations as directed by pseudo-ops  Stop when.END is encountered

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside Assembled code  Using the earlier example: x ; LD R1, SIX x ; LD R2, NUMBER x ; AND R3, R3, #0 x ; ADD R3, R3, R2 x ; ADD R1, R1, #-1 x ; BRp AGAIN x ; HALT x3057 ;.BLKW 1 x ;.FILL x0006

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside Object File Each source file is translated into an object file  a list of ML instructions including the symbol table. A complete program may include several source and/or object files:  Source files written in Assembly by the programmer  Library files provided by the system (OS or other)  Compiled HLL libraries The object files must be linked  One object file will be the “main”  All cross-referenced labels in symbol tables will be resolved

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slides prepared by Walid A. Najjar & Brian J. Linard, University of California, Riverside The end result … … is the executable image (.exe file)  this is a file (“image”) of the finalized list of ML instructions, with all symbolic references resolved  it is loaded by copying the list into memory, starting at the address specified in the.ORIG directive  it is run by copying the starting address to the PC