Hadarsi320
Hadarsi320

Reputation: 393

What do the arguments mean for Int 10h, AH 6h/7h?

Kind of a dumb question, but nevertheless, can anyone explain to me what purpose do the registers cx and dx have in Int 10h with ah=6/7 (they both use the same variables just have scroll in different directions).

Everywhere I've looked it just says something similar to this:

CH = Upper row number, CL = Left column number, DH = Lower row number, DL = Right column number

This doesn't really mean a lot to me, can anyone explain this in a way someone dumb like me can understand?

Upvotes: 1

Views: 1929

Answers (2)

Margaret Bloom
Margaret Bloom

Reputation: 44076

Consider this eye-stabbing psychedelic picture of a red rectangular window painted in ol' text mode:

Rectangular red window

Each white-blue square represents a character cell. Cells are counter top-right and top-bottom. The numbers on the top, read downward, give a cell distance from the left edge1.
The numbers on the left give a cell distance from the top.

The pair (distance from left, distance from top), unique for each cell2, is called the coordinate pairs or simply the coordinates (or even the coords).
It's customary to call the distance from left as X and the distance from top as Y and everything related to width as something-X and everything related to height as something-Y.

The big red rectangle is a window3.
Windows have two dimensions and a position. So a window can be identified with a triple (position coord of top-left corner, size-X, size-Y).
For example the red window can be described as ((30, 8), 22, 7) since it starts at (30, 8), it's 22 cells wide and 7 cells tall.

Another way to describe a window is with the coords of the top-left corner and the coords of the bottom-right corner.
In this case the red window is ((30, 8), (51, 14)).


The service int 10h/AH=06h can be used to move the content inside the red window up.
We need to tell it where window to move is, and since it uses the second notation, so we do.

CL and CH form the pair holding the top-left coords, X in CL, Y in CH.
DL and DH form the pair holding the bottom-right coords, X in DL, Y in DH.

This code, loads the registers properly (both versions equivalent)

;Easy version             ;Normal version
mov cl, 30                mov cx, 081eh
mov ch, 8                 mov dx, 0e34h
mov dl, 52
mov dh, 14

The other inputs of the service routines are trivial, but for BH which for now we set to zero.
Lets call the service:

mov ax, 0603h      ;Scroll three lines up
xor bh, bh
mov cx, 081eh
mov dx, 0e34h
int 10h

The result is:

Window scrolled

We can see that the content inside the window has been scrolled up by three lines.
Nothing outside the window has been touched.

We also note that the lines "shifted" in from below are black lines.
This is where the input BH comes into play, it contains the attribute (combination of color and background color) used to draw those lines.

For example the attribute 0e0h specifies a bright yellow4, lets use it.

mov ax, 0603h      ;Scroll three lines up
mov bh, 0e0h       ;Yellow lines
mov cx, 081eh
mov dx, 0e34h
int 10h

Window scrolled up with yellow lines

Finally, the value of AL can be zero to scroll up the whole window, i.e. a number of lines equal to the height of the window.


For the service int 10h/AH=07h the rationale is the same but the window is scrolled down.


1 In cell units.
2 Note that the cells used to display the number have coordinates too.
3 Because it actually looks like a window.
4 Since we have the high intensity bit set in this context.

Upvotes: 10

Cody Gray
Cody Gray

Reputation: 244812

The 16-bit register CX can be divided into two 8-bit halves, which are referred to as CL and CH. CL is the lower 8 bits (think of the mnemonic as being CLow), while CH is the upper 8 bits (CHigh).
The same is true for the DX register: the lower 8 bits are in DL, and the upper 8 bits are in DH.

Indeed, all 4 of the x86's primary general-purpose registers—EAX, EDX, ECX, and EBX—have 8-bit and 16-bit overlapping aliases:

------------------------------------
|               EAX                |    (32 bits)
-----------------------------------
                 |       AX        |    (16 bits)
                 -------------------
                 |   AH   |   AL   |    (8 bits)
                 -------------------

So, the documentation for the int 10h function is telling you that the lower 8 bits of CX (CL) contains the left-most column of the window, while the upper 8 bits of CX (CH) contains the top-most row of the window. The lower 8 bits of DX (DL) contains the right-most column of the window, while the upper 8 bits of DX (DH) contains the bottom-most row of the window.

In other words, you are passing the function values that describe a rectangle in terms of its left, top, right, and bottom bounds. CX contains two 8-bit values that specify the window's top-left coordinate, while DX contains two 8-bit values that specify the window's bottom-right coordinate.

(When I say "window" here, I mean "rectangular area on the screen to be scrolled".)

Upvotes: 1

Related Questions