News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

MASM - Simple console Program

Started by jnrico, September 15, 2005, 02:05:43 AM

Previous topic - Next topic

jnrico

I have programmed in Java and C++ but I am a novice to assembler programming. For an unknown reason I got an error
when running the executable generated by this code. Any help you can provide will be appreciated.

main proc

    LOCAL str1:DWORD
    LOCAL dest:DWORD

    mov str1, input("Type in some text: ")
   
    mov esi, str1
    mov edi, dest

DoIt:
    mov al, [esi]
    inc esi
    mov [edi],al

    inc edi
    cmp al, 0
    jne DoIt
   
    print edi

    ret
   
main endp

end start

tenkey

The local variable "dest" is uniinitialized.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

roticv

Like what tenkey mentioned the stack you are copying too is well too small. You only declare src and dest to be a dword each and how do you expect to copy a string there?

AeroASM

Quote from: roticv on September 15, 2005, 05:57:44 AM
Like what tenkey mentioned the stack you are copying too is well too small. You only declare src and dest to be a dword each and how do you expect to copy a string there?

Actually he is storing string pointers there. Tenkey is right: the variable dest is not a valid pointer.

hutch--

jnrico,

To do what you are after with initialised strings, yu need to have it in the .DATA secion of the source file.


.data
  mystring "This is my string",0
  ....
.code
  ....

myproc proc

    LOCAL pString :DWORD

    mov pString, OFFSET mystring

  ; do what you need with te string address "pString"

    ret

myproc endp


MASM32 has a number of macros that make this stuff a lot more convenient but the pseudo code above is how its done manually.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Bieb

To have an adequate string buffer, you'll want to use the dup macro, and then you'll need to make a DWORD pointer to the memory buffer.  Here's an example.


.data?
Pointer dword ? ;Our DWORD pointer
.data
MyString db 256 dup(0) ;Our memory buffer
.code

start:
mov Pointer, offset MyString ;Move adress of buffer into pointer


It's been a little while since I've used MASM, though, so there might be something wrong with that code.  Good luck, anyhow.

P1

It would be nice to list the errors.

I see other errors in your code, but I don't know if you left it out from the post or from your code.

Regards,  P1  :8)

Bieb

Yeah, I didn't fill in a whole program.  It's just enough to show what he needs to do.