News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

My first program!

Started by felipe, April 26, 2017, 12:13:44 PM

Previous topic - Next topic

felipe

Quote from: jj2007 on April 27, 2017, 08:50:39 AM
You cannot reproduce the problem, I suppose?

No man, but i just have done another little program that creates a new file (with the CreateFile api function) and i did have the same problem: Assembly and linking correct, but windows coudn't run the program. Then i checked the code and i was omiting a ret instruction. I did correct that and it work.
In ms-dos this kind of problems would be funny, but here windows protects the system, wich it's funny too.  ;)... :lol:

mineiro

a basic abstration means that mov and lea and others processors instructions are instructions, not abstractions.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

newrobert

Quote from: LordAdef on April 27, 2017, 04:54:08 AM
both below will work. You may have missed something else

push_parameters proc       
        push    0                   ; Style of message box.

        ;mov    ebx,offset head    ;<== this
        lea      ebx, head               ;<== or this

        push    ebx

lea means move address of varible to register;

        ;mov    ebx,offset inside
        lea      ebx, inside

        push    ebx
        push    0                   ; No window, no handle?
        call    MessageBoxA         ; Windows function.
        ret
push_parameters endp

LordAdef

QuoteI did correct that and it work.

good to know!

hutch--

Here are the normal variations.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    ; *********************************
    ; *********************************
    ;   build with "Assembler & Link"
    ; *********************************
    ; *********************************

    .data
      titl db "Example",0
      doff db "Using the data OFFSET",0
      lead db "Loading the effective address",0
      tdat db "Using POINTERS to the data",0

    ; -------------------------------------
    ; DWORD pointers to the above text data
    ; -------------------------------------
      pttl dd titl
      poff dd doff
      padr dd lead
      pdat dd tdat

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    exit

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

main proc

  ; ----------------------------
  ; using the OFFSET of the data
  ; ----------------------------
    push MB_OK
    push OFFSET titl
    push OFFSET doff
    push 0
    call MessageBox

  ; -------------------------------------------
  ; load effective address with instruction LEA
  ; -------------------------------------------
    push MB_OK
    lea eax, titl
    push eax
    lea eax, lead
    push eax
    push 0
    call MessageBox

  ; --------------------------
  ; using POINTERS to the data
  ; --------------------------
    push MB_OK
    push pttl
    push pdat
    push 0
    call MessageBox

    ret

main endp

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

end start

LordAdef

Any reason why you are not "invoking" this MessageBox?

hutch--

Just to show felipe how its done manually.

LordAdef


felipe

Thanks a lot Hutch. So that 'p' is required for the 'pointers type'? And they should be always 32 bit long? (At least in 32 bit programming).

jj2007

Quote from: felipe on April 28, 2017, 05:27:32 AM
So that 'p' is required for the 'pointers type'?

You can use whatever you want, but search for hungarian notation. And yes, 32 bits wide.

hutch--

Hi felipe,

The names you use as variable are your own choice, what I have tried to do is use a consistent naming system so that you can understand what you write. A pointer is the address of data placed in a DWORD variable and in 32 bit Windows, it is always a 32 bit unsigned variable. In 64 bit it is always a 64 bit variable.

You can think of a pointer like this.

.DATA
  MyVariable dd 0
................
.CODE
................
    lea eax, someitem        ; get the address of whatever you need
    mov MyVariable, eax    ; write it to a variable so it is a POINTER to the data


felipe

Clear as water, thanks a lot! I was confused first, but now i realized that you assigned to the dwords variables the addresses of the other variables.  :t

jj2007

Here is another detailed example, copy & paste & build & run:include \masm32\include\masm32rt.inc

.data
MyByteArray BYTE "Byte array means an ANSI string", 0
MyPointer DWORD MyByteArray ; this dword variable points to the string

.data?
buffer db 100 dup(?) ; uninitialised, i.e. contains zeros

.code
start:
  mov eax, MyPointer ; two instructions that do the same: in both cases,
  mov esi, offset MyByteArray ; the register is now a pointer to the string
  .if eax==esi
print "eax==esi", 13, 10 ; this is what we suspected ;-)
  .else
print "eax<>esi", 13, 10 ; this would be rather surprising
  .endif
  mov edi, offset buffer ; edi contains a pointer to the buffer
  push edi ; keep a copy
  print esi, 13, 10 ; display the byte array
  mov ecx, sizeof MyByteArray-1 ; we use ecx as a counter
  .Repeat
lodsb ; load al from esi, increment esi by one
or al, 32 ; for you to find out ;-)
stosb ; store al to [edi], inc edi
dec ecx
  .Until Sign? ; stop when dec ecx sets the sign flag, i.e. ecx=-1
  pop edi ; get the copy back
  inkey edi ; and use it
  exit
end start


You may notice that the cursor blinks one byte after the string. Use Olly to find out why, and if you need homework, try to eliminate this little bug.

felipe

Quote from: jj2007 on April 28, 2017, 12:25:15 PM
Here is another detailed example, copy & paste & build & run:include \masm32\include\masm32rt.inc

.data
MyByteArray BYTE "Byte array means an ANSI string", 0
MyPointer DWORD MyByteArray ; this dword variable points to the string

.data?
buffer db 100 dup(?) ; uninitialised, i.e. contains zeros

.code
start:
  mov eax, MyPointer ; two instructions that do the same: in both cases,
  mov esi, offset MyByteArray ; the register is now a pointer to the string
  .if eax==esi
print "eax==esi", 13, 10 ; this is what we suspected ;-)
  .else
print "eax<>esi", 13, 10 ; this would be rather surprising
  .endif
  mov edi, offset buffer ; edi contains a pointer to the buffer
  push edi ; keep a copy
  print esi, 13, 10 ; display the byte array
  mov ecx, sizeof MyByteArray-1 ; we use ecx as a counter
  .Repeat
lodsb ; load al from esi, increment esi by one
or al, 32 ; for you to find out ;-)
stosb ; store al to [edi], inc edi
dec ecx
  .Until Sign? ; stop when dec ecx sets the sign flag, i.e. ecx=-1
  pop edi ; get the copy back
  inkey edi ; and use it
  exit
end start


You may notice that the cursor blinks one byte after the string. Use Olly to find out why, and if you need homework, try to eliminate this little bug.

Thanks.  :t
I haven't learned the use of olly yet, but i will do that soon as i can. I tryed to run the program, both in directly with the mouse and the console, but nothing happen (well, the program stay in running so i have to terminate the process with the task manager).
Now, i know why you did the or operation: It's for convert each letter in the string in an lowercase letter.