Placing Constant Data in a Subroutine in Visual Studio .NET

Generation QR Code in Visual Studio .NET Placing Constant Data in a Subroutine
Placing Constant Data in a Subroutine
Recognizing QR Code 2d Barcode In .NET Framework
Using Barcode Control SDK for VS .NET Control to generate, create, read, scan barcode image in VS .NET applications.
By now you're used to thinking of code as living in the [text] section, and data as living in the [data] section In almost all cases this is a good way to organize things, but there's no absolute demand that you separate code and data in this way It's possible to define data within a subroutine using NASM's pseudoinstructions including DB, DW, and DD I've created a useful subroutine that shows how this is done and is a good example of when to do it The subroutine allows you to issue some number of newline characters to standard output, specified by a value passed to the subroutine in EAX: newline: mov ecx,10 ; We need a skip value, which is 10 minus the sub ecx,eax ; number of newlines the caller wants add ecx, dword nl ; This skip value is added to the address of push dword ecx ; the newline buffer nl before calling printf call printf ; Display the selected number of newlines add esp,4 ; Clean up the stack ret ; Go home nl db 10,10,10,10,10,10,10,10,10,10,0 The buffer nl contains 10 newline characters, followed by a null It is thus a null-terminated string of newline characters, and you can pass all of it-or any chunk starting in the middle and going to the end-to printf If you pass printf the address of the beginning of the string, printf will output all 10 newlines, and your display will scroll by 10 lines If you pass printf the address of the third newline, printf will output only 8 newlines, having skipped the first 2 If you only want printf to output a single newline, you pass printf the address of the very last newline, so that the only things that printf actually sends to standard output will be the final newline and the null character All the trickery is in calculating the address to pass to printf The algorithm: To output x newline(s), we need to skip past 10 - x newline(s) This is why we load 10 into ECX and subtract EAX from it The resulting value in EAX becomes the offset that, when added to the address represented by nl, gives you the address of the place in the string where printf should begin outputting Having the data right in the subroutine means that it's easy to cut and paste the subroutine from one program into another without leaving the essential table of newline characters behind And because the only code that ever uses the newline table is the subroutine itself, there's no benefit to placing the newline table in the more centrally visible [data] section
Paint QR Code ISO/IEC18004 In .NET
Using Barcode printer for .NET Control to generate, create QR Code JIS X 0510 image in .NET applications.
Accessing Command-Line Arguments
QR Code JIS X 0510 Scanner In Visual Studio .NET
Using Barcode decoder for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
One of the most useful things to be able to do when writing simple utilities is to pass them parameters C people call them arguments on the command line If you're working in C or Pascal, these are set up as predefined arrays or functions and are a snap to use In assembly, there's no such convenience (Surprise!) You have to know where and how they're stored, which is (alas) nontrivial On the other hand, getting at command-line arguments is a wonderful exercise both in the use of pointers and also of accessing the stack up-memory from EBP, where a number of interesting things live EBP is your marker driven into the stack, and it anchors your access to both your own items (stored down-memory from EBP) and those owned by the runtime library, which are up-memory Because we're talking about a pointer to a pointer to a table of pointers to the actual argument strings, the best way to begin is to draw a picture of the lay of the land Figure 133 shows the pointer relationships and stack structures we have to understand to identify and read the command-line arguments
Barcode Creator In .NET
Using Barcode printer for VS .NET Control to generate, create bar code image in .NET applications.
Figure 133: Linux command-line arguments As I explained earlier in this chapter, when Linux passes control to your program, the C library's startup code gets control first, and it sets up a number of things for you, before the code that you wrote ever begins executing One of the things the startup code does is set up your program's access to the command-line arguments It does this by building a table of pointers to the arguments and placing a pointer to that table of pointers on the stack, up-memory from EBP The startup code places other things on the stack as well Immediately above EBP is the return address for your portion of the code When your code is done, it executes a RET instruction, which takes execution back into the runtime library code's shutdown sequence This RET instruction uses the return address just above EBP to take execution to the shutdown sequence The shutdown sequence has its own return address, which eventually takes it back into Linux You don't need to access the return address for anything; and certainly don't change it! Immediately above the return address, at offset 8 from EBP (as the literature would say, at EBP+8) is an integer count of the number of arguments There will always be at least one, because the name of the program is the first command-line argument (After all, you typed the name on the command line, no ) Immediately above the argument count, at EBP+12, is a pointer to the argument table Immediately above that, at EBP+16, is a pointer to the table of environment variable pairs Reading environment variable pairs is done pretty much the same way as reading command-line arguments, so if you understand one, you won't have much trouble with the other
Bar Code Reader In .NET Framework
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
Creating QR Code In C#.NET
Using Barcode maker for Visual Studio .NET Control to generate, create Denso QR Bar Code image in VS .NET applications.
Draw QR-Code In VB.NET
Using Barcode maker for VS .NET Control to generate, create QR image in .NET framework applications.
Print USS-128 In .NET Framework
Using Barcode encoder for .NET framework Control to generate, create UCC-128 image in VS .NET applications.
Encoding Leitcode In .NET
Using Barcode creator for .NET framework Control to generate, create Leitcode image in VS .NET applications.
Making EAN-13 Supplement 5 In Java
Using Barcode drawer for Java Control to generate, create EAN-13 image in Java applications.
Painting EAN / UCC - 14 In Visual Basic .NET
Using Barcode generation for VS .NET Control to generate, create UCC - 12 image in .NET applications.
Reading European Article Number 13 In .NET
Using Barcode reader for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
Print EAN128 In Java
Using Barcode printer for Java Control to generate, create USS-128 image in Java applications.