Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Machine Organization class I wiuld like you to add some explanations for each step, thank you!! 6. A Parsons Problem. Consider the following program, which
Machine Organization class
6. A Parsons Problem. Consider the following program, which is designed to: (a) accept a pointer to a string of 31 or fewer lower case character; (b) accept a single lower-case character from the user using scanf; (c) determine if the input character is valid and re-prompts the user if necessary; (d) Scans the string, and counts the number of times the input character appears; (c) prints the result. , data , text plzstring: .asciz "Please enter a single lower-case character. In" fmtstring: .asciz "\%1s" outstring: .asciz "The character % s appears % i times in the string %/s. " global main main: stp x29,30,[sp,#16] ! sub sp, sp, \#16 str x0, [sp] 1drx0,=plzstring b1 printf 1dr0, =fmtstring sub sp,sp,\#16 promptuser: mov x1,sp bl scanf mov x0,sp b1 checkchar mov x0,sp 1drx1,[sp,#16] mov x2, \#0 b1 countchar mov w5, u3 1dr0,=outstring mov x1,sp mov x2, sp add x2,x2,#16 bl printf add sp,sp,#32 1dp 29,30,[sp],#16 mov w0,#0 ret checkchar: ldr x1,[x0] cmp 1, \#0x61 b. ge test2 b promptuser test2: cmp 1,#07A b.It goodchar b promptuser goodchar: ret countchar: 1drb w3, [x0] mov w5, \#0 checkequals: 1drbw4,[x1,x2] cbzw4, endofstring cmp w3,w4 b.eq samechar add 2,2,#1 b checkequals samechar: add 5,5,#1 add x2,x2,\#1 b checkequals endofstring: ret It's a little hard to demonstrate this concept, but the question intended here is called a Parsons Problem. Essentially, you would be given the above program in blocks, with each block having one or more instructions. The code within each block is correct. However, the blocks are presented in random order, and the goal is to reorder them so that the program would work correctly. In practice, we might implement this by printing blocks on sticky labels or individual papers, and then you would arrange them on another sheet. A good way to prepare for this sort of question is to go through this program and think about what each instruction does, and why they are in the order presented. Also, this particular set of code is a little longer than what we'd probably put on comps, but it does make for a good exercise to prepare I wiuld like you to add some explanations for each step, thank you!!
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