Who Decrements CX in .NET

Painting Denso QR Bar Code in .NET Who Decrements CX
Who Decrements CX
QR-Code Recognizer In Visual Studio .NET
Using Barcode Control SDK for .NET framework Control to generate, create, read, scan barcode image in .NET applications.
Early in my experience with assembly language, I recall being massively confused about where and when the CX register was decremented when using string instructions It's a key issue, especially when you don't use the REP prefix When you use REP STOSW (or REP with any of the string instructions), CX is decremented automatically, by 1, for each memory access the instruction makes And once CX gets itself decremented down to 0, REP STOSW detects that CX is now 0 and stops firing into memory Control then passes down to the next instruction in line But take away REP, and the automatic decrementing of CX stops So, also, does the automatic detection of when CX has been counted down to 0 Obviously, something has to decrement CX, since CX governs how many times the string instruction accesses memory If STOSW doesn't do it-you guessed it-you have to do it somewhere else, with another instruction The obvious way to decrement CX is to use DEC CX And the obvious way to determine if CX has been decremented to 0 is to follow the DEC CX instruction with a JNZ (Jump if Not Zero) instruction JNZ tests the Zero flag ZF and jumps back to the STOSW instruction until ZF becomes true And ZF becomes true when a DEC instruction causes its operand (here, CX) to become 0
Painting QR Code JIS X 0510 In Visual Studio .NET
Using Barcode encoder for .NET Control to generate, create QR image in Visual Studio .NET applications.
The LOOP Instructions
QR Code Scanner In Visual Studio .NET
Using Barcode decoder for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
With all that in mind, consider the following assembly language instruction loop Note that I've split it into three parts by inserting blank lines: DoChar: stosw add aaa add mov dec jnz AL,'1' AL,'0' AH,07 CX DoChar ; Note that there's no REP prefix! ; ; ; ; Bump the character value in AL up by 1 Adjust AX to make this a BCD addition Basically, put binary 3 in AL's high nybble Make sure our attribute is still 7
Bar Code Creation In Visual Studio .NET
Using Barcode drawer for .NET framework Control to generate, create bar code image in VS .NET applications.
; Decrement the count by 1 ; and loop again if CX > 0
Decoding Barcode In VS .NET
Using Barcode reader for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
Ignore the block of instructions in the middle for the time being What it does is what I suggested could be done a little earlier: change AX inbetween each store of AX into memory I'll explain in detail shortly
QR Code ISO/IEC18004 Creation In C#
Using Barcode generator for .NET framework Control to generate, create QR Code JIS X 0510 image in Visual Studio .NET applications.
Look instead (for now) to see how the loop runs STOSW fires, AX is modified, and then CX is decremented The JNZ instruction tests to see if the DEC instruction has forced CX to zero If so, the Zero flag ZF is set, and the loop will terminate But until ZF is set, the jump is made to the label DoChar, where STOSW fires yet again There is a simpler way, using an instruction I haven't discussed until now: LOOP The LOOP instruction combines the decrementing of CX with a test and jump based on ZF It looks like this: DoChar: stosw add aaa add mov loop AL,'1' AL,'0' AH,07 DoChar ; Note that there's no REP prefix! ; ; ; ; Bump the character value in AL up by 1 Adjust AX to make this a BCD addition Basically, put binary 3 in AL's high nybble Make sure our attribute is still 7
Painting QR Code In Visual Studio .NET
Using Barcode creation for ASP.NET Control to generate, create QR Code 2d barcode image in ASP.NET applications.
; Go back & do another char until CX goes to 0
QR Code Maker In VB.NET
Using Barcode drawer for .NET framework Control to generate, create QR image in Visual Studio .NET applications.
The LOOP instruction first decrements CX by 1 It then checks the Zero flag to see if the decrement operation forced CX to zero If so, it falls through to the next instruction If not (that is, if ZF remains 0, indicating that CX was still greater than 0), LOOP branches to the label specified as its operand So, the loop keeps looping the LOOP until CX counts down to 0 At that point, the loop is finished, and execution falls through and continues with the next instruction following the loop
Code 3/9 Maker In .NET Framework
Using Barcode drawer for Visual Studio .NET Control to generate, create Code 3/9 image in VS .NET applications.
Displaying a Ruler on the Screen
Generating ECC200 In Visual Studio .NET
Using Barcode maker for .NET framework Control to generate, create DataMatrix image in Visual Studio .NET applications.
As a useful demonstration of when it makes sense to use STOSW without REP (but with LOOP) let me offer you another item for your video toolkit The Ruler macro which follows displays a repeating sequence of ascending digits from 1 at some selectable location on your screen In other words, you can display a string of digits like this at the top of a window: 123456789012345678901234567890123456789012345678901234567890 This might allow you to determine where in the horizontal dimension of the window a line begins or some character falls The macro allows you to specify how long the ruler is, in digits, and where on the screen it will be displayed A call to Ruler would look like this: Ruler VidOrigin,20,80,15,5 This invocation (assuming you had defined VidOrigin to be the address of the start of the video refresh buffer in your machine) places a 20-character long ruler at position 15,5 The "80" argument indicates to Ruler that your screen is 80 characters wide If you had a wider or narrower text screen, you would have to change the "80" to reflect the true width of your screen in text mode Don't just read the code inside Ruler! Load it up into a copy of EAT5ASM, and display some rulers on the screen You don't learn half as much by just reading assembly code as you do by loading and using it! ;--------------------------------------------------------------; RULER -- Displays a "1234567890"-style ruler on-screen ; Last update 9/16/99 ; ; Caller must pass: ; In VidAddress: The address of the start of the video buffer ; In Length: The length of the ruler to be displayed ; In ScreenW: The width of the current screen (usually 80) ; In ScreenY: The line of the screen where the ruler is
GTIN - 12 Creation In Visual Studio .NET
Using Barcode creator for VS .NET Control to generate, create UPCA image in Visual Studio .NET applications.
; to be displayed (0-24) ; In ScreenX: The row of the screen where the ruler should ; start (0-79) ; Action: Displays an ASCII ruler at ScreenX,ScreenY ;--------------------------------------------------------------%macro Ruler 5 ;VidAddress,Length,ScreenW,ScreenX,ScreenY les DI,[%1] ; Load video address to ES:DI mov AL,%5 ; Move Y position to AL mov AH,%3 ; Move screen width to AH imul AH ; Do 8-bit multiply AL*AH to AX add DI,AX ; Add Y offset into vidbuff to DI add DI,%4 ; Add X offset into vidbuf to DI shl DI,1 ; Multiply by two for final address mov CX,%2 ; CX monitors the ruler length mov AH,07 ; Attribute 7 is "normal" text mov AL,'1' ; Start with digit "1" %%DoChar: stosw add aaa add mov loop %endmacro AL,'1' ; ; ; AL,'0' ; AH,07 ; %%DoChar ; Note that there's no REP prefix! Bump the character value in AL up by 1 Adjust AX to make this a BCD addition Basically, put binary 3 in AL's high nybble Make sure our attribute is still 7 Go back & do another char until BL goes to 0
Draw MSI Plessey In VS .NET
Using Barcode maker for Visual Studio .NET Control to generate, create MSI Plessey image in VS .NET applications.
Over and above the LOOP instruction, there's a fair amount of new assembly technology at work here that could stand explaining Let's detour from the string instructions for a bit and take a closer look
EAN 128 Encoder In VS .NET
Using Barcode creator for ASP.NET Control to generate, create GS1-128 image in ASP.NET applications.
EAN-13 Scanner In Visual Studio .NET
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
Painting Barcode In .NET
Using Barcode generation for ASP.NET Control to generate, create bar code image in ASP.NET applications.
Generate Code 128A In Visual C#.NET
Using Barcode drawer for VS .NET Control to generate, create Code 128 Code Set C image in Visual Studio .NET applications.
Code 39 Extended Encoder In .NET
Using Barcode generation for ASP.NET Control to generate, create Code39 image in ASP.NET applications.