News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

A quick one!

Started by LordAdef, April 22, 2018, 02:23:36 PM

Previous topic - Next topic

LordAdef

guys,

There is dd, etc...
whats the equivalent for sdword?

Lonewolff

I'd say it would be a DW as they both take up 4 bytes.

hutch--

A pseudo HLL notation for a DWORD that is evaluated as signed. Assemblers have a 32 bit hole that you plonk data into, how you evaluate it makes it signed or unsigned.

LordAdef

Oh, I see. It's clear they use the same space and so on, but what would be the reason to declare it as sdword?

Because I've been declaring sdword variables as sdword.

foo struct
    aaa     dd  ?
    bbb     sdword ?
foo ends

well, at least it helps organizing the code design

Lonewolff

I'd just declare it as a 'dw'.

I pretty much declare anything going by the space it takes. As Hutch said, it doesn't really matter, it's just 'space'.

LordAdef

Quote from: Lonewolff on April 22, 2018, 02:49:04 PM
I'd just declare it as a 'dw'.

I pretty much declare anything going by the space it takes. As Hutch said, it doesn't really matter, it's just 'space'.

Hmm, I think I'll stick to sdword. It's the same space but it makes it clearer in the design, mainly for cmps, which must be dealt accordingly

hutch--

Wolf,

A DW data size is 16 bit, it needs to be DD for 32 bit. What Alex is using is using a form of strong typing to equate the DWORD to an SDWORD which is simply a HLL notation for a signed 32 bit value.

Lonewolff

Ah, I always get the notation mixed up. I keep forgetting the first 'd' is declaration. I mixed up dw as meaning double word.  :icon_rolleyes:

As you saw in my first reply, I said 4 bytes (32 bit).

jj2007

include \masm32\include\masm32rt.inc

.data
MyDW dd -100
MySDW SDWORD -100

.code
start:
  .if MyDW<0
print "MyDW is below zero", 13, 10
  .else
print "MyDW is NOT below zero", 13, 10
  .endif
  .if MySDW<0
print "MySDW is below zero", 13, 10
  .else
print "MySDW is NOT below zero", 13, 10
  .endif
  inkey chr$(13, 10, "clear enough?")
  exit

end start

LordAdef

Hutch & cia,

One last question, please... I've already spent some time trying to figure it out


mov ecx, offset man
mov eax, TYPE man

.IF eax ==  Player                    <== man is a Player struct
con "yep, it's right Alex"
.ENDIF

assume ecx: ptr Player ;<== Player is hard coded, I'd like to get the TYPE of man
con "%d  %d",  [ecx].x, [ecx].y
assume ecx:nothing


In the above code, assume ecx: ptr ...  Player is hard coded. I'd like to get the struct of man in there,  but "assume    ecx: ptr eax" obviously doesn't work.

how can I do this?

LordAdef

Quote from: jj2007 on April 22, 2018, 05:08:08 PM
include \masm32\include\masm32rt.inc

.data
MyDW dd -100
MySDW SDWORD -100

.code
start:
  .if MyDW<0
print "MyDW is below zero", 13, 10
  .else
print "MyDW is NOT below zero", 13, 10
  .endif
  .if MySDW<0
print "MySDW is below zero", 13, 10
  .else
print "MySDW is NOT below zero", 13, 10
  .endif
  inkey chr$(13, 10, "clear enough?")
  exit

end start


Yep.
any great macro/EQU/MAGIC/etc I could substitute sdword for something like  foo sdw ? (it's for aesthetical purposes really!)

jj2007

sdw equ <SDWORD>
MySDW   sdw -100

Not that I advocate that, though. I rarely need SDWORD, but if I need one, I want it to stand out of the crowd:
MbArrayPlot proc arrID, arrTypeAndFlags, apMargins, DotCol, DotSize, xStart, xEnd1 ; 31.3.18, 1990 bytes; testbed
LOCAL oldBrush, oldPen, arrSize, xEnd, mrgLeft, mrgTop, ebxSave, ctRegions, curRegion:SDWORD
LOCAL yRange:REAL4, yMin:REAL4, xRange:REAL4, xMin:REAL4 ; order is important for movups; point count is xEnd-xStart
LOCAL apW, apH, m2xInit, minorX, minorY, ptY, ptX:SDWORD, curY:REAL4, valymax:REAL4, fct:REAL4, LenYval ; , ptCt
LOCAL ctPolyAll, ctPolySub, pAllXY, pHandles, pColours
LOCAL pSubPolyStart, ctVertex, pVertexCounts[1600]:DWORD ; 1. tmp position for closing sub-vertex, 2. array of integers
  ClearLocals

How many milliseconds does it take to see that there are two SDWORDs?  ;)

P.S.:
.IF eax ==  Player                    <== man is a Player struct
con "yep, it's right Alex"
.ENDIF


That may work but it's dangerous because eax just carries the size of Player. It would say yep for any other structure that happens to have that size. Masm and its clones have a possibility to check the type, but it's done in macros. For illustration here an excerpt of the ChkNum macro; note that it delivers different values for DWORD and REAL4 (tmp$ is the name of a variable):
; decide: push the arg itself, or a pointer to the arg?
  if (type(tmp$) eq DWORD) or (type(tmp$) eq SDWORD)
  NumSize = MbDword
  elseif (type(tmp$) eq WORD) or (type(tmp$) eq SWORD)  ;; needs wp flag
  NumSize = MbDword
  aPass$ CATSTR <wp:>, arg
  elseif type(tmp$) eq BYTE ;; byte: needs bp flag
  NumSize = MbDword
  aPass$ CATSTR <bp:>, arg
  elseif type(tmp$) eq REAL4 ;; dword or real4: direct push
  NumSize = MbReal4
  elseif type(tmp$) eq REAL8
  NumSize = MbReal8
aPass$ equ <pupo> ;; others: push a pointer to the var
  elseif type(tmp$) eq REAL10
  NumSize = MbReal10
aPass$ equ <pupo>
  elseif type(tmp$) eq QWORD
  % echo x=<argX>
  NumSize = MbQword
aPass$ equ <pupo>
  else
  % echo unknown type: tmp$
  .err
endif
EXITM %NumSize

LordAdef

Cheers JJ, well... it's a bit of fun

ps: I missed your whole explanation and only saw it now! Thanks once again JJ. I'll have a look

hutch--

If you want something that looks like strong typing,

  LONG equ <DWORD>

Its probably already in the include file but I have not looked.  :P

LordAdef

Quote from: hutch-- on April 22, 2018, 06:24:27 PM
If you want something that looks like strong typing,

  LONG equ <DWORD>

Its probably already in the include file but I have not looked.  :P

Not really! It was just a cosmetic thing in my structure declaration, sdword is fine really.

But one thing I am realizing in asm: every time we ask something, we learn twice as much as one asked.