예제 #1
0
int main()
{
    START_MACHINE;
    JUMP(CONTINUE);

#include "char.lib"
#include "io.lib"
#include "math.lib"
#include "string.lib"
#include "system.lib"
#include "scheme.lib"

 CONTINUE:
    /* initialize the 4 singletons */
    PUSH(IMM(1));
    CALL(MAKE_SOB_BOOL);         /* define SOB_BOOL_TRUE in mem[1]*/
    DROP(1);
    PUSH(IMM(0));
    CALL(MAKE_SOB_BOOL);         /* define SOB_BOOL_FALSE in mem[3]*/
    DROP(1);
    CALL(MAKE_SOB_NIL);          /* define nil in mem[5] */
    CALL(MAKE_SOB_VOID);         /* define #Void in mem[6] */

  /* start of code */
  /* CALL(MAKE_SOB_NIL); */
    /* MOV(R0, IND(IMM(4))); */
    MOV(R0, IMM(5));
  PUSH(R0);
  CALL(IS_SOB_TRUE);
  CMP(R0, IMM(1));              /* 1 means R0 was true, 0 means it
                                   was #f */
  JUMP_EQ(Lelse1);
  PUSH(IMM(1));
  CALL(MAKE_SOB_BOOL);
  JUMP(Lexit1);
 Lelse1:
  PUSH(IMM(0));
  CALL(MAKE_SOB_BOOL);
 Lexit1:

  PUSH(R0);
  CALL(WRITE_SOB);
  /* newline and stop machine */
  PUSH(IMM('\n'));
  CALL(PUTCHAR);
  STOP_MACHINE;

  return 0;
}
예제 #2
0
파일: output13.c 프로젝트: tompere/hw4
int main()
{
	START_MACHINE;
	
	JUMP(CONTINUE);

	#include "scheme.lib"
	#include "char.lib"
	#include "io.lib"
	#include "math.lib"
	#include "string.lib"
	#include "system.lib"

CONTINUE:
	
	/* Initialize stack with default values */
	
	/* Void */
	CALL(MAKE_SOB_VOID);
	MOV(ADDR(10), IND(R0));
	
	/* Nil (Empty List) */
	CALL(MAKE_SOB_NIL);
	MOV(ADDR(11), IND(R0));
	
	/* False (Boolean) */
	PUSH(IMM(0));
	CALL(MAKE_SOB_BOOL);
	MOV(ADDR(12), IND(R0));
	MOV(ADDR(13), INDD(R0,1));
	DROP(IMM(1));
	
	/* True (Boolean) */
	PUSH(IMM(1));
	CALL(MAKE_SOB_BOOL);
	MOV(ADDR(14), IND(R0));
	MOV(ADDR(15), INDD(R0,1));
	DROP(IMM(1));
	
	/* END of initialization */
	
	/* Internal function to check if a type is a SOB */
	
	IS_SOB_TYPE:
		MOV(R0, STARG(0));
		MOV(R0, IND(R0));
		CMP(R0, IMM(T_VOID));
		JUMP_EQ(TRUE_SOB_TYPE);
		CMP(R0, IMM(T_NIL));
		JUMP_EQ(TRUE_SOB_TYPE); 
		CMP(R0, IMM(T_BOOL));
		JUMP_EQ(TRUE_SOB_TYPE); 
		CMP(R0, IMM(T_CHAR));
		JUMP_EQ(TRUE_SOB_TYPE); 
		CMP(R0, IMM(T_INTEGER));
		JUMP_EQ(TRUE_SOB_TYPE);
		CMP(R0, IMM(T_STRING));
		JUMP_EQ(TRUE_SOB_TYPE);
		CMP(R0, IMM(T_SYMBOL));
		JUMP_EQ(TRUE_SOB_TYPE);
		CMP(R0, IMM(T_PAIR));
		JUMP_EQ(TRUE_SOB_TYPE);
		CMP(R0, IMM(T_VECTOR));
		JUMP_EQ(TRUE_SOB_TYPE);
		CMP(R0, IMM(T_CLOSURE));
		JUMP_EQ(TRUE_SOB_TYPE);
		MOV(R0, IMM(0));
		JUMP(EXIT_IS_SOB_TYPE);
		TRUE_SOB_TYPE:
			MOV(R0, IMM(1));
		EXIT_IS_SOB_TYPE:
			POP(FP);
			RETURN;
	/* End of IS_SOB_TYPE */
	
		/* applic_3342061*/
	/* applic_3342061 - B4 */
	MOV(R0, IMM(12));
	PUSH(R0);
	/* applic_3342061 - B3 */
	MOV(R0, IMM(14));
	PUSH(R0);
	/* applic_3342061 - B2 */
	MOV(R0, IMM(12));
	PUSH(R0);
	/* applic_3342061 - B1 */
	MOV(R0, IMM(14));
	PUSH(R0);
	PUSH(4);
	PUSH(INDD(R0,1))
	CALL(INDD(R0,2))
	MOV(IND(R1),IMM(2));
	ADD(IND(R1),IMM(4));
	MOV(SP,IND(R1));

	PUSH(R0);
	CALL(WRITE_SOB);
	
	STOP_MACHINE;

	return 0;
}
예제 #3
0
int main()
{
    START_MACHINE;
    JUMP(CONTINUE);

#include "char.lib"
#include "io.lib"
#include "math.lib"
#include "string.lib"
#include "system.lib"
#include "scheme.lib"

#define SOB_BOOL_TRUE (ADDR(1));
#define SOB_BOOL_FALSE (ADDR(3));
#define SOB_NIL (M(mem)[5]);
#define SOB_VOID (ADDR(6));
#define IS_TRUE(reg)

 CONTINUE:
    /* initialize the 4 singletons */
    PUSH(IMM(1));
    CALL(MAKE_SOB_BOOL);         /* define SOB_BOOL_TRUE */
    DROP(1);
    PUSH(IMM(0));
    CALL(MAKE_SOB_BOOL);         /* define SOB_BOOL_FALSE */
    DROP(1);
    CALL(MAKE_SOB_NIL);          /* define nil */
    CALL(MAKE_SOB_VOID);

  /* start of code */
    /*
        code for the expression:
        (begin #t #t #f () #t)
    */
    /*
        code for the expression:
        #t
    */
 MOV(R0, IMM(1));    /* assigning true to R0 */
    /*
        code for the expression:
        #t
    */
 MOV(R0, IMM(1));    /* assigning true to R0 */
    /*
        code for the expression:
        #f
    */
 MOV(R0, IMM(3));    /* assigning false to R0 */
    /*
        code for the expression:
        ()
    */
 MOV(R0, IMM(5));    /* assign nil to R0 */
    /*
        code for the expression:
        #t
    */
 MOV(R0, IMM(1));    /* assigning true to R0 */


/* end of generated code. CONCLUSION: */
 MOV(R1, R0);    /* save the result in R1 */
 PUSH(R1);    /* pushing R1 for void-check */
 CALL(IS_SOB_VOID);    /* if R0 is #Void, don't print */
 DROP(1);
 CMP(R0, IMM(1));    /* 1 means R0 was void, 0 means it wasn't */
 JUMP_EQ(END_OF_THE_WORLD);    /* do not print */
 PUSH(R1);    /* push R1 for print */
 CALL(WRITE_SOB);    /* print the result before quitting */
 DROP(1);
/* that was useless.. */
END_OF_THE_WORLD:    /* (only as we know it.) */
  /* newline and stop machine */
  PUSH(IMM('\n'));
  CALL(PUTCHAR);
  STOP_MACHINE;

  return 0;
}