0

I'm trying to write a simple procedure which will assign a letter grade to a string variable based on a grade entered by the user which I've stored in a variable named "AGrade". I have written the statements like this:

     LGrade proc AGrade;dword ; 1 Parameter 
    .if (AGrade > -1) && (AGrade<60)
    mov letter, "F"
    .EndIf

     .if (AGrade > 66) && (AGrade<70) 
    mov letter, "D+" ;ERROR SHOWS HERE
    .Endif

letter is declared as letter byte " ", NULL

I get the error:

 error A2070: invalid instruction operands

I noticed that when i remove the second if statement entirely, I can build without a problem. So my guess is that I am nesting incorrectly. Is "else" required instead? If possible, can someone show me the correct way I'd nest these two statements? Thanks a lot!

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Google Z
  • 5
  • 3
  • @zx485 Thanks for the reply! Are you saying the "AGrade" Variable is conflicting with "letter" ? Sorry, I'm fairly new to this. I thought that having ".endif" between each would fix this issue – Google Z Nov 10 '19 at 23:19
  • The `.if` has nothing to do with your error, look at which line it's on. (And try making a more-minimal [mcve] by removing the other lines). `"D+"` isn't a single letter; presumably `letter` is a `db` variable or array, and `"D+"` has multiple characters. MASM is weird about multi-character constant; avoid it. – Peter Cordes Nov 10 '19 at 23:19
  • Hello @PeterCordes , I had initialized "letter" as "letter byte " ", NULL " – Google Z Nov 10 '19 at 23:21
  • @PeterCordes Thanks!!!! would it work the way I had it if I initialized "letter" as word instead of byte? – Google Z Nov 10 '19 at 23:39
  • Yes, I think `"D+"` has `word` size, but I don't know. It would be in the wrong order, though. – Peter Cordes Nov 10 '19 at 23:42

1 Answers1

0

The .if has nothing to do with your error, look at which line it's on.

"D+" isn't a single byte, but your letter is a byte array which MASM magically associates with byte operand-size.

Your probably need mov word ptr letter, "+D" to match the operand-size for your 2-byte store.

See When using the MOV mnemonic to load/copy a string to a memory register in MASM, are the characters stored in reverse order? MASM is weird about multi-character constants so you need to reverse them in the source vs. the order you want stored into memory. (Unlike nice assemblers such as NASM, MASM reversed the bytes from the source when putting them into an immediate constant.)

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847