Answered step by step
Verified Expert Solution
Link Copied!

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 0x24) and character '0'(ascii hex 0x30) and the newline character
(ascii hex code 0x0a).
1. It will first prompt for the height of the pattern (i.e., 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 Lab3.asm file provided.
2. Then your program should generate the following pattern, a " right-angled triangle", using the
aforementioned characters. Refer to test cases in testCases sub folder in Lab3 folder for examples.
3. This entire pattern generated from the user input of n is written to the file lab3_output.txt.
****************************************************************************************
Below is the Lab3.asm 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
*************************************************************
Lab3.asm
.macro exit #macro to exit program
li a7,10
ecall
.end_macro
.macro print_str(%string1) #macro to print any string
li a7,4
la a0,%string1
ecall
.end_macro
.macro read_n(%x)#macro to input integer n into register x
li a7,5
ecall
#a0 now contains user input
addi %x, a0,0
.end_macro
.macro print_n(%x)#macro to input integer n into register x
addi a0,%x,0
li a7,1
ecall
.end_macro
.macro file_open_for_write_append(%str)
la a0,%str
li a1,1
li a7,1024
ecall
.end_macro
.macro initialise_buffer_counter
#buffer begins at location 0x10040000
#location 0x10040000 to keep track of which address we store each character byte to
#actual buffer to store the characters begins at 0x10040008
#initialize mem[0x10040000] to 0x10040008
addi sp, sp,-16
sd t0,0(sp)
sd t1,8(sp)
li t0,0x10040000
li t1,0x10040008
sd t1,0(t0)
ld t0,0(sp)
ld t1,8(sp)
addi sp, sp,16
.end_macro
.macro write_to_buffer(%char)
#NOTE:this macro can add ONLY 1 character byte at a time to the file buffer!
addi sp, sp,-16
sd t0,0(sp)
sd t4,8(sp)
li t0,0x10040000
ld t4,0(t0)#t4 is starting address
#t4 now points to location where we store the current %char byte
#store character to file buffer
li t0,%char
sb t0,0(t4)
#update address location for next character to be stored in file buffer
li t0,0x10040000
addi t4, t4,1
sd t4,0(t0)
ld t0,0(sp)
ld t4,8(sp)
addi sp, sp,16
.end_macro
.macro fileRead(%file_descriptor_register, %file_buffer_address)
#macro reads upto first 10,000 characters from file
addi a0,%file_descriptor_register, 0
li a1,%file_buffer_address
li a2,10000
li a7,63
ecall
.end_macro
.macro fileWrite(%file_descriptor_register, %file_buffer_address,%file_buffer_address_pointer)
#macro writes contents of file buffer to file
addi a0,%file_descriptor_register, 0
li a1,%file_buffer_address
li a7,64
#a2 needs to contains number of bytes sent to file
li a2,%file_buffer_address_pointer
ld a2,0(a2)
sub a2, a2, a1
ecall
.end_macro
.macro print_file_contents(%ptr_register)
li a7,4
addi a0,%ptr_register, 0
ecall
#entire file content is essentially stored as a string
.end_macro
.macro close_file(%file_descriptor_register)
li a7,57
addi a0,%file_descriptor_register, 0
ecall
.end_macro
.data
prompt: .asciz "Enter the height of the pattern (must be greater than 0):"
invalidMsg: .asciz "Invalid Entry!"
newLine: .asciz "
"
star_dollar: .asciz "*$"
dollar: .asciz "$"
star: .asciz "*"
blankspace: .asciz ""
outputMsg: .asciz " display pattern saved to lab3_output.txt "
filename: .asciz "lab3_output.txt"
Zero:.asciz"0"
.text
file_open_for_write_append(filename)
#a0 now contaimns the file descriptor (i.e. ID no.)
#save to t6 register
addi t6, a0,0
initialise_buffer_counter
#for utilsing macro write_to_buffer, here are tips:
#0x2a is the ASCI code input for star(*)
#0x24 is the ASCI code input for dollar($)
#0x30 is the ASCI code input for the character '0'
#0x0a is the ASCI code input for newLine (/n)
#START WRITING YOUR CODE FROM THIS LINE ONWARDS
#DO NOT use the registers a0, a1, a7, t6, 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
write_to_buffer(0x00)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions