assembly - How can one implement printf-like functionality in assembler? -


I'm just looking for feedback and guidance rather than a straightforward answer.

.586 Assembling instructions, how can you simulate functionality like printf? For fixed width areas, I know that I can do something like this:

  .data format BYTE 'you are ## years old., 0   

And before printing the string, change the ## value to the appropriate number, to be changed later if I need to use the format string multiple times with different values.

It may not be the best way, but now it works.

I do not understand how to do it if you do not know the number of digits before time. The option is okay if you should know which marks in the maximum number you want to use (For example, do not work very well for people 100 years of age or older, you lose space between words).

If you reserve a lot of space, you get double space between your number and your world.

 . Data format BYTE 'You are ### years old, 0   

My plan will be used with 12 people:

  You are 12 years old   

My only thought was that there was such a ASCII character which is nothing (separate \ 0 ), But it is very complicated.

The whole problem arises because the trainer wants us to be able to use this type of string to use a call to a print stringing process (which he had given us), which Looks like \ 0 is set to esi .

You agree that your output will be in the same buffer used to specify formatting - C printf () Routines do not do this, it also realizes that the conversion due to the format specifier does not need to take the number of characters in the form of output as the format specifier, for example , Output to printf () specification % s 2 Fie can take characters (or at least have access to at least 2 characters).

You can do the same thing according to your assembly rule, which are routine - format for the format string function (and not modified) because the format to be converted into the form specified by the string Are there. The output produced by the function goes elsewhere - either for an output routine that sends data to a file or device, or returns the memory buffer provided by the caller.

The function format string runs, it can decide that the characters need to go into the unchanged output (i.e. the format string in the format not the format specifier). When it comes to the format specifier, it will consume another input parameter, convert it according to the format specifier, and send those characters to output.

Comments