1 / 12

OutLine of Tutorial 3

OutLine of Tutorial 3. Memory Allocation Const string New string(byte array) Read memory in simulator Function invocation How Import library files Modify example 1 using what we learned today. const { align quad; message1: asciiz “question” align quad; message2:

phila
Download Presentation

OutLine of Tutorial 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OutLine of Tutorial 3 • Memory Allocation • Const string • New string(byte array) • Read memory in simulator • Function invocation • How • Import library files • Modify example 1 using what we learned today

  2. const { align quad; message1: asciiz “question” align quad; message2: ascii “question” } Notes: Strings are stored in big endian One char is stored in one byte Allocated space is multiple of the size of the specified type (here is quad). asciiz directive: an extra zero byte is allocated and added on the end Memory Allocation – Const String Exercise 1: • Draw a memory table to show the data stored. • Write down the first quad word in Hex

  3. Write alpha assembly code to allocate memory for two strings. One is “Type some input: ”. The other is “Your input was: ” Draw a table to show how memory is allocated Const String – Exercise 2

  4. Write alpha assembly code to allocate memory for two strings. One is “Please type some inputs: ”. The other is “Your input is: ” const { align quad; message1: asciiz “Type some input: ”; align quad; message2: asciiz “Your input was: ”; } Const String – Exercise Answer

  5. abs{ BUFFERSIZE = 10 } data{ align quad; buffer: byte [BUFFERSIZE + 1]; } Notes: define buffer size of the string In “abs”-absolute section Allocating memory for a new string by allocating memory for a byte array Allocate array in “data” section Array size needs to be buffer size plus 1 because of ascizz Memory Allocation – New String

  6. Memory Reading in Simulator • Load example 2 • Open user memory window • Find memory section by using search window. Or type “CTRL+f” • Type blockName.sectionName or blockName.memoryLabel • For example “main.data”,“main.message1”

  7. bsr Sys.getChar.enter; Steps: Load function parameters to register $a0…$a6 Call procedure by using instruction “bsr” followed by a operand(entry point to the function). The return value is stored in register $V0 Function Invocation – How Library name Function name enter

  8. Read a char input by using Sys.getChar Display the inputted char to screen by using Sys.putChar Function invocation – Exercise1

  9. Read a char input by using Sys.getChar Display the inputted char to screen by using Sys.putChar bsr Sys.getChar.enter; mov $v0, $a0; bsr Sys.putChar.enter; Function invocation – Exercise1 Answer

  10. What and why declarations, definitions, and functions supported by the simulator system. “IMPORT” folder contains all files that you can import in your assembly code code syntax to import library files: import “path of the file to import”; For example: import “..\IMPORT\register.h”; Library files

  11. files in “IMPORT” folder .h files: contain declarations and absolute definitions which usually are used in your assembly code and system supplied functions. Like, registers($a0,$v0…) “callsys.h”: system call “register.h”: integer and float registers “proc.h”: special registers which are used in functions supplied by system “entryReg.h” .s files: contain system supplied functions, like print. “callsys.lib.s”: contains functions like “getChar” “io.lib.s”: contains functions like “print”, “readLine” Others: you can read them if you are interested. Reading library files is always a good way to know a language system quickly. Library files 2

  12. Modify example 1 by replacing system calls with functions Sys.getChar and Sys.putChar Try to find out what library files you need to import to use these two functions. Exercise

More Related