Search code examples
c++assembly32-bitmasm

How to increment letters of pointer in assembler?


I have procedure in assembler and i want to add to each letter of String strV, which is byte pointer some value, in this case it will be +3. I try to add 3 only for first letter, but proc returns weird sign or nothing, so I asks for help. (Returned pointer will be assigned to char * string in C++).

start proc strV: PTR BYTE
    mov eax, [strV]
    ret
start endp

Solution

  • You want to add 3 to each letter of a string ?

    The following code is not tested, but it should work. Assuming that your string is a NUL-terminated string, of course.

    I'm simply checking to see if we're at the end of the string, if we're not it adds 3 and keeps going.

    start proc strV: PTR BYTE
        mov eax, strV
    next:
        cmp byte ptr [eax], 0
        je done
        add byte ptr [eax], 3
        inc eax
        jmp next
    done:
        ret
    start endp