csci341
play

CSCI341 Lecture 21, MIPS Programming REVIEW Assemblers understand - PowerPoint PPT Presentation

CSCI341 Lecture 21, MIPS Programming REVIEW Assemblers understand special commands called directives instructions for the assembler, eg, .text Assemblers understand macro commands higher-level instructions that abstract


  1. CSCI341 Lecture 21, MIPS Programming

  2. REVIEW • Assemblers understand special commands called “directives” • instructions for the assembler, eg, .text • Assemblers understand “macro” commands • higher-level instructions that abstract multiple “integer” instructions, eg, mult vs mul

  3. ASSEMBLY LANGUAGE One-to-one correspondence with machine instruction. Assembly is easier for humans to read than 010101, etc.

  4. ASSEMBLY LANGUAGE mnemonics Symbols that help us “remember” something else. The mnemonic addi helps us “remember” 00...10..11.

  5. ASSEMBLY PROCESS source assembler object file linker executable source assembler object file libs

  6. ASSEMBLY PROCESS high-level object compiler assembler source file linker executable high-level object compiler assembler source file

  7. ASSEMBLY = CONTROL (AND SPEED) Often difficult to ensure high-level language program responds within definite time interval.

  8. PROFILING Measuring where a program spends its time (among other things). Performance improvements may require recoding a critical part in assembly language. eg, Embedding assembly in parts of your C program.

  9. MAN VS. MACHINE Historically, when compilers were more primitive, humans could often out-optimize the compiler.

  10. Today? Not so much.

  11. HOW DOES AN ASSEMBLER WORK? • Bind program labels to memory locations. • Translate assembly instructions to an object file.

  12. WHAT’S AN OBJECT FILE? • Contains machine instructions, data, and “bookkeeping” • Typically is never directly executed, because it references... • procedures or data in other files

  13. LOCAL VS. GLOBAL • Programs usually generated from multiple assembly files / object files. • Some labels need to remain “local” or “private” to a file. • Others need to be “global” and accessible from all files.

  14. CONSIDER... .text “hey assembler, make sure all the object .globl main files you create know about this label.” main: global label subu $sp, $sp, 32 ... flower_loop: local label lw $t6, 28($sp) ... jal printf That better be a global label, since it’s not declared in this file. ... ...

  15. .globl SomeSymbol Declare SomeSymbol as global, so it can be referenced from other files.

  16. LOCAL SYMBOLS If a label isn’t global, then it’s local. “A label is local if the label can be used only within the file in which it is defined.”

  17. THE LINKER • The assembler processes one file at a time, in isolation. • It only knows the addresses of local labels! • The linker resolves external labels. • But the assembler “helps,” by providing lists of labels and unresolved references. (Part of the “bookkeeping”)

  18. HOW DOES AN ASSEMBLER WORK? • Bind program labels to memory locations. • Translate assembly instructions to an object file.

  19. FIRST PASS • Read each line of assembly • Break it into pieces or lexemes. • ble $t0, 100, loop (six lexemes) • If the line begins with a label, then record that label and its instruction address in a symbol table.

  20. SYMBOL TABLE A table that maps labels to addresses. (example) address label hm, line swing 0xN...N 23 hm, line pitch 0xN...N 76

  21. HOW DOES AN ASSEMBLER WORK? • Bind program labels to memory locations. • Translate assembly instructions to an object file.

  22. SECOND PASS • Examine each line of the instructions • If it contains an instruction, translate it to binary machine code • Replace local label references with addresses in the symbol table • Leave instructions using external symbols unresolved. • The linker will help resolve addresses needed by these instructions.

  23. WHAT IS AN OBJECT FILE, REALLY? Structured encoding of your assembly instructions. Six segments. object file text data symbol debugging relocation header segment segment information table info

  24. HEADER object file text data symbol debugging relocation header segment segment information table info Describes the size and position of the other pieces of the file.

  25. TEXT object file text data symbol debugging relocation header segment segment information table info Contains machine language from the source file. May contain unresolved references! (therefore unexecutable) .text

  26. DATA object file text data symbol debugging relocation header segment segment information table info Contains binary representation of data from your source file. May also contain unresolved references. .data

  27. RELOCATION object file text data symbol debugging relocation header segment segment information table info Instructions and data that depend on specific, absolute addresses . These references have to change if portions of the program are moved in memory.

  28. RELOCATION object file text data symbol debugging relocation header segment segment information table info Instructions and data that depend on specific, absolute addresses . “Grab a beverage, the third bottle on the third shelf.” If the whole shelf moves, you need to revise your specific instruction.

  29. RELOCATION object file text data symbol debugging relocation header segment segment information table info The assembler doesn’t know the final, specific memory locations a procedure or piece of data will occupy after it is linked with other object files. (The linker will determine where the shelf of beverages will be finally located.)

  30. SYMBOL TABLE object file text data debugging relocation symbol header segment segment information table info A mapping of labels to addresses, as well as unresolved references.

  31. DEBUGGING INFORMATION object file text data relocation symbol debugging header segment segment information table info A description of how the program was compiled. For a debugger/assembler can find which memory addresses correspond to which lines of source code. (“Look at line 6” is better than “look at instruction 0xnnnnnnnn.”)

  32. HOMEWORK • Reading 19 • Textbook sections B.6 & 2.8 FUNctions!

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend