Coding and testing the procedure out_a_nibble

In this post, I will write about how I made the code of out_a_nibble in DEBUG.EXE and how to use shift and rotate instructions for bit manipulation in x86 assembly language. But before start writing about this procedure I want to clarify one point that concerns the pictures used to illustrate the steps done inside DEBUG. The point is that I wasn't happy with some of the screenshots and I preferred to take some of them again from a slightly different perspective that I found was better suited for the explanations. Consequently, the snapshots are taken in two different points in time: in one case, once DEBUG was loaded in memory, it assigned CS = DS = ES = SS = 0x1523 (Fig. A and Fig. B) in the other case it assigned CS = DS = ES = SS = 0x1521 ( Fig. C and Fig. D). It doesn't change that much in the practice but I wanted to make the point clear right at the beginning because some of you may notice the difference and wonder whether or not the change in the segment was done intentionally by me or what was the cause for it.

In Fig. A you see that I placed the CALL at 0x0100 and the code at 0x0110. After that, I adjusted the registers to get ready for testing.

Best practice with DEBUG.EXE
Fig. A

In Fig. B, I stepped through the code using the t command and I positively tested that when CX = 0x0004 the most significant nibble of BX is selected and stored in the least significant nibble of AX.

Best practice with DEBUG.EXE
Fig. B

In Fig. C , I tested the index selection with CX = 0x0002 and CX = 0x0003, but this time using the command p to execute the procedure completely and looking at the result immediately. I have marked in yellow and blue first the nibble in BX corresponding to the index in CX and then I called the function checking that the selected nibble ends in the low nibble of AX.

Best practice with DEBUG.EXE
Fig. C

After positive coding and testing of the procedure, I piled it up on the rest of the code in Fig. D.

Best practice with DEBUG.EXE
Fig. D

Comments