Presentation is loading. Please wait.

Presentation is loading. Please wait.

OutLine of Tutorial 3 Memory Allocation Const string New string(byte array) Read memory in simulator Function invocation How Import library files Modify.

Similar presentations


Presentation on theme: "OutLine of Tutorial 3 Memory Allocation Const string New string(byte array) Read memory in simulator Function invocation How Import library files Modify."— 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 Memory Allocation – Const String 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 Exercise 1:  Draw a memory table to show the data stored.  Write down the first quad word in Hex

3 Const String – Exercise 2 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

4 Const String – Exercise Answer 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: ”; }

5 Memory Allocation – New String 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

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 Function Invocation – How 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 Library name Function name enter

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

9 Function invocation – Exercise1 Answer 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;

10 Library files 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”;

11 Library files 2 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.

12 Exercise 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.


Download ppt "OutLine of Tutorial 3 Memory Allocation Const string New string(byte array) Read memory in simulator Function invocation How Import library files Modify."

Similar presentations


Ads by Google