Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

my loop goes forever

it goes forever, just a few undoes before it was going until a halt but it started from the wrong place, so I thought this should be better although its endless haha. I need to display the 'X' char in all combinations of foreground and background color, I'm using the table:

black = 0
red = 4
gray = 8
lightRed = 12

blue = 1
magenta = 5
lightBlue = 9
lightMagneta = 13

green = 2
brown = 6
lightGreen = 10
yellow = 14

cyan = 3
lightGray = 7
lightCyan = 11
white = 15

and nested loops, the outer one is for background, the other one is for foreground, so it gets like 16 times 16

INCLUDE Irvine32.inc is where some of the function have already been defined , nobody told me how to do nested loops so I guess my ecx is value messing it all up. Plus I don't know how this SetTextColor really works, and even if I make it to an ended loop then most probably adding 16 wouldn't really change the background, I don't know. I'm real sloppy. Thank you for any ideas. Here's the code:


[code]INCLUDE Irvine32.inc

.data
str1 BYTE 'X',0dh,0ah,0
count DWORD ?


.code

main PROC
call clrscr
mov ecx, 16




mov ax,0
mov cx, 0*16
L1:
mov count, ecx

add ax,cx



mov ecx,count

L2:
call SetTextColor
mov edx,OFFSET str1

call WriteString

inc ax
loop L2

mov ecx, count
add cx,16
loop L1








main ENDP
END main[/code]

--------------------------------------------------------------------------------







Comments

  • shaolin007shaolin007 Member Posts: 1,018
    [b][red]This message was edited by shaolin007 at 2004-11-4 6:25:27[/red][/b][hr]
    [b][red]This message was edited by shaolin007 at 2004-11-3 14:48:38[/red][/b][hr]
    : it goes forever, just a few undoes before it was going until a halt but it started from the wrong place, so I thought this should be better although its endless haha. I need to display the 'X' char in all combinations of foreground and background color, I'm using the table:
    :
    : black = 0
    : red = 4
    : gray = 8
    : lightRed = 12
    :
    : blue = 1
    : magenta = 5
    : lightBlue = 9
    : lightMagneta = 13
    :
    : green = 2
    : brown = 6
    : lightGreen = 10
    : yellow = 14
    :
    : cyan = 3
    : lightGray = 7
    : lightCyan = 11
    : white = 15
    :
    : and nested loops, the outer one is for background, the other one is for foreground, so it gets like 16 times 16
    :
    : INCLUDE Irvine32.inc is where some of the function have already been defined , nobody told me how to do nested loops so I guess my ecx is value messing it all up. Plus I don't know how this SetTextColor really works, and even if I make it to an ended loop then most probably adding 16 wouldn't really change the background, I don't know. I'm real sloppy. Thank you for any ideas. Here's the code:
    :
    :
    : [code]INCLUDE Irvine32.inc
    :
    : .data
    : str1 BYTE 'X',0dh,0ah,0
    : count DWORD ?
    :
    :
    : .code
    :
    : main PROC
    : call clrscr
    : mov ecx, 16
    :
    :
    :
    :
    : mov ax,0
    : mov cx, 0*16
    : L1:
    : mov count, ecx
    :
    : add ax,cx
    :
    :
    :
    : mov ecx,count
    :
    : L2:
    : call SetTextColor
    : mov edx,OFFSET str1
    :
    : call WriteString
    :
    : inc ax
    : loop L2
    :
    : mov ecx, count
    : add cx,16
    : loop L1
    :
    :
    :
    :
    :
    :
    :
    :
    : main ENDP
    : END main[/code]
    :
    [green]
    When writing to video memory in text mode 3, ascii is represented by 2 bytes in memory. The 1st byte is the character you want and the 2nd is it's attribute blink/color ect.. So knowing this we can write a simple routine that can go through all the colors by incrementing the attribute byte for each write operation.
    [/green]

    [code]

    mov eax, 0b800h ;video memory for mode 3
    mov es, eax
    xor edi, edi ;start at screen location 0,0 upperleft corner
    mov eax, 1 ;start with dark blue
    cld ;set direction flag for incrementing edi

    Loop:
    cmp edi, [count] ;are we done?
    je Done
    mov byte al, [esi] ;Put 'X' into al
    stosw ;write to video memory 2 bytes and inc by 2
    inc ah ;go to next color
    jmp Loop

    Done:
    mov eax,0 ;wait for a key press
    int 16h

    mov eax, 4c00h ;terminate
    int 21h

    xmark byte 'X'
    [/code]




  • gorilkagorilka Member Posts: 90
    Isn't there any way to do it with nested loop yet?
  • shaolin007shaolin007 Member Posts: 1,018
    : Isn't there any way to do it with nested loop yet?
    :
    [green]
    Sure you can if you were looking to do something else besides the example I posted before. What are you trying to accomplish?
    [/green]

  • gorilkagorilka Member Posts: 90
    I fixed it :)

    Thanks for the help.
Sign In or Register to comment.