News:

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

Main Menu

Question about TYPEDEF in masm

Started by StillLearningMasm, April 13, 2019, 07:48:31 PM

Previous topic - Next topic

StillLearningMasm

To whom it may concern,

I read the documentation that came with my version of masm. It shows some examples for using TYPEDEF. After looking at the BNF Grammer that shows how masm sees the different instructions. I
created the following 2 instructions that assembled with no errors but I have found no examples on how to use them. Here are the 2 different examples that I am talking about:

label1 typedef ptr proc
label2 typedef proc

Does anybody have any examples on how to use them?
Thank you for your help.


jj2007

Welcome to the Forum :icon14:

I have no example ready, but you may find some stuff using the search function. Use e.g.  "typedef ptr proc" to find quite a number of threads. If that's not enough, try to search the old forum.

nidud

#2
deleted

StillLearningMasm

Thank you for your example jj2007 but the example I am looking for are using these instructions:

label1 typedef ptr proc
label2 typedef proc

I am looking for examples of using user defined proc. I have not found any.

StillLearningMasm

Do these statements create the same user defined type:

Label1 typedef
Label1 typedef ptr

I did not find and examples of using the first statement. Masm gave me no error for either one of the statements. I did find a example of using the second statement. Should the first statement be a error?

jj2007

No idea. It is difficult to understand out of context what you mean, and we rarely use these constructs, probably because there are better alternatives. Can you post a complete example showing where it chokes, and explaining what you really want to achieve?

aw27

All 6 variations are the same.
(Do you mean ?
label1 typedef PROTO
label2 typedef ptr label1)


.486

.model flat, stdcall

printf proto C :ptr, :vararg
ExitProcess proto :dword

label1 typedef ptr proc
label2 typedef proc

.data
msg db "Hello from called function",10,0

.code

myFunc proc
invoke printf, addr msg
ret
myFunc endp

main proc
mov esi, myFunc
call esi
call label1 ptr esi
call label2 ptr esi
lea esi, myFunc
call esi
call label1 ptr esi
call label2 ptr esi

push 0
call ExitProcess
main endp

end


Output:

Hello from called function
Hello from called function
Hello from called function
Hello from called function
Hello from called function
Hello from called function

hutch--

 :biggrin:

Be careful of what you wish for, you can provide sheer confusion and get nothing out of it.

TYPEDEF MADNESS

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

    include \masm32\include64\masm64rt.inc

    WOTTA_LOTTA_ROT typedef PTR
    INT_UNKNOWN_SIZE_AND_NAME_BOVINE_EXCREMENT typedef PTR WOTTA_LOTTA_ROT
    YETTA_NUTHA_MINDLESS_TYPEDEF_NAME typedef PTR INT_UNKNOWN_SIZE_AND_NAME_BOVINE_EXCREMENT
    WTF_IS_THIS_PILE_OF_CRAP typedef YETTA_NUTHA_MINDLESS_TYPEDEF_NAME
    UNKNOWABLE_TYPE typedef PTR WTF_IS_THIS_PILE_OF_CRAP

    .code

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

entry_point proc

  ; bsvar# = bullsh*t variable

    LOCAL bsvar1 :UNKNOWABLE_TYPE

    % echo +++++++++++++++++++++++++++++++++
    % echo UNKNOWABLE_TYPE = varsize(UNKNOWABLE_TYPE) bytes
    % echo +++++++++++++++++++++++++++++++++

    mov rax, 12345678
    mov bsvar1, rax
    conout str$(rax),lf

    waitkey

    invoke ExitProcess,0

    ret

entry_point endp

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

    end


StillLearningMasm

Thank you AW. That was exactly what I was looking for.

Do these instruction create the same code?

Label1 typedef
Label1 typedef ptr

According to the listing file if I create code and name them as this:

Label1 typedef
Label2 typedef ptr

Then the listing file shows the attr for Label2 as ptr but shows blank for Label1.
Are they two different types? Is Label2 a pointer type? I think it is.
But I have no idea what type is Label1.

Still trying to understand TYPEDEF.

I love the example from hutch--.  :lol:

hutch--

Have a look at a couple of basic things, there is no difference in 32 bit between a normal DWORD variable and a pointer. In 32 bit ALL pointers are the native data size, 4 bytes in length. The only factor that a processor understands is the data SIZE, not its name. While TYPEDEF statements are usable for renaming data sizes and their use, it comes at the price that you no longer know how BIG the data is and this is an endless source of data size errors.

If you start off the bottom, size based data you are free of the confusion and with practice you will get to remember things like BYTE PTR which is the ADDRESS of a BYTE in memory. A BYTE PTR is standard Intel notation in x86 and while you can TYPEDEF it to things like PCHAR and the like, you gain nothing from doing it and you lose the reference to how BIG the data is.

StillLearningMasm

Thank you for the explanation Hutch--.

So for the examples I was originally talking about:

Label1 typedef
Label2 typedef ptr

Label1 is not a pointer and has no defined size. Shouldn't this be an error when creating it? Masm gives no error unless I attempt to make it local in a proc:

local pmystr1:Label1
c:\masm32\bin\assembly2.asm(152) : error A2195: parameter or local cannot have void type.

Label2 is a pointer it does not need a defined size.

Am I understanding this correctly?




hutch--

Pretty close to it.

error A2195: parameter or local cannot have void type.

This is the same as in a high level language,

variable =

Its an error if you don't have something to assign to the variable.

You have data types and depending on the OS version, in 32 bit, a PTR is 32 bit, in Win64 a pointer = QWORD (8bytes).

Know the OS version and you know the native data size for a pointer. You have the rest of the integer data sizes,

BYTE
WORD
DWORD
QWORD

There are larger 128 and 256 data types but you won't need them yet.

aw27

Destroying Masm small brain, aka Buffer Overflow  :bgrin:


.486

.model flat, stdcall

ExitProcess proto :dword

label1 typedef ptr CRAP

.data
msg  db 'Blowing MASM',10,0
crap label1 1000000

.code

main proc
invoke Exitprocess, 0
main endp

end


Microsoft (R) Macro Assembler Version 14.20.27508.1
Copyright (C) Microsoft Corporation.  All rights reserved.

Assembling: testB.asm

MASM : fatal error A1016: Internal error

  Version 14.20.27508.1

  ExceptionCode            = C0000005
  ExceptionFlags           = 00000000
  ExceptionAddress         = 0089F3E7 (00870000) "H:\masm32\bin\ml.exe"
  NumberParameters         = 00000002
  ExceptionInformation[ 0] = 00000000
  ExceptionInformation[ 1] = 00008408

CONTEXT:
  Eax    = 00000000  Esp    = 010FF340
  Ebx    = 00000001  Ebp    = 010FF344
  Ecx    = 00008400  Esi    = 00000000
  Edx    = 00000000  Edi    = 00008400
  Eip    = 0089F3E7  EFlags = 00010202
  SegCs  = 00000023  SegDs  = 0000002B
  SegSs  = 0000002B  SegEs  = 0000002B
  SegFs  = 00000053  SegGs  = 0000002B
  Dr0    = 00000000  Dr3    = 00000000
  Dr1    = 00000000  Dr6    = 00000000
  Dr2    = 00000000  Dr7    = 00000000

HSE

Quote from: AW on April 17, 2019, 02:00:36 AM
Destroying Masm small brain, aka Buffer Overflow  :bgrin:

Just a bug in ML14


X:\masm32\test>ml crap.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: crap.asm
crap.asm(11) : error A2004: symbol type conflict : CRAP
crap.asm(11) : fatal error A1016: Internal Assembler Error
Equations in Assembly: SmplMath