Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This program should print out a pattern with dollar signs ( $ , ascii hex code 0 x 2 4 ) and character ' 0
This program should print out a pattern with dollar signs$ ascii hex code x and character ascii hex x and the newline character
ascii hex code xa
It will first prompt for the height of the pattern ie the number of rows in the pattern If the user enters an invalid input such as a negative number or zero, an error message will be printed and the user will be prompted again. These error messages are listed in the starter code in the Labasm file provided.
Then your program should generate the following pattern, a rightangled triangle", using the
aforementioned characters. Refer to test cases in testCases sub folder in Lab folder for examples.
This entire pattern generated from the user input of n is written to the file laboutput.txt
Below is the Labasm code that was provided with the problem statement. Please write the code that needs to be added to the part which is left blank and has to be written after the comments # your code starts here..........................................................#
Please help. Thanks
Labasm
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
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