The MASM Forum

General => The Workshop => Topic started by: pgw001 on March 11, 2014, 10:03:07 AM

Title: Passing Addresses
Post by: pgw001 on March 11, 2014, 10:03:07 AM
Folks,
After 12 hours of desperate measures, please help
I have a test environment where I call a main procedure which in turn invokes a procedure (wtor) passing the addresses of a console output message and a console input buffer
I have a PROTO statement in place to cover the invoke
When I execute -- invoke wtor, txtinput, txtmsg only the first char of the message (txtmsg) is output to the console
The first few lines of wtor are as follows:

wtor proc msgin:DWORD,msgout:DWORD

;   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;   <   Output text to console and read response
;   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

  invoke StdOut, addr msgout
  invoke StdIn, addr msgin, 100

Please excuse my ignorance but I can no longer see the wood for the trees..
Thanks for any guideance
Title: Re: Passing Addresses
Post by: dedndave on March 11, 2014, 11:22:13 AM
you pass addresses (pointers) to "wtor"
  invoke StdOut, addr msgout
  invoke StdIn, addr msgin, 100

so, you are passing pointers to pointers for these, when you want pointers
  invoke StdOut, msgout
  invoke StdIn, msgin, 100


i find the easiest way to read standard input is to use ReadConsole, as long as the string does not exceed 255 characters
it's easier to write a UNICODE aware program

see the attached program
notice that you can assemble the program as ANSI or UNICODE and it works either way
(to assemble as UNICODE, remove the comment semicolon on the UNICODE EQU 1 line)
Title: Re: Passing Addresses
Post by: pgw001 on March 11, 2014, 09:42:15 PM
Thanks for the suggestion, I feel that I have a basic lack of understanding in this area despite 10 years of programming in IBM 360 assembler (rather too long ago).
Removing the addr operands within the wtor procedure led to an access violation so I guess my problems are more fundamental. To avoid wasting more time could
I please trouble you to correct the following  code extracts at the heart of the problem, I can then work backwards to gain the understanding:

.DATA           ; Begin initialized data segment
   wtor PROTO :DWORD, :DWORD
   txtout db 'Input chars : ',0

main proc
      LOCAL txtinput:DWORD        ; a "handle" for the text returned by stdin"
      invoke wtor, txtinput, txtout

wtor proc msgin:DWORD,msgout:DWORD

      invoke StdOut, addr msgout    >>>>> only single char output in this form / access violation if addr removed
      invoke StdIn, addr msgin, 100

Thanks for your help
Title: Re: Passing Addresses
Post by: GoneFishing on March 12, 2014, 12:18:40 AM
Quote
;###############################################################################################

INCLUDE    \Masm32\Include\Masm32rt.inc

;###############################################################################################

.DATA                         ; Begin initialized data segment

   wtor PROTO :DWORD, :DWORD
   txtout db "Input chars : ",0

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

.CODE

  main  proc
 
       LOCAL txtinput[100]:BYTE          ;  a -- BUFFER -- for the text returned by stdin
 
        invoke wtor, addr txtinput, addr  txtout
       
        invoke StdOut, addr txtinput     ; show the txtinput
                                     
        ret
       
  main  endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

  wtor  proc msgin:DWORD,msgout:DWORD 
       
        invoke StdOut, msgout 
     
        invoke StdIn, msgin  , 100
       
        ret
         
  wtor endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

END main