#include #include unsigned int code[] = { // end: 0xA0000000, // syscall exit 0xA0000000, //add test //push 1 & 2 0xE0000001, 0xE0000002, //add 0x10000000, //print (should get 3) 0xA0000001, //push 0 (separator) 0xE0000000, //print 0xA0000001, //sub test //push 2 & 3 0xE0000002, 0xE0000003, 0x20000000, 0xA0000001, //should get -1 //push 0 (separator) 0xE0000000, //print 0xA0000001, //mult test //push 2 & 3 0xE0000002, 0xE0000003, 0x30000000, 0xA0000001, //should get 6 //push 0 (separator) 0xE0000000, //print 0xA0000001, //load test //load second word 0xE0000004, 0x80000000, 0xA0000001, //should get "1" //push 0 (separator) 0xE0000000, //print 0xA0000001, //load 4th word 0xE000000C, 0x80000000, 0xA0000001, //should get "-2" //push 0 (separator) 0xE0000000, //print 0xA0000001, //store & load test 0xE000000E, 0xE0000000, 0x90000000, //store 14 at zero 0xE0000000, 0x80000000, //load it back 0xA0000001, //print it (should get 14) //clear test & underflow test 0xE0000001, 0xE0002000, 0xE0000101, 0xD0000000, //try add -- this should cause underflow 0x10000000, //print 0 -- shouldn't get here //push 0 (separator) 0xE0000000, //print 0xA0000001, 0xA0000000 }; unsigned int data[] = { 0x00000004, 0x00000001, 0xffffffff, 0xfffffffe, 0x00000002 }; typedef struct _Header378Binary { unsigned char MagicCode[4]; unsigned int DataSize; unsigned int CodeSize; unsigned int InitialPC; } Header378Binary; int main() { FILE *fp = fopen("378binary.bin", "wb"); Header378Binary Header; Header.MagicCode[0] = '3'; Header.MagicCode[1] = '7'; Header.MagicCode[2] = '8'; Header.MagicCode[3] = ' '; Header.DataSize = sizeof(data); Header.CodeSize = sizeof(code); Header.InitialPC = 0x00000008; printf("code=%d, data=%d\n", sizeof(code), sizeof(data)); fwrite(&Header, 1, sizeof(Header), fp); fwrite(data, 1, sizeof(data), fp); fwrite(code, 1, sizeof(code), fp); fclose(fp); }