0

I'm new to masm32 programming, and I am having a hard time understanding how the flows works

.data
ask DB "Enter Input Here: ", 0


.data?
conversion DB 100 dup(?)



.code

start:

    Push Offset ask
    Call StdOut

    Push 100
    Push Offset conversion
    Call StdIn

    sub ecx, ecx

setCounter:
    lea ebx, conversion
    mov al, [ebx+ecx]
    .IF ebx != 0
        inc ecx
    .ELSE
        jmp conv
    .ENDIF

    jmp setCounter

strLen:
    dec ecx
    cmp ecx, 0
    je printOut
conv:
    cmp al, 97
    jge checkLimit
    cmp al, 65
    jge checkLimit
    cmp al, 0
    je terminate

toLow:
    add al, 32
    stosb
    jmp strLen

toHigh:
    sub al, 32
    stosb
    jmp strLen

checkLimit:
    cmp al, 91
    jl toLow
    cmp al, 123
    jl toHigh
    stosb
    jmp strLen

printOut:
    push offset conversion          
    call StdOut                 


terminate:

    invoke ExitProcess,0

end start

It is expected to have an output of
"SSss%$ 23@ssSS" from input
"ssSS%$ 23@SSss

4
  • I wrote an asm function that does this efficiently on a different Q&A: How to access a char array and change lower case letters to upper case, and vice versa. You only need to decide if it's alphabetic, and if so XOR with 32, regardless of whether it's upper or lower case. That allows the branching to be simpler. (See What is the idea behind ^= 32, that converts lowercase letters to upper and vice versa?) Commented Aug 23, 2019 at 1:51
  • 1
    Is there a question here? From a quick look, this code has some of the right constants and might work. If so, what kind of answer are you looking for? If not, then edit it to make a minimal reproducible example. Commented Aug 23, 2019 at 1:51
  • @PeterCordes the code doesn't work on me... after I enter an input, the program crashes. From what I think, my code has a problem on how I store the modified string. And I can't still identify what to be done. By the way thanks for the comment/help Commented Aug 23, 2019 at 2:16
  • Then edit your question to make it a minimal reproducible example, including what you see with a debugger: which instruction crashes, and what's in registers at the time. (vs. what you expected to be there). Commented Aug 23, 2019 at 2:21

1 Answer 1

1

after I enter an input, the program crashes


    sub ecx, ecx
  setCounter:
    lea ebx, conversion
    mov al, [ebx+ecx]
    .IF ebx != 0
        inc ecx
    .ELSE
        jmp conv
    .ENDIF
    jmp setCounter

This is an infinite loop!

The condition .IF ebx != 0 always evaluates to TRUE and thus the counter increments endlessly.

Sign up to request clarification or add additional context in comments.

Comments

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.