
COSC2200: Hardware Systems Introduction to Assembly Language and MIPS ISA Instructor: Rong Ge Extracted from various online sources 1 Outline • Why do we learn assembly programing? • Format of assembly programs • MIPS Instruction Set Architecture 2 Programming on Early Computers • Wire the computer circuits to solve the desired problem – No program instructions, no memory • Load instructions manually, one at a time, to stored-program computer – Machine instructions • Programming needed to be easier • The first programming support programs were assembers 3 Assemblers • Assemblers allow the programmers to use simple names for instructions in writing a program – “Add”, for example – The program is constructed using instruction acronyms. – The assembler converted the English test names to the combinations of 1’s and 0’s that represented instructions. – Automatic program loading was developed with tapes and disks • Today, most time we program in high level language because – Compilers arrived 4 A Translation Hierarchy C, Fortran, and some other HLL • High Level Language (HLL) Compiler programs first compiled (possibly into assembly), Assembly language program then linked and finally loaded into main memory. Assembler Object: Machine language module Object: Library routine (machine language) Linker Executable: Machine language program Loader Memory 5 Why Learn Assembly Language • Compilers reduce the “feel” of the software-hardware interaction. – HLL code uses keywords, libraries, – Remove the lower-level visibility of computer and program operation • Assembly language programming gives the “feel” of computer operation – Assembly language is machine specific and “low level” – The program and syntax is much closer to the computer’s processor, memory, and I/O system • Learning assembly language also helps in understanding much of the basics of computer design • Some programs still need assembly language for – Direct hardware manipulation – Access to specialized processor instruction, or performance 6 Assembly Program Template # Title: Filename: # Author: Date: # Description: # Input: # Output: ################# Data segment ##################### .data . ################# Code segment ##################### .text .globl main main: # main program entry . li v0, 10 # load an immediate # Exit program Assembly Language Statements • One statement should appear on a line • Three types of statement: Executable Instructions – Generate machine code for the processor to execute at runtime – Instructions tell the processor what to do Pseudo-Instructions and Macros – Translated by the assembler into real instructions – Simplify the programmer task Assembler Directives – Provide information to the assembler while translating a program – Used to define segments, allocate memory variables, etc. – Non-executable: directives are not part of the instruction set .DATA, .TEXT, & .GLOBL Directives • .DATA directive – Defines the data segment of a program containing data – The program's variables should be defined under this directive – Assembler will allocate and initialize the storage of variables • .TEXT directive – Defines the code segment of a program containing instructions • .GLOBL directive – Declares a symbol as global – Global symbols can be referenced from other files – We use this directive to declare main procedure of a program Instructions • Assembly language instructions have the format: [label:] mnemonic [operands] [#comment] • Label: (optional) – Marks the address of a memory location, must have a colon – Typically appear in data and text segments • Mnemonic – Identifies the operation (e.g. add, sub, etc.) • Operands – Specify the data required by the operation – Operands can be registers, memory variables, or constants – Most instructions have three operands L1: addiu t0, t0, 1 #increment the value in t0 Comments • Comments are very important! – Explain the program's purpose – When it was written, revised, and by whom – Explain data used in the program, input, and output – Explain instruction sequences and algorithms used – Comments are also required at the beginning of every procedure • Indicate input parameters and results of a procedure • Describe what the procedure does • Single-line comment – Begins with a pound sign # and terminates at end of line Structure of Conventional Processor • ALU: Arithmetic and Logic Unit • Local storage • Controller • Internal DataPath • External interface Parts of A Conventional Processor • Arithmetic Logic Unit (ALU) Can perform basic operations – Integer arithmetic: addition, subtraction, multiplication, divide – binary AND, OR, NOT, XOR, etc. – Shift (left, right, circular) • Local Storage – Registers – Typical modern processors have 8 to 32 regs, 32 to 64 bits Parts of A Conventional Processor • Controller – tells ALU which operation to perform next, and local storage which operand(s) to provide and where to store result – Executes program • Could be hardwired for simple procs • Could be fetching next line of program from main memory • Internal data path – Has to be "wide" enough to move entire registers quickly. – Multiple of register size • External interface – external to processor, not computer – Connects to external, main memory (RAM) Instruction Set Architecture (ISA) • ISA: the part of the processor that is visible to the programmer or compiler writer – Serves the boundary between software and hardware • The ISA of a processor can be described using 5 categories – Operand storage in the CPU • Where are the operands kept other than in memory? – Number of explicit named operands • How many operands are named in a typical instruction? – Operand location • Can any ALU instruction operand be located in memory? – Operations • What operations are provided in the ISA – Type and size of operands • What is the type and size of each operand and how is it specified? 15 MIPS Instruction Set Architecture ° Instruction Categories . Load/Store . Computational . Jump and Branch . Floating Point (coprocessor) 3 Instruction Formats: all 32 bits wide ALU (R) instructions have 3 operands which are only registers The only memory access is through explicit load/store instructions R OP Rs Rt Rd sa funct I OP Rs Rt Immediate J OP jump target 32 registers Number: $0 $1 $2-$3 $4-$7 Name: zero at v0-v1 a0-a3 $8-$15 $16-$23 $23-$31 t0-t7 s0-s7 8 other registers not discussed here 16.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages16 Page
-
File Size-