Question: Using the student _ inputC.s Download student _ inputC.sARM code provided in the Files - - > ARM Programs on Canvas and discussed in class

Using the student_inputC.s Download student_inputC.sARM code provided in the Files --> ARM Programs on Canvas and discussed in class expand the code to do all the following:
1. Prompt the user for an input number (integer).[Already in program]
2. Print the input number back to the screen. [Already in program]
3. Prompt the user for an input character. [New function]. Use "%c" instead of "%d" for the input. This will keep from reading the CR from the previous input.
4. Print the input character back to the screen. [New function]. Use "%c" for the output.
5. Return control back to the operating system. [Already in program]
Also modify the code comments to include:
CS309-01
Use the Raspberry Pi computer assemble, link and run your program. Once you have it working upload the .s as your submission. Name your program yourlastname2.s.
Here is the code: (Please add the answer to where it works with this code)
@ Filename: student_inputC.s
@ Author: Kevin Preston
@ Purpose: Show CS309 and CS413 students how to read user inputs from
@ the keyboard. Students are expected to learn ARM assembly in
@ these courses not obscure details about C printf and scanf.
@ In most cases it should be assumed the user provided a valid
@ input.
@
@ History:
@ Date Purpose of change
@ ---------------------
@ 4-Jul-2019 Changed this code from using the stack pointer to a
@ locally declared variable.
@ 15-Sep-2019 Moved some code around to make it clearer on how to
@ get the input value into a register.
@ 1-Oct-2019 Added code to check for user input errors from the
@ scanf call.
@ 21-Feb-2019 Added comments about "%c" vs "%c" related to scanf.
@
@ Use these commands to assemble, link, run and debug this program:
@ as -o student_inputC.o student_inputC.s
@ gcc -o student_inputC student_inputC.o
@ ./student_inputC ;echo $?
@ gdb --args ./student_inputC
@ ***********************************************************************
@ The =(equal sign) is used in the ARM Assembler to get the address of a
@ label declared in the .data section. This takes the place of the ADR
@ instruction used in the textbook.
@ ***********************************************************************
.equ READERROR, 0 @Used to check for scanf read error.
.global main @ Have to use main because of C library uses.
main:
@*******************
prompt:
@*******************
@ Ask the user to enter a number.
ldr r0,=strInputPrompt @ Put the address of my string into the first parameter
bl printf @ Call the C printf to display input prompt.
@*******************
get_input:
@*******************
@ Set up r0 with the address of input pattern.
@ scanf puts the input value at the address stored in r1. We are going
@ to use the address for our declared variable in the data section - intInput.
@ After the call to scanf the input is at the address pointed to by r1 which
@ in this case will be intInput.
ldr r0,=numInputPattern @ Setup to read in one number.
ldr r1,=intInput @ load r1 with the address of where the
@ input value will be stored.
bl scanf @ scan the keyboard.
cmp r0, #READERROR @ Check for a read error.
beq readerror @ If there was a read error go handle it.
ldr r1,=intInput @ Have to reload r1 because it gets wiped out.
ldr r1,[r1] @ Read the contents of intInput and store in r1 so that
@ it can be printed.
@ Print the input out as a number.
@ r1 contains the value input to keyboard.
ldr r0,=strOutputNum
bl printf
b myexit @ leave the code.
@***********
readerror:
@***********
@ Got a read error from the scanf routine. Clear out the input buffer then
@ branch back for the user to enter a value.
@ Since an invalid entry was made we now have to clear out the input buffer by
@ reading with this format %[^
] which will read the buffer until the user
@ presses the CR.
ldr r0,=strInputPattern
ldr r1,=strInputError @ Put address into r1 for read.
bl scanf @ scan the keyboard.
@ Not going to do anything with the input. This just cleans up the input buffer.
@ The input buffer should now be clear so get another input.
b prompt
@*******************
myexit:
@*******************
@ End of my code. Force the exit and return control to OS
mov r7, #0x01 @ SVC call to exit
svc 0 @ Make the system call.
.data
@ Declare the strings and data needed
.balign 4
strInputPrompt: .asciz "Input the number:
"
.balign 4
strOutputNum: .asciz "The number value is: "%d "
@ Format pattern for scanf call.
.balign 4
numInputPattern: .asciz "%d" @ integer format for read.
.balign 4
strInputPattern: .asciz "%[^
]" @ Used to clear the input buffer for invalid
input.
.balign 4
strInputError: .skip 100*4 @ User to clear the input buffer for invalid input.
.balign 4
intInput: .word 0 @ Location used to store the user input.
@ Let the assembler know these are the C library functions.
.global printf
.global scanf

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!