Author Topic: A quick one!  (Read 631 times)

LordAdef

  • Member
  • ****
  • Posts: 588
A quick one!
« on: April 22, 2018, 02:23:36 PM »
guys,

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

Ascended

  • Member
  • ***
  • Posts: 331
Re: A quick one!
« Reply #1 on: April 22, 2018, 02:28:24 PM »
I'd say it would be a DW as they both take up 4 bytes.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5634
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: A quick one!
« Reply #2 on: April 22, 2018, 02:28:29 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

LordAdef

  • Member
  • ****
  • Posts: 588
Re: A quick one!
« Reply #3 on: April 22, 2018, 02:32:30 PM »
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

Ascended

  • Member
  • ***
  • Posts: 331
Re: A quick one!
« Reply #4 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'.

LordAdef

  • Member
  • ****
  • Posts: 588
Re: A quick one!
« Reply #5 on: April 22, 2018, 03:09:53 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--

  • Administrator
  • Member
  • ******
  • Posts: 5634
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: A quick one!
« Reply #6 on: April 22, 2018, 03:27:01 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Ascended

  • Member
  • ***
  • Posts: 331
Re: A quick one!
« Reply #7 on: April 22, 2018, 04:56:58 PM »
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

  • Member
  • *****
  • Posts: 8599
  • Assembler is fun ;-)
    • MasmBasic
Re: A quick one!
« Reply #8 on: April 22, 2018, 05:08:08 PM »
Code: [Select]
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

  • Member
  • ****
  • Posts: 588
Re: A quick one!
« Reply #9 on: April 22, 2018, 05:09:53 PM »
Hutch & cia,

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

Code: [Select]
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

  • Member
  • ****
  • Posts: 588
Re: A quick one!
« Reply #10 on: April 22, 2018, 05:13:34 PM »
Code: [Select]
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

  • Member
  • *****
  • Posts: 8599
  • Assembler is fun ;-)
    • MasmBasic
Re: A quick one!
« Reply #11 on: April 22, 2018, 05:24:12 PM »
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:
Code: [Select]
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.:
Code: [Select]
.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):
Code: [Select]
; 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

  • Member
  • ****
  • Posts: 588
Re: A quick one!
« Reply #12 on: April 22, 2018, 05:34:35 PM »
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--

  • Administrator
  • Member
  • ******
  • Posts: 5634
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: A quick one!
« Reply #13 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
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

LordAdef

  • Member
  • ****
  • Posts: 588
Re: A quick one!
« Reply #14 on: April 22, 2018, 06:55:47 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.