Implement a simplified printf function

Assignment Help Assembly Language
Reference no: EM133105147

Assignment: Implement a simplified printf function:

As mentioned before, the printf subroutine is just a subroutine like any other. To prove this, you will write your own simplified version of printf in this assignment.

Exercise:

Write a simplified printf subroutine that takes a variable amount of arguments. The first argument for your subroutine is the format string. The rest of the arguments are printed instead of the placeholders (also called format specifiers) in the format string. How those arguments are printed depends on the corresponding format specifiers. Your printf function has to support any number of format specifiers in the format string. Any format specifier after that may be printed without modification.

Unlike the real printf, your version only has to understand the format specifiers listed below. If a format specifier is not recognized, it should be printed without modification. Give your printf function a different name (e.g. my printf) to avoid confusion with the real printf function in the C library. Please note that for this exercise you are not allowed to use the printf function or any other C library function, except for the putchar function to output a single ASCII character. Your function must follow the proper x86 64 calling conventions. It must accept any num- ber of arguments (e.g., tens of arguments) like any standard printf implementation. Refer to Section 3.3.1 for details on how to pass and accept a large number of arguments.

Supported format specifiers:

%d Print a signed integer in decimal. The corresponding parameter is a 64 bit signed integer.

%u Print an unsigned integer in decimal. The corresponding parameter is a 64 bit unsigned integer.

%s Print a null terminated string. No format specifiers should be parsed in this string. The corresponding parameter is the address of first character of the string.

%% Print a percent sign. This format specifier takes no argument.

Example:
Suppose you have the following format string:

My name is %s. I think I'll get a %u for my exam. What does %r do? And %%?

Also suppose you have the additional arguments "Piet" and 10. Then your subroutine should output:

My name is Piet. I think I'll get a 10 for my exam. What does %r do? And %?

Hints

To get started you may divide the work in a number of steps. Note that these are just hints, you do not have to follow these steps to finish this assignment.

1. Write a subroutine that prints a string character by character, for example by using putchar.

2. Modify the subroutine to recognize format specifiers in the format string. Initially, you can discard the format specifiers rather than process them. Characters that are not part of a format specifier can be printed as before.

3. Implement the various format specifiers. It may help to implement %u before %d.

4. It may help to store all input argument registers on the stack at the start of your function, even if you don't end up using them.

Reference no: EM133105147

Questions Cloud

Prepare the year-end closing entries : Marin Consulting, a proprietorship, has the following year-end account balances: Service Revenue $456,000; Prepare the year-end closing entries
By what amount would this donation cause total shareholders : The share was originally issued for P18 per share. By what amount would this donation cause total shareholders' equity to decrease
Hiring people with felony criminal past : As discussed in class this semester, employment laws are relaxing, and more employers are open to hiring people with a felony criminal past.
What is the amount of revenue realized from the sale : Kate Corp. purchased 1,000 shares of its P5 par ordinary share at P10. What is the amount of revenue realized from the sale
Implement a simplified printf function : Write a simplified printf subroutine that takes a variable amount of arguments. The first argument for your subroutine is the format string
How much van running expenses should be recognised : Premises were rented from 1 Jan 2018 at an annual rental of £20,000. How much van running expenses should be recognised
Career goal-information technology : What strategy will you take from this Law to confidently achieve your long-term career goal?
Significance of the innovation to the business industry : Trend 3 - Telehealth The healthcare industry has traditionally been one of the most resistant when it comes to IT and digital technology uptake. However, the CO
Interviewees opinion of salespeople : What common themes did you observe in the responses, especially in the interviewees' opinion of salespeople?

Reviews

len3105147

3/15/2022 10:58:39 PM

I need to work with assembly.AT&T syntax. In the files below i will upload the lab manual with assignment 6 with the references that we need to use and an example code we wrote for another assignment so that you can see the syntax we work with. ( Also worth mentioning that my professor has a 0 tolerance for using code on the internet ). I just need help with assignment 6 and not the bonus part of the assignment

Write a Review

Assembly Language Questions & Answers

  Create a assembly language subroutine

Create a assembly language subroutine MULSUM that takes an array named A containing n bytes of positive numbers, and fills two arrays, array B containing n words and array C containing n long words

  Write a function in linux assembly

Write a function in Linux assembly

  Analog measurements

Prepare an assembly program for the correctly measures the wind direction

  Design a simple digital clock

Design a simple digital clock

  Write an assembly program

Prepare an Assembly program that reads in a number of cents.

  Write an assembly language program

Write an assembly language program for encrypting alphabates of a string

  Greatest common divisor of integers-masm assembly language

Must be done in MASM assembly language: Greatest common divisor of two integers is largest integer which will evenly divide both integers. GCD algorithm involves integer division in a loop.

  Write assembly program-find right admission price to movie

Write the Assembly program to find correct admission price to movie. Price of admission to a movie is $7 for kids (under 12) and $9 for adults.

  Create simple 8-bit alu using add-subtract-shift functions

Create a simple 8-bit ALU. Requirements:The eight functions that you will implement are: add, subtract, and, or, shift left logical, less than, shift right logical.

  Write assembly program print binary representation-integers

Write the assembly program called hw6_ex1, stored in file hw6_ex1.asm. This program must prompt user to enter signed 32-bit integer. Program must print out binary representation of the integer.

  Allot op-codes and add microcode to microprogram

Allot op-codes and add microcode to microprogram of Mic-1 to implement following instructions which are then included with IJVM instruction set.

  Write mips assembly program to read two non-negative numbers

Write MIPS assembly program to repeatedly read two non-negative integers and print integer product and quotient without using multiplication and division instructions.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd