Search code examples
assemblymasmirvine32

MASM615 and switching the address of two strings


I am trying to write a MASM615 assembly program where part of the program switches the address of two strings if needed. However, I have no idea how to do this. Basically, I need to pass the two string pointers into a new procedure by reference, and the procedure switches the addresses.

Thus far I have:

lea eax, str1
lea ebx, str2
push ebx
push eax
call compare

So you see, the addresses are pushed into stack. In the procedure I pop them off of stack into the same registers (seems a little pointless, but oh well)... and then what? I feel like I need to somehow tell str1 to point to the address in ebx, and str2 to point to the address in eax, but how?!

Edit: Current test code....

TITLE MASM Template                        (main.asm)

INCLUDE Irvine32.inc

.data
str1 db "Hello",0
str2 db "Hi there",0

.data?
pStr1 dd ?
pStr2 dd ?

.code
main PROC
mov [pStr1],OFFSET str1
mov [pStr2],OFFSET str2

mov edx, [pStr1]
call WriteString
main ENDP

END main

Solution

  • It seems like you want something like this:

    .data
    str1 db "Hello",0
    str2 db "Hi there",0
    
    .data?
    pStr dd ?
    
    .code
    mov [pStr],OFFSET str1
    ...
    ; if some condition is fulfilled, jump past this:
    mov [pStr],OFFSET str2
    ...
    mov edx,[pStr]
    call WriteString