0

I am in an assembly language course and need to do the following:

  1. Write code that defines symbolic constants for all seven days of the week.
  2. Create an array variable that uses the symbols as initializers

Here is my code so far:

MON EQU <"Monday", 0>
TUE EQU <"Tuesday", 0>
WED EQU <"Wednesday", 0>
THU EQU <"Thursday", 0>
FRI EQU <"Friday", 0>
SAT EQU <"Saturday", 0>
SUN EQU <"Sunday", 0>

.data
    array BYTE MON,TUE,WED,THU,FRI,SAT,SUN

I found this post on StackOverflow that said:

Ok, there are a few ways to declare a string in MASM: First, you can declare the string in the data segment and use the variable throughout your code.

stringName BYTE "Hello, this is a string", 0

To declare a string constant you can use the EQU or TEXTEQU directive. Both are declared before the data segment in the global scope.

constantString EQU <"Hello, string content", 0>


I also found this post on StackOverflow that said the following:

An array of strings is not a continuous block of strings, it is a continuous block of pointers to strings. The strings can be anywhere.

arrayOfWords  DWORD  OFFSET strBicycle, 
                     OFFSET strCanoe,
                     OFFSET strSkateboard,
                     OFFSET strOffside,
                     OFFSET strTennis

strBicycle    BYTE "BICYCLE",0 
strCanoe      BYTE "CANOE", 0
strSkateboard BYTE "SKATEBOARD", 0 
strOffside    BYTE "OFFSIDE", 0
strTennis     BYTE "TENNIS", 0

I have tried writing the following code:

.data
    array DWORD OFFSET MON,
            OFFSET TUE,
            OFFSET WED,
            OFFSET THU,
            OFFSET FRI,
            OFFSET SAT,
            OFFSET SUN

but this code fails to build with the following error:

1>AddTwo.asm(24): error A2084: constant value too large

Have I created string symbolic constants and an array of strings correctly?

5
  • 1
    EQU declares a compile time constant, but does not declare any storage or data for runtime. Whereas OFFSET requires runtime data storage to refer to. So use the BYTE declaration as what you're showing above to get runtime data storage instead. Commented Feb 7 at 18:09
  • @ErikEidt Thank you for the information! I have another question, if the line of code MON BYTE "Monday",0 is inside of the .data directive, is MON a symbolic constant or just a normal string? Commented Feb 7 at 18:35
  • 2
    In that case MON is a symbol whose address is the start of the string, like you'd get from C char MON[] = "Monday";. MASM also magically associated the BYTE ... data with the symbol so you can do sizeof on it as an array variable, I think. (Other assemblers aren't like that.) To get its address into a register, mov edi, OFFSET MON. To load the first 4 bytes of ASCII characters, mov eax, dword ptr [MON]. To load the second byte, movzx eax, byte ptr [MON + 1]. Commented Feb 7 at 19:16
  • 2
    .data is a directive for which "section" the next lines goes into. There are sections for code, data: mutable (read/write) data, read-only data, etc.. (but the availability of some these depends on your programming model.) The label MON could have gone into any section and would be the same, a symbol that refers to an address that is constant at runtime. Commented Feb 7 at 19:47
  • @PeterCordes I find it interesting that the question doesn't actually say create symbolic string constants. Maybe just assign the days of the week with an ordinal position like SUN EQU 0 MON EQU 1 etc. ;-) Commented Feb 7 at 21:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.