Answered step by step
Verified Expert Solution
Question
1 Approved Answer
. macro exit #macro to exit program li a 7 , 1 0 ecall . end _ macro . macro print _ str ( %
macro exit #macro to exit program
li a
ecall
endmacro
macro printstrstring #macro to print any string
li a
la astring
ecall
endmacro
macro readnx#macro to input integer n into register x
li a
ecall
#a now contains user input
addi x a
endmacro
macro printnx#macro to input integer n into register x
addi ax
li a
ecall
endmacro
macro fileopenforwriteappendstr
la astr
li a
li a
ecall
endmacro
macro initialisebuffercounter
#buffer begins at location x
#location x to keep track of which address we store each character byte to
#actual buffer to store the characters begins at x
#initialize memx to x
addi sp sp
sd tsp
sd tsp
li tx
li tx
sd tt
ld tsp
ld tsp
addi sp sp
endmacro
macro writetobufferchar
#NOTE:this macro can add ONLY character byte at a time to the file buffer!
addi sp sp
sd tsp
sd tsp
li tx
ld tt#t is starting address
#t now points to location where we store the current char byte
#store character to file buffer
li tchar
sb tt
#update address location for next character to be stored in file buffer
li tx
addi t t
sd tt
ld tsp
ld tsp
addi sp sp
endmacro
macro fileReadfiledescriptorregister, filebufferaddress
#macro reads upto first characters from file
addi afiledescriptorregister,
li afilebufferaddress
li a
li a
ecall
endmacro
macro fileWritefiledescriptorregister, filebufferaddress,filebufferaddresspointer
#macro writes contents of file buffer to file
addi afiledescriptorregister,
li afilebufferaddress
li a
#a needs to contains number of bytes sent to file
li afilebufferaddresspointer
ld aa
sub a a a
ecall
endmacro
macro printfilecontentsptrregister
li a
addi aptrregister,
ecall
#entire file content is essentially stored as a string
endmacro
macro closefilefiledescriptorregister
li a
addi afiledescriptorregister,
ecall
endmacro
data
prompt: asciz "Enter the height of the pattern must be greater than :
invalidMsg: asciz "Invalid Entry!"
newLine: asciz
stardollar: asciz $
dollar: asciz $
star: asciz
blankspace: asciz
outputMsg: asciz display pattern saved to laboutput.txt
filename: asciz "laboutput.txt
Zero:.asciz"
text
fileopenforwriteappendfilename
#a now contaimns the file descriptor ie ID no
#save to t register
addi t a
initialisebuffercounter
#for utilsing macro writetobuffer, here are tips:
#xa is the ASCI code input for star
#x is the ASCI code input for dollar$
#x is the ASCI code input for the character
#xa is the ASCI code input for newLine n
#START WRITING YOUR CODE FROM THIS LINE ONWARDS
#DO NOT use the registers a a a t sp anywhere in your code.
# your code starts here..........................................................#
# your code ends here..........................................................#
#END YOUR CODE ABOVE THIS COMMENT
#Don't change anything below this comment!
Exit:
#write null character to end of file
writetobufferx
#write file buffer to file
fileWritetxx
addi t a
printstrnewLine
printstroutputMsg
exit
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started