Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 1: Syscall input and output Home This assignment will run through the second program everyone writes, prompting for the user's name and then greeting

image text in transcribedimage text in transcribed

Assignment 1: Syscall input and output Home This assignment will run through the second program everyone writes, prompting for the user's name and then greeting them by name. When you run the final program, it should work like this: What is your name: Andy Hello, Andy, nice to meet you! (Where Andy is what I typed in; the rest was printed by the program.) In order to do this, you will need to add another syscall to your repertoire: syscall code is SYS_READ, which reads from a stream up to a newline or a maximum length (whichever comes first) and stores the resulting bytes into a buffer. rax = 0, SYS_READ rdi = the stream to read from. Standard input (stdin) is stream 0. rsi = the address of the beginning of the buffer to save the read-in bytes into rdx = the maximum number of bytes to read in (i.e. the length of the buffer). Reading will stop after this many bytes, or after a newline character, whichever comes first. Note that the characters stored in the buffer are not NUL-terminated; instead, the syscall will return" the number of bytes read in, including the newline, by storing it into rax. Because you need to use rax for other things, you'll want to copy this value into one of the registers that is not used by syscalls. This length will include the newline that ended the input, so you'll probably want to subtract 1 to prevent that from appearing in the output There's no way to "concatenate" strings in assembly, so to print the final message you will need three syscalls: one to print Hello, , a second to print the contents of the buffer, and a third to print , nice to meet you!. When you print the contents of the buffer, the length you should use is not the BUFFER_LEN , because it's unlikely that the user typed in a name that filled the entire buffer; instead, use the length returned by the SYS_READ syscall (which you should have saved into a different register). Like all syscall-style programs, this one must end with a SYS_EXIT = 60 syscall, to correctly exit the program. Here's a skeleton that you can use to start: Like all syscall-style programs, this one must end with a SYS_EXIT 60 syscall, to correctly exit the program. Here's a skeleton that you can use to start: ;;; greet.s ;;; Prompt the user for their name, then greet them by name. ;;; At runtime, the program should work like this:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions

Question

4. Prove Theorem 9.1.10.

Answered: 1 week ago