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 studentinputC.s Download studentinputC.sARM code provided in the Files ARM Programs on Canvas and discussed in class expand the code to do all the following:
Prompt the user for an input number integerAlready in program
Print the input number back to the screen. Already in program
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.
Print the input character back to the screen. New function Use c for the output.
Return control back to the operating system. Already in program
Also modify the code comments to include:
CS
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 yourlastnames
Here is the code: Please add the answer to where it works with this code
@ Filename: studentinputC.s
@ Author: Kevin Preston
@ Purpose: Show CS and CS 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
@
@ Jul Changed this code from using the stack pointer to a
@ locally declared variable.
@ Sep Moved some code around to make it clearer on how to
@ get the input value into a register.
@ Oct Added code to check for user input errors from the
@ scanf call.
@ Feb Added comments about c vs c related to scanf.
@
@ Use these commands to assemble, link, run and debug this program:
@ as o studentinputC.o studentinputC.s
@ gcc o studentinputC studentinputC.o
@ studentinputC ;echo $
@ gdb args studentinputC
@
@ 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, @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 rstrInputPrompt @ Put the address of my string into the first parameter
bl printf @ Call the C printf to display input prompt.
@
getinput:
@
@ Set up r with the address of input pattern.
@ scanf puts the input value at the address stored in r 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 r which
@ in this case will be intInput.
ldr rnumInputPattern @ Setup to read in one number.
ldr rintInput @ load r with the address of where the
@ input value will be stored.
bl scanf @ scan the keyboard.
cmp r #READERROR @ Check for a read error.
beq readerror @ If there was a read error go handle it
ldr rintInput @ Have to reload r because it gets wiped out.
ldr rr @ Read the contents of intInput and store in r so that
@ it can be printed.
@ Print the input out as a number.
@ r contains the value input to keyboard.
ldr rstrOutputNum
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 rstrInputPattern
ldr rstrInputError @ Put address into r 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 r #x @ SVC call to exit
svc @ Make the system call.
data
@ Declare the strings and data needed
balign
strInputPrompt: asciz "Input the number:
balign
strOutputNum: asciz "The number value is: d
@ Format pattern for scanf call.
balign
numInputPattern: asciz d @ integer format for read.
balign
strInputPattern: asciz
@ Used to clear the input buffer for invalid
input.
balign
strInputError: skip @ User to clear the input buffer for invalid input.
balign
intInput: word @ 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
