Question: . ( 3 0 points ) Using the echo _ nsl . s program below, write an assembly program that inputs a single character from
points Using the echonsls program below, write an assembly program that inputs a single
character from stdin and then prints the character before it to stdout. For example, if you enter a D
your program will output a C In order for your character to be passed to your program, you will
have to press the enter key to flush the input buffer. Your program will output only one character.
Name your program prednsls
points Read two decimal digits from stdin and interpret that input as an integer between an
inclusive. Compute x where x is the provided integer. Print the input value, the result in
decimal and hexadecimal like this:
x : fx or x
Spacing matters. You can get the integer value of an ASCII digit by subtracting from it The
appendix has an example of using
Name your program fxs
points Write prompts for the two programs above and submit them to the LLM of your choice. Save
the resulting code not any explanation that came with it into predprom.s and fxprom.s Include
the prompt as a comment at the top of the source file. Also include a critique of the geneated code in
the introductory comments as well
echonsls:
# printf.s
# This program adds and and then outputs the sum in hex. It
# uses stdlib.
# gcc nopie echo.s o echo
# prevents missing note.GNUstack error
section note.GNUstack,"",@progbits
#extern putchar
section data
num: word
num: word
# The h in the format specifier is a length parameter.
# Printf expects a unsigned short int.
format: string "result hx
section text
global main
main:
# Load the values into registers
movl numeax
movl numebx
# Add the values
addl ebx, eax
# save the callee of main, call to printf will wipe it out
push rbp
# Call printf to print the result:
# printfhx
sum
# loads effective address of format string
# into first argument register
lea format, rdi
# move value we want to print into the
# second argument register
movl eax, esi
call printf
# Restore the callee that was overwritten by
# call to printf
pop rbp
ret
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
