Question

I have a programming assignment to run through and set the background and text of all the possible combinations. I am using a predefined function called SetTextColor which basically sets the values like this:

mov eax, white + (blue * 16)

Essentially this sets the text white and the background blue (to set the background you multiply by 16). Basically the combination is 16 X 16 = 256

TITLE BACKGROUND COLORS                     (main.asm)

; Description: T
; Author: Chad Peppers
; Revision date: June 21, 2012

INCLUDE Irvine32.inc
.data
COUNT = 16
COUNT2 = 16
LCOUNT DWORD ?

val1 DWORD 0
val2 DWORD 0
.code
main PROC

    mov ecx, COUNT

    L1:
        mov LCOUNT, ecx
        mov ecx, COUNT2
        L2:
            mov eax, val1 + (val2 * 16)
            call SetTextColor
            inc val2
            Loop L2
        mov ecx, LCOUNT
        Loop L1

    call DumpRegs
    exit
main ENDP

END main

Basically I am doing a nested loop. My thinking is that I simply do a 1 * (1 * 16) then inc the value in a nested loop until 1 * (16 * 16). I am getting the error below

I am getting the error A2026: constant expected

Was it helpful?

Solution

I imagine the error you are getting is at this line:

mov eax, val1 + (val2 * 16)

You just can't do that. If you intend to multiply val2 by 16 and then add val1 to the result, then you need to implement it step by step (you may come across addressing in the form of a+b*c but a and c need to be registers and b can only be 2, 4 or 8, not 16). Try replacing this line with something like this:

mov eax, val2
imul eax, 16
add aex, val1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top