Author Topic: EDI Problem  (Read 2371 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
EDI Problem
« on: February 28, 2016, 08:33:44 AM »
Hi Charles,

EDI does not work correctly.
Code: [Select]
indexbase 0

sys a[9] = {10,20,30,40,50,60,70,80,90,100}
sys reg

lea esi,a
mov eax,[esi]
print eax

mov eax,[esi+4]
print eax

mov eax,[esi+8]
print eax

lea edi,a
mov eax,[edi]
print eax

mov eax,[edi+4]
print eax

mov eax,[edi+8]
print eax

jack

  • Guest
Re: EDI Problem
« Reply #1 on: February 28, 2016, 10:18:23 AM »
hi peter
I have not tried this but maybe the register esi is being used by the print statement and therefor left in an undefined state.

Peter

  • Guest
Re: EDI Problem
« Reply #2 on: February 28, 2016, 11:20:30 AM »
Quote
I have not tried this but maybe the register esi is being used by the print statement and therefor left in an undefined state.

Hello Jack,

The ESI Register is okay, this EDI Register makes trouble.
Code: [Select]
indexbase 0
dword a[9] = {10,20,30,40,50,60,70,80,90,100}

addr esi,a
mov eax,[esi]
print eax

mov eax,[esi+4]
print eax

mov eax,[esi+8]
print eax

mov eax,[esi+12]
print eax

mov eax,[esi+16]
print eax

mov eax,[esi+20]
print eax

Charles Pegge

  • Guest
Re: EDI Problem
« Reply #3 on: April 05, 2016, 11:18:57 PM »
Hi Peter,

Internal o2 functions treat the ESI and EDI registers as volatile (as with EAX, ECX, EDX)

To ensure compliance with STDCALL, any calls made directly from Assember, where ESI and EDI are used, should be wrapped in an extern function, or simply push/pop these registers.

Example wrapping print:
Code: OxygenBasic
  1. extern
  2.   function printsys(sys i)
  3.     print i
  4.   end function
  5.  
  6.   ...
  7.  
  8. end extern
  9.  
  10.  

Peter

  • Guest
Re: EDI Problem
« Reply #4 on: April 09, 2016, 06:06:09 AM »
Quote
Internal o2 functions treat the ESI and EDI registers as volatile (as with EAX, ECX, EDX)

Better would be, oxygenbasic PUSH / POP all the register in a FUNCTION!
Programming can be so easy.   ;D

Charles Pegge

  • Guest
Re: EDI Problem
« Reply #5 on: April 10, 2016, 11:12:16 PM »
This is one way of sembedding Basic expressions safely  within an Assembler sequence:

Code: OxygenBasic
  1. 'test safe call macro
  2.  
  3. function f(sys a,b) as sys
  4. return a+b
  5. end function
  6.  
  7. def safe
  8.   pushad
  9.   %1
  10.   popad
  11. end def
  12.  
  13. safe ( print f(1,2) )
  14.  

ps pushad and popad are not valid instructions in 64 bit mode. You have to specify each register.