The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: www.:).com on November 12, 2010, 07:17:27 PM

Title: Code Help ???Question???
Post by: www.:).com on November 12, 2010, 07:17:27 PM
I have some code that simply fills the screen(320 * 200 - 13h) starting at 6400 linear on the screen and fills the rest downward or to 64000. My problem is that the for some reason it doesn't fill at all, the only way i can get it to fill is if i put a number around 40000 or lower into cx, but then still it doesn't fill the whole way down just to the number in cx. Is there something wrong with my code?


    mov ah, 2    ; Set color to green - ah
    mov cx, 64000    ; move end location into cx
    mov di, 6400    ; move into di the start location

FillFrom:    ; setup loop
    mov es:[di], ah    ; set byte at point
    add di, 1    ; add 1 to di for one pixel farther in memory
    cmp di, cx    ; compare the values
    jl FillFrom    ; if di is still less than the end values continue to fill pixels - loop back to FillFrom

Title: Re: Code Help ???Question???
Post by: FORTRANS on November 12, 2010, 07:34:10 PM
Hi,

   The conditional jump JL (jump if less) is to test against signed
numbers.  Try JB (jump if below), which is for unsigned numbers.

HTH,

Steve N.

Title: Re: Code Help ???Question???
Post by: dedndave on November 12, 2010, 07:39:08 PM
Steve is right - 64000 is FA00h, a negative value in signed context

but, this will be a little faster   :bg
        mov     ax,0A000h
        mov     es,ax
        mov     di,6400               ;beginning line = 20
        mov     cx,28800              ;180 lines, 57600 bytes
        mov     ax,202h               ;AL = 2 and AH = 2
        cld                           ;direction = up
        rep     stosw
Title: Re: Code Help ???Question???
Post by: MichaelW on November 12, 2010, 08:00:16 PM
Since I already typed this up, I'll post it.

For conditional jumps, for the second character in the mnemonic, Above and Below specify unsigned comparisons, and Greater and Less specify signed comparisons.

The range for a 16-bit unsigned value is:
0 to 65535 in decimal
0 to FFFF in hex
0000000000000000 to 1111111111111111 in binary

The range for a 16-bit signed value is:
-32768 to 32767 in decimal
8000 to 7FFF in hex
1000000000000000 to 0111111111111111 in binary.

As unsigned values, 6400 is less than 64000, but as signed values, since 64000 (FA00h) is interpreted as negative, 6400 is greater than 64000, and your code sets one pixel, and the loop falls through.
Title: Re: Code Help ???Question???
Post by: www.:).com on November 12, 2010, 08:49:49 PM
ok, thanks it works now.