csci341
play

CSCI341 Lecture 22, MIPS Programming: Directives, Linkers, Loaders, - PowerPoint PPT Presentation

CSCI341 Lecture 22, MIPS Programming: Directives, Linkers, Loaders, Memory REVIEW Assemblers understand special commands called directives Assemblers understand macro commands Assembly programs become object files


  1. CSCI341 Lecture 22, MIPS Programming: Directives, Linkers, Loaders, Memory

  2. REVIEW • Assemblers understand special commands called “directives” • Assemblers understand “macro” commands • Assembly programs become object files • Object files are structured in a specific way (six segments)

  3. REVIEW Six segments. object file text data symbol debugging relocation header segment segment information table info You should have a good understanding of what these segments are for.

  4. ASSEMBLER DIRECTIVES • .data Your new friend: .asciiz • .text (and her brother, .ascii ) • .double • .globl

  5. .ASCIIZ “Store this string in consecutive bytes in memory, and null-terminate it.”

  6. .ASCII “Store this string in consecutive bytes in memory, but don’t null-terminate it.”

  7. EXAMPLE .asciiz “liberty” is like... .byte 108, 105, 98, 101, 114, 116, 121, 0

  8. .BYTE CRASHES YOUR .ASCIIZ PARTY! .byte Another directive you now know. “Store n 8-bit values in successive bytes of memory.”

  9. .BYTE “Store n 8-bit values in successive bytes of memory.” .byte b 1, b 2, b 3, b 4 ..., b n .byte 1, 8, 6, 7, 5, 3, 0, 9 addr 0 1 2 3 4 5 6 7 val 1 8 6 7 5 3 0 9

  10. EXAMPLE .asciiz “liberty” is like... .byte 108, 105, 98, 101, 114, 116, 121, 0

  11. EXAMPLE .asciiz directives are often labeled. Why? .data welcome: .asciiz “Welcome to the jungle!” .text # assembly code here... “Store the string Welcome to the jungle! and remember it’s base address as welcome . ”

  12. NULL TERMINATION A “special” character whose ascii code is 0.

  13. WHY NULL-TERMINATION? Common functions such as println or the OS syscall(8) will read your ascii data beginning with the base address until the null character is “found.”

  14. .ASCIIZ AND SYSCALL (printing a string on the console) • Store a string in memory using .asciiz • Print the string to the screen via syscall • (we’ll return to this after break)

  15. LINKERS • Separate compilation of files (“modules”) means we’ve got to “link” them together before execution. • (To resolve all unresolved labels and symbols)

  16. LINKERS • Search program libraries to find library function calls in the program • Determine memory locations that each module’s instructions will occupy, and relocate those instructions by adjusting absolute references. • (Remember, “the shelf may move,” so instructions referencing something on the shelf must change.) • Resolve references among modules

  17. LINKER MISSION #1 • Ensure the program has no undefined labels. • Aside: remember all those compiler warnings about unused or “unmatched” variable references? • Those are symbols that were defined but never used.

  18. LINKER MISSION #2 • If a program uses a library function, “extract” the function’s code from the library and integrate it into the final executable. • (Keep in mind library functions may call other library functions) • Continue this process until all external references are resolved.

  19. LINKER MISSION #3 • Determine the memory locations each “module” will occupy. • Absolute address references must be relocated. • Process is assisted by relocation information segment of each module’s object file.

  20. LINKER COMPLETE? • Produces executable file. • Typically has same segment-format as object file, except: • There are no longer unresolved references • No relocation information is stored

  21. LOADING • Executable programs first reside on disk (secondary storage) • To “execute” a program means to: • Load the executable file into memory • Set the program counter to the base address of what was just loaded • Go!

  22. LOADING (HELLO KERNEL!) The “kernel” is the central component of the operating system. It’s the “bridge” between applications and the hardware layer. Handles system calls.

  23. LOADING • OS reads the file’s header to determine size of text and data segments • Creates space in memory for the program (instructions, data and a “workspace” or “stack”) • Copies instructions and data into memory • Copies arguments passed to the program onto the stack • Initializes the machine registers (sets the stack pointer) • Jumps to a startup routine that calls the main routine

  24. LOADING • Lastly, if main returns, the startup routine terminates the program via an exit system call.

  25. AFTER BREAK: • Memory usage • Stacks • Procedure calling (B.6, 2.8)

  26. HOMEWORK • Reading 20 • MIPS Assembly Language Programming • Chapter 4 (online) • Start reviewing for the midterm yeah midterms!

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