Question: . ( 3 0 points ) Using the echo _ nsl . s program below, write an assembly program that inputs a single character from

.(30 points) Using the echo_nsl.s 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 pred_nsl.s.
2.(60 points) Read two decimal digits from stdin and interpret that input as an integer between 0 an
99, inclusive. Compute 27x +17, where x is the provided integer. Print the input value, the result in
decimal and hexadecimal like this:
x =19 : f(x)=530 or 0x212
Spacing matters. You can get the integer value of an ASCII digit by subtracting 0 from it. The
appendix has an example of using
Name your program fx.s.
3.10 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 pred_prom.s and fx_prom.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
echo_nsl1.s:
# printf.s
# This program adds 48 and 29 and then outputs the sum in hex. It
# uses stdlib.
# gcc -no-pie echo.s -o echo
# prevents missing .note.GNU-stack error
.section .note.GNU-stack,"",@progbits
#.extern putchar
.section .data
num1: .word 48
num2: .word 29
# The h in the format specifier is a length parameter.
# Printf expects a unsigned short int.
format: .string "result =%04hx
\0"
.section .text
.global main
main:
# Load the values into registers
movl num1,%eax
movl num2,%ebx
# 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:
# printf("%04hx
", 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 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!