Author Topic: ObjAsm: boring notes  (Read 7898 times)

HSE

  • Member
  • *****
  • Posts: 2497
  • AMD 7-32 / i3 10-64
ObjAsm: boring notes
« on: February 09, 2019, 02:03:27 AM »
Code: [Select]
fInt macro
  sub xsp, @WordSize                                    ;;Reserve stack place for one word
  fstcw WORD ptr [xsp]                                  ;;Store FPU control word
 >>>> push QWORD ptr [xsp]                                  ;;Duplicate value
  BitSet WORD ptr [xsp], (BIT10 or BIT11)               ;;Modify the control word, int(x) = Truncate (toward 0)
  fldcw WORD ptr [xsp]                                  ;;Restore modified FPU control word
  frndint                                               ;;Round down
  fldcw WORD ptr[xsp + @WordSize]                       ;;Restore previous FPU control word
  add rsp, 2*@WordSize              <<<<<<<<                    ;;Restore stack. Don't use pop eax. We wan't destroy it
endm

« Last Edit: February 12, 2019, 11:09:16 PM by HSE »
Equations in Assembly: SmplMath

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 1082
  • ObjAsm Developer
    • ObjAsm
Re: ObjAsm: boring notes
« Reply #1 on: February 09, 2019, 05:23:55 AM »
Hi
Sorry for the typo. It was midnight when I wrote it  :P
Should be

Code: [Select]
  add xsp, 2*@WordSize        ;;Restore stack. Don't use pop xax. We'll not destroy it.
also correct the same way the fRndDn macro.

Biterider


HSE

  • Member
  • *****
  • Posts: 2497
  • AMD 7-32 / i3 10-64
Re: ObjAsm: boring notes
« Reply #2 on: February 09, 2019, 06:43:08 AM »
It's presumed that because main development is oriented to 64bit, this little things will appear when testing in 32bit.  :t

The title reflect the fact that this things don't even allow any discussion.  :biggrin:
Equations in Assembly: SmplMath

HSE

  • Member
  • *****
  • Posts: 2497
  • AMD 7-32 / i3 10-64
Re: ObjAsm: boring notes
« Reply #3 on: February 09, 2019, 07:37:37 AM »
Demo02 don't have Shared.inc
Equations in Assembly: SmplMath

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 1082
  • ObjAsm Developer
    • ObjAsm
Re: ObjAsm: boring notes
« Reply #4 on: February 09, 2019, 08:11:28 AM »
Thanks!

HSE

  • Member
  • *****
  • Posts: 2497
  • AMD 7-32 / i3 10-64
Re: ObjAsm: boring notes
« Reply #5 on: February 09, 2019, 08:45:13 AM »
Demo01b crash because ReadFile don't have storage for number of bytes readed.
Equations in Assembly: SmplMath

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 1082
  • ObjAsm Developer
    • ObjAsm
Re: ObjAsm: boring notes
« Reply #6 on: February 09, 2019, 06:43:34 PM »
Hi HSE
You are completely right. Fixed now.
Thank you  :icon14:


Biterider

HSE

  • Member
  • *****
  • Posts: 2497
  • AMD 7-32 / i3 10-64
Re: ObjAsm: boring notes
« Reply #7 on: February 12, 2019, 11:12:41 PM »
Hi Biterider!

See again first post. Macros in fMath.inc are pushing QWORDs. I don't know if you maked a dual equate WORD/QWORD for 32/64 BITNESS
Equations in Assembly: SmplMath

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 1082
  • ObjAsm Developer
    • ObjAsm
Re: ObjAsm: boring notes
« Reply #8 on: February 13, 2019, 04:07:17 AM »
Hi HSE
Yes, you are right. Please try the posted file. I think I've made all necessary corrections.

Biterider

HSE

  • Member
  • *****
  • Posts: 2497
  • AMD 7-32 / i3 10-64
Re: ObjAsm: boring notes
« Reply #9 on: February 13, 2019, 08:21:20 AM »
I maked a little mess with my test :biggrin:, but your file looks good  :t

Thanks.
Equations in Assembly: SmplMath

HSE

  • Member
  • *****
  • Posts: 2497
  • AMD 7-32 / i3 10-64
Re: ObjAsm: boring notes
« Reply #10 on: February 13, 2019, 09:40:18 PM »
Hi Biterider:

Nothing was working until I noted change in "m2m" macro  :biggrin: :biggrin:

I solved using old macro if BITNESS = 32. I thing that without register specification m2m have to make push and pop in 32, and use some 64 register not used in 32 (r10...r13) .

Only problem I see using AsmC are 2 or 3 ".elseif macro something" that I changed to ".elseif OA_something" (I will see again if I find where that was!)

Regards.
Equations in Assembly: SmplMath

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: ObjAsm: boring notes
« Reply #11 on: February 13, 2019, 10:16:23 PM »
Only problem I see using AsmC are 2 or 3 ".elseif macro something" that I changed to ".elseif OA_something"

Remember the old late expansion problem when using .elseif somemac(arg)==123

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 1082
  • ObjAsm Developer
    • ObjAsm
Re: ObjAsm: boring notes
« Reply #12 on: February 13, 2019, 10:50:01 PM »
Hi HSE
It wasn't an easy decision to extend/change the way m2m works.
But it there is making some troubles, there is an easy way to overcome the issue. Other people are using a mrm macro, that explicitly uses a register to transfer the value. Since the goal was to write code that can be compiled for x86 and x64, I can do a "mass mutation" of the source code changing m2m to mrm, leaving m2m free to work like before.
Is this acceptable for you?

Like JJ said, the ".elseif macro something" is something to avoid. If you can find the code, please let me know.  :t

Biterider


HSE

  • Member
  • *****
  • Posts: 2497
  • AMD 7-32 / i3 10-64
Re: ObjAsm: boring notes
« Reply #13 on: February 14, 2019, 12:22:05 AM »
Remember the old late expansion problem when using .elseif somemac(arg)==123

Thanks JJ. It's that.

Forcing expansion solve the AsmC problem (in XMenu.inc):
Code: [Select]
    % .elseif [xbx].$Obj(XMenuItem).dType == MENU_TYPE_SIDEBAR
Since the goal was to write code that can be compiled for x86 and x64

The better practice in 32 bit is to use push and pop because there is few registers (if you don't need to load a value in a register). In 64 bit you have to use a register.  The dual code have to use both, just taking care that in 64 bit registers in use are not trashed (rax,rbx,rcx,etc). 
R8 and r9 are used to pass arguments. R14 and r15 are prefered for some procedures (see Hutch code) and registers with same name have especific use in ARM. That left r10...r13 for choice...
Not very elegant, but I put in system.inc the old m2m for 32 bitness and the new for 64 but using r10 instead of rax.
Equations in Assembly: SmplMath

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: ObjAsm: boring notes
« Reply #14 on: February 14, 2019, 01:06:12 AM »
Thanks JJ. It's that.

Forcing expansion solve the AsmC problem (in XMenu.inc):
Code: [Select]
    % .elseif [xbx].$Obj(XMenuItem).dType == MENU_TYPE_SIDEBAR

Are you sure?

Code: [Select]
include \masm32\include\masm32rt.inc
.code
start:
  mov eax, 1
  .if eax==12345678h
print "never"
  % .elseif len("test")>3
print "Len gt 3"
  .else
print "you are screwed, my friend"
  .endif
  exit
end start

P.S.: Replace the mov eax, 1 with mov eax, 4 to enjoy some pleasant nights of bug chasing for Real MenTM 8)