Oberon Community Platform Forum
November 21, 2019, 06:20:45 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Assembler Puzzle  (Read 6201 times)
soren renner
Global Moderator
Full Member
*****
Posts: 216



« on: February 22, 2011, 01:54:09 AM »

I would like to compile the following module using the very latest compiler present in r3872. It results in several errors now: the syntax has changed.



Quote
MODULE XNPSE;
IMPORT SYSTEM, XNPSBase;


(* procedure for casting real array to integer array. From Patrik Reali ETHZ 2000*)

PROCEDURE E*(VAR p: XNPSBase.PT; VAR ijk: XNPSBase.IPT);
VAR
   in: ARRAY 3 OF REAL;
   out: ARRAY 3 OF INTEGER;
BEGIN
   in[0]:=p.x;in[1]:=p.y; in[2]:=p.z;
   Eprime(in,out);
   ijk.i:=out[0]; ijk.j:=out[1]; ijk.k:=out[2];
END E;

PROCEDURE Eprime(VAR in:ARRAY OF REAL; VAR out: ARRAY OF INTEGER);
CODE {SYSTEM.i386, SYSTEM.FPU}
   MOV   EDI, [EBP+8] ; dest   = ADR(out)
   MOV   ECX, [EBP+12]       ; count  = LEN(out)
   MOV   ESI, [EBP+16]        ; source = ADR(in)
   CMP   ECX, [EBP+20]
   JGE   Ok
   PUSH  99                  ; LEN(in) > LEN(out)  then TRAP(99)
   INT   3
Ok:
   SUB   ESP, 8              ; change FPU rounding to "chop"
   FSTCW [ESP]
   WAIT
   MOV   EBX, [ESP]
   OR    EBX, 0400H          ; clear bit 10,11 (chop/truncate toward zero)
   MOV   [ESP+4], EBX
   FLDCW [ESP+4]
   JMP   Check
Loop:
   DEC   ECX
   FLD   DWORD [ESI][ECX*4]  ; in: SREAL
   FISTP WORD [EDI][ECX*2]   ; out: INTEGER
   WAIT
Check:
   CMP   ECX, 0
   JG    Loop
   FLDCW [ESP]               ; restore original FPU configuration
   ADD   ESP, 8
END Eprime;

PROCEDURE E2*(in: XNPSBase.PT; VAR out: XNPSBase.IPT);
BEGIN
(*   ROUND(in[0], out[0]);
   ROUND(in[1], out[1]);
   ROUND(in[2], out[2]); *)
END E2;

(* PROCEDURE ROUND(x: SREAL; VAR y: LONGINT);
CODE {SYSTEM.i386, SYSTEM.FPU}
       FLD x[EBP]
       MOV EAX, y[EBP]
       FISTP DWORD 0[EAX]
END ROUND;

PROCEDURE ROUND(x: LONGSREAL; VAR y: LONGINT);
CODE {SYSTEM.i386, SYSTEM.FPU}
       FLD x[EBP]
       MOV EAX, y[EBP]
       FISTP DWORD 0[EAX]
END ROUND; *)

PROCEDURE -ROUND*(x: REAL; VAR y: LONGINT);
CODE {SYSTEM.i386, SYSTEM.FPU}
       POP EAX
       FLD DWORD PTR [EBP]
       ADD ESP, 4
       FISTP DWORD [EAX]
END ROUND;

(* PROCEDURE -ROUND(x: LONGREAL; VAR y: LONGINT);
CODE {SYSTEM.i386, SYSTEM.FPU}
       POP EAX
       FLD QWORD PTR 0[EBP]
       ADD ESP, 8
       FISTP DWORD 0[EAX]
END ROUND;
*)

END XNPSE.


ERRORS:
   XNPSE.Mod@1749   error: constant expected
   XNPSE.Mod@780   error: unkown instruction : WAIT
   XNPSE.Mod@973   error: operand missing
      error: invalid combination of opcode and operands : FLD   [ESI], [ECX*4];  @58 in XNPSE.Eprime
   XNPSE.Mod@1013   error: operand missing
      error: invalid combination of opcode and operands : FISTP   [EDI], [ECX*2];  @58 in XNPSE.Eprime
   XNPSE.Mod@1041   error: unkown instruction : WAIT
   XNPSE.Mod@780   error: unkown instruction : WAIT
   XNPSE.Mod@973   error: operand missing
      error: invalid combination of opcode and operands : FLD   [ESI], [ECX*4];  @58 in XNPSE.Eprime
   XNPSE.Mod@1013   error: operand missing
      error: invalid combination of opcode and operands : FISTP   [EDI], [ECX*2];  @58 in XNPSE.Eprime
   XNPSE.Mod@1041   error: unkown instruction : WAIT
   XNPSE.Mod   error: A2.XNPSE could not be compiled (backend errors).
   XNPSE.Mod@1741   error: constant expected
   XNPSE.Mod@969   error: operand missing
      error: invalid combination of opcode and operands : FLD   [ESI], [ECX*4];  @58 in XNPSE.Eprime
   XNPSE.Mod@1009   error: operand missing
      error: invalid combination of opcode and operands : FISTP   [EDI], [ECX*2];  @58 in XNPSE.Eprime
   XNPSE.Mod@969   error: operand missing
      error: invalid combination of opcode and operands : FLD   [ESI], [ECX*4];  @58 in XNPSE.Eprime
   XNPSE.Mod@1009   error: operand missing
      error: invalid combination of opcode and operands : FISTP   [EDI], [ECX*2];  @58 in XNPSE.Eprime
   XNPSE.Mod   error: A2.XNPSE could not be compiled (backend errors).
Logged
soren renner
Global Moderator
Full Member
*****
Posts: 216



« Reply #1 on: February 22, 2011, 02:23:56 AM »

MODULE XNPSE;
IMPORT SYSTEM, XNPSBase;

(* procedure for casting real array to integer array. From Patrik Reali ETHZ 2000*)

PROCEDURE E*(VAR p: XNPSBase.PT; VAR ijk: XNPSBase.IPT);
VAR
   in: ARRAY 3 OF REAL;
   out: ARRAY 3 OF INTEGER;
BEGIN
   in[0]:=p.x;in[1]:=p.y; in[2]:=p.z;
   Eprime(in,out);
   ijk.i:=out[0]; ijk.j:=out[1]; ijk.k:=out[2];
END E;

PROCEDURE Eprime(VAR in:ARRAY OF REAL; VAR out: ARRAY OF INTEGER);
CODE {SYSTEM.i386, SYSTEM.FPU}
   MOV   EDI, [EBP+8]         ; dest   = ADR(out)
   MOV   ECX, [EBP+12]       ; count  = LEN(out)
   MOV   ESI, [EBP+16]        ; source = ADR(in)
   CMP   ECX, [EBP+20]
   JGE   Ok
   PUSH  99                  ; LEN(in) > LEN(out)  then TRAP(99)
   INT   3
Ok:
   SUB   ESP, 8              ; change FPU rounding to "chop"
   FSTCW [ESP]
   FWAIT
   MOV   EBX, [ESP]
   OR    EBX, 0400H          ; clear bit 10,11 (chop/truncate toward zero)
   MOV   [ESP+4], EBX
   FLDCW [ESP+4]
   JMP   Check
Loop:
   DEC   ECX
   FLD   DWORD [ESI+ECX*4]  ; in: REAL
   FISTP WORD [EDI+ECX*2]   ; out: INTEGER
   FWAIT
Check:
   CMP   ECX, 0
   JG    Loop
   FLDCW [ESP]               ; restore original FPU configuration
   ADD   ESP, 8
END Eprime;

PROCEDURE E2*(in: XNPSBase.PT; VAR out: XNPSBase.IPT);
(*
BEGIN
   ROUND(in[0], out[0]);
   ROUND(in[1], out[1]);
   ROUND(in[2], out[2]); *)
END E2;

(* PROCEDURE ROUND(x: REAL; VAR y: LONGINT);
CODE {SYSTEM.i386, SYSTEM.FPU}
       FLD x[EBP]
       MOV EAX, y[EBP]
       FISTP DWORD 0[EAX]
END ROUND;

PROCEDURE ROUND(x: LONGREAL; VAR y: LONGINT);
CODE {SYSTEM.i386, SYSTEM.FPU}
       FLD [EBP+x]
       MOV EAX, [EBP+y]
       FISTP DWORD [EAX]
END ROUND; *)

PROCEDURE -ROUND*(x: REAL; VAR y: LONGINT);
CODE {SYSTEM.i386, SYSTEM.FPU}
       POP EAX
       FLD DWORD [EBP]
       ADD ESP, 4
       FISTP DWORD [EAX]
END ROUND;

(* PROCEDURE -ROUND(x: LONGREAL; VAR y: LONGINT);
CODE {SYSTEM.i386, SYSTEM.FPU}
       POP EAX
       FLD QWORD [EBP]
       ADD ESP, 8
       FISTP DWORD [EAX]
END ROUND;
*)

END XNPSE.
Logged
justin_ruch1180
Guest
« Reply #2 on: March 07, 2011, 02:17:45 AM »

is there still errors now?
Logged
soren renner
Global Moderator
Full Member
*****
Posts: 216



« Reply #3 on: March 07, 2011, 04:01:25 PM »

No. It has been unpuzzled by me. I am sorry for the inconvenience.
Logged
lunar
Newbie
*
Posts: 1


« Reply #4 on: July 17, 2011, 09:17:20 PM »

OKay, so there are no errors now? That's good thanks for working so hard to fox the problem, it's very much appretiated.  Wink
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!