News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Coloring in ASM!!!!! XD

Started by StatusQuo, May 19, 2011, 08:10:00 PM

Previous topic - Next topic

StatusQuo

Hello all, I am fairly new to this forum and towards the Assembly Language. I have learned much about Assembly, at least enough to surpass the noob level a bit, now I have an issue with this one program that I am writing. My professor asks me to create a program, using .WHILE, to print Random numbers from 1 to 59, and only print numbers for 1-39 being selected, and having only 6 numbers to be printed. So far I have no trouble with this at all until he asks of me that the first five numbers should be in white while the very last number should be printed in RED. I have tried this in various ways and no matter what way I do it, it comes out to be the opposite, where the first number is in white and the other five are in red. I figured this would be a good place to ask such a question, and I was wondering if anyone can give me a pointer here or there. Perhaps someone else has a better eye than I have lol.

Here is part of my program.

-------------------------------------------------------------------------------------------------------------------------------------------------------
R DWORD ?
T DWORD ?
different DWORD ?

.CODE
MAIN PROC
   Call Randomize
   mov R,1
   mov T,59
   mov ebx, 1
.WHILE ebx <= 6
      mov eax, 39
      call RandomRange
      add eax,1
      call writeint
      mov al, " "
      call writechar
      inc ebx
   mov eax, red + (black* 16)
   call SetTextColor

Slugsnack


StatusQuo

Ive tried that too earlier, still didnt fix my problem. The thing is I know theres a method for it to be colored in a specific area, in this case its 6th position, or the 5th rather if it goes 0,1,2,3...etc, yet I am still having trouble. But thank you for the idea...

vanjast

Your request is ambigious, random ranges seem wrong..etc... Sorry you failed this one.

With Assembler.. You have to be VERY EXPLICIT in what you do, require... otherwise you'll have endless problems.
This requires a ordered and structured mind/thought process

Try rewrite your requirements
:wink

mineiro

You are probably using irvine, these calls are from their library.

.while
;some code
.endw      ;this statement mark the end of while loop, you need find one way to put this in your program,
               ;but pay atention about where you put this, because your are using a counter (ebx).

You say that you need print only first 5 numbers in one color, so try to change the .while ebx <=6 to 5. Well, generaly, we use the ecx (counter) register to store some counts, but you can do it by your own way.
eax = acumulator, ebx = base, ecx = counter, edx = data.
After your program showed the 5 numbers in one color, rest only one, this will be easy, some simply copy and paste of your own code typed before at the end of program and the victory is near.

StatusQuo

Thank you for the suggestion, by default I had the ebx<=5 in my first test run of the program, unforuntely I am getting mixed signals with the professors intsruction. Where as, he wanted the first five to be in white (default) and the last number to be printed in red. So instead i changed it from 5 to 6 so I could go with his instructions of having five numbers in white and the last in red. I was playing around with ebx, eax, and etc. Yet I continue to have the same. Unofortuntely this vag professor REQUIRES me to use random ranges and Randomize, although I can do it without one of them, or neither through other methods  i have been reading on, I know he would bury me with little things so....At the moment im just, hush hush and do what your told without a little freestyling :'(

qWord

include masm32rt.inc
.686p
.code
main proc
LOCAL range:DWORD
LOCAL hStdOut:HANDLE
LOCAL tmp:REAL4

mov hStdOut,rv(GetStdHandle,STD_OUTPUT_HANDLE)

print "specifie number range",13,10
mov esi,a2ud(input("upper limit: "))
mov esi,[esi]
mov edi,a2ud(input("lower limit: "))
mov edi,[edi]
mov ebx,a2ud(input("requested numbers: "))
mov ebx,[ebx]

mov range,esi
sub range,edi

xor esi,esi
.while esi < ebx

rdtsc
and eax,01111111y ; 0 ... 2^7-1
mov tmp,eax
fild tmp
fdiv FP4(127.0)
fimul range
fistp DWORD ptr tmp
mov edx,tmp
add edx,edi
push edx
mov eax,ebx
sub eax,1
.if esi < eax
invoke SetConsoleTextAttribute,hStdOut,FOREGROUND_GREEN or BACKGROUND_RED or BACKGROUND_GREEN or BACKGROUND_BLUE
.else
invoke SetConsoleTextAttribute,hStdOut,FOREGROUND_RED or BACKGROUND_GREEN
.endif
pop edx
print str$(edx),13,10
inc esi
.endw
; set white
invoke SetConsoleTextAttribute,hStdOut,FOREGROUND_RED or FOREGROUND_GREEN or FOREGROUND_BLUE

inkey
ret

main endp
end main
FPU in a trice: SmplMath
It's that simple!

Neil

Here is a proc that changes the colour of a character cell after it has been displayed on screen.

SetCellColor proc fore:DWORD,back:DWORD,x:DWORD,y:DWORD,n:DWORD

    LOCAL noc    :DWORD
    LOCAL coord  :DWORD

    mov edx,back            ;get background colour
    shl edx,4                  ;mov it into bits 4 to 7
    or  edx,fore              ;foregound colour in Lo 4 bits
    mov ecx,x                ;get column
    mov eax,y               ;get row
    shl eax,16               ;mov into Hi 16 bits (row)
    mov ax,cx               ;mov into Lo 16 bits (column)
    mov coord,eax         ;prime coordinate
    mov ecx,n               ;number of character cells
   
    invoke FillConsoleOutputAttribute,hConsoleOutput,edx,ecx,coord,ADDR noc
    ret

SetCellColor endp

Use it like this :-

invoke SetCellColor,14,0,10,6,3

This changes 3 character cells to yellow text on a black background starting at column 10 row 6

You can use the loc macro to set the cursor start position.




brethren

you haven't posted the full code listing so i can't be sure, but from the snippet you've posted the first number would be printed in white and after that every number will be printed in red.

if what you need is the 6th number to be red and all other numbers to be white you need to code it into your program. i'll show you what i mean with a bit of pseudo code
R DWORD ?
T DWORD ?
different DWORD ?

.CODE
MAIN PROC
   Call Randomize
   mov R,1
   mov T,59
   mov ebx, 1
.WHILE ebx <= 6

if ebx is equal to 6

   mov eax, red + (black* 16)
   call SetTextColor

else

    set text colour to white

endif


      mov eax, 39
      call RandomRange
      add eax,1
      call writeint
      mov al, " "
      call writechar
      inc ebx




StatusQuo

#9
Thank You brethren & Neil, I had a much better idea and it does work like a charm, now out of my own personal projection. Suppose I wish to print the entire list of 1 to 59, but this time backwards, with the last one in red. I think I have an idea to attempt this. This time no Rrandom Calls, and I suppose I could try something like,

.data
space byte " ",0
R dword 59


.code 
   main PROC
   
call clrscr

mov eax,59
.while eax>0
   call writeint
    mov edx,offset space
    call writestring
   dec eax
           
.endw 
main endp
exit

END main

From ther4e I just have to paint the last one in red.

StatusQuo

Quote from: brethren on May 20, 2011, 03:04:06 PM
you haven't posted the full code listing so i can't be sure, but from the snippet you've posted the first number would be printed in white and after that every number will be printed in red.

if what you need is the 6th number to be red and all other numbers to be white you need to code it into your program. i'll show you what i mean with a bit of pseudo code




By The way bro,I tried to punch this in, appearently, it isnt working.