120 likes | 219 Views
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:
E N D
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: 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
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
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
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
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”
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
Read a char input by using Sys.getChar Display the inputted char to screen by using Sys.putChar Function invocation – Exercise1
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
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
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
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