Commit 6a3463c7 by malcolm

added simple comp library

parent e54b5743
Showing with 77 additions and 0 deletions
#include "comp.h"
int cstack[128];
int cstack_size;
void cpush(int n)
{
cstack[cstack_size]=n;
cstack_size++;
}
void cpop()
{
if(cstack_size==0)
return;
cstack_size--;
}
int cpeek()
{
return cstack[cstack_size-1];
}
void cadd()
{
if(cstack_size<2)
return;
int a=cpeek();
cpop();
int b=cpeek();
cpop();
cpush(a+b);
}
void cmult()
{
if(cstack_size<2)
return;
int a=cpeek();
cpop();
int b=cpeek();
cpop();
cpush(a*b);
}
void csub()
{
if(cstack_size<2)
return;
int a=cpeek();
cpop();
int b=cpeek();
cpop();
cpush(a-b);
}
void cdiv()
{
if(cstack_size<2)
return;
int a=cpeek();
cpop();
int b=cpeek();
cpop();
cpush(a/b);
}
#ifndef _INC_COMP
#define _INC_COMP
void cpush(int n);
void cpop();
int cpeek();
void cadd();
void cmult();
void csub();
void cdiv();
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment