0

I am new to MASM coding. I found that it is really difficult to handle with registers, due to lack of knowledge in built-in functions.

I am trying to write a program to change all letters in input string to CAPITAL letters. Here is my code:

.386
.model flat, stdcall
option casemap:none
include windows.inc
include kernel32.inc
include msvcrt.inc
includelib msvcrt.lib

.data
InputMsg db "String Input: (At most 20 characters)", 10, 0
OutputMsg db "Your string is ", 0
StringFormat db "%s", 0

.data?
StringData db 20 dup(?)

.code
start:
    invoke crt_printf, addr InputMsg
    invoke crt_scanf, addr StringFormat, addr StringData, 20

    ;Change lowercase letter to uppercase
    lea ecx, StringData
    CounterLoop:
        .if [ecx] >= 97
            .if [ecx] <= 122
                sub [ecx], 32
            .endif
        .endif

        inc ecx
        .if [ecx] != 0
            jmp CounterLoop
        .endif

    invoke crt_printf, addr OutputMsg
    invoke crt_printf, addr StringData
    invoke ExitProcess, NULL
end start

I want to use ecx to store the effective address of StringData. However, A2070 error occured when I want to get the content of StringData.

Is [ecx] incorrect? How can I get the character in StringData using direct addressing? Thank you very much!

Brian Tsui
  • 21
  • 2
  • 4
    Possible duplicate of [Converting lowercase character string to uppercase masm](https://stackoverflow.com/questions/16503066/converting-lowercase-character-string-to-uppercase-masm) – WhatsThePoint Oct 06 '17 at 09:47
  • You don't say where the error is but I'm venturing to guess that MASM is complaining about the fact that it doesn't know the size of the data `[ecx]`represents. Appears you want to compare a byte at memory address ECX would be something like `byte ptr [ecx]`. you probably just have to replace all the `[ecx]` with `byte ptr [ecx]` – Michael Petch Oct 06 '17 at 10:10
  • Of course this isn't a duplicate as this is about the error _A2070 Invalid Instruction Operands_, not specifically about the character conversion and a followup question about direct addressing. There are other A2070 SO questions though. – Michael Petch Oct 06 '17 at 12:16
  • 1
    Thanks for your help, Michael! It works with `byte ptr [ecx]`. I should point out that my error was at lines related to `[ecx]`. Anyway, thank you! – Brian Tsui Oct 09 '17 at 05:53

0 Answers0