void conditional_move(Seq_T stream) { emit(stream, loadval(r2, 72)); emit(stream, loadval(r3, 2)); emit(stream, conditional(r1, r2, r3)); emit(stream, output(r1)); emit(stream, halt()); }
void print_six(Seq_T stream) { emit(stream, input(r3)); emit(stream, output(r3)); emit(stream, loadval(r1, 36)); emit(stream, loadval(r2, 36)); emit(stream, add(r3, r1, r2)); emit(stream, output(r3)); emit(stream, halt()); }
void load_prgm_test(Seq_T stream) { emit(stream, loadval(r1, 72)); emit(stream, loadval(r4, 5)); emit(stream, load_prgm(0, 0, r4)); emit(stream, halt()); emit(stream, halt()); emit(stream, output(r1)); emit(stream, halt()); }
void arith_test(Seq_T stream) { emit(stream, loadval(r2, 20)); emit(stream, loadval(r3, 10)); emit(stream, add(r1, r2 , r3)); emit(stream, multiply(r1, r2, r3)); emit(stream, divide(r1, r2, r3)); emit(stream, nand(r1, r2, r3)); emit(stream, halt()); }
void emit_condmove_test(Seq_T stream) { emit(stream, loadval(r3, 99)); emit(stream, loadval(r2, 47)); emit(stream, loadval(r1, 99)); emit(stream, condmove(r1, r2, r3)); emit(stream, output(r1)); emit(stream, loadval(r1, '\n')); emit(stream, output(r1)); emit(stream, halt()); }
void emit_nand_test(Seq_T stream) { emit(stream, loadval(r2, 42)); emit(stream, loadval(r3, 42)); emit(stream, nand(r1, r2, r3)); emit(stream, nand(r1, r2, r3)); emit(stream, output(r2)); emit(stream, loadval(r1, '\n')); emit(stream, output(r1)); emit(stream, halt()); }
void load_seg(Seq_T stream) { emit(stream, loadval(r1, 72)); emit(stream, loadval(r5, 5)); emit(stream, map(0, r2, r5)); emit(stream, store(r2, r0, r1)); emit(stream, load(r3, r2, 0)); emit(stream, output(r3)); emit(stream, unmap(r2)); emit(stream, map(0, r2, r5)); emit(stream, halt()); }
void emit_halt_test(Seq_T stream) { emit(stream, halt()); emit(stream, loadval(r1, 'B')); emit(stream, output(r1)); emit(stream, loadval(r1, 'a')); emit(stream, output(r1)); emit(stream, loadval(r1, 'd')); emit(stream, output(r1)); emit(stream, loadval(r1, '!')); emit(stream, output(r1)); emit(stream, loadval(r1, '\n')); emit(stream, output(r1)); }
/* load, store, map, unmap */ void emit_map_test(Seq_T stream) { // length of segment emit(stream, loadval(r0, 40)); emit(stream, map(r1, r0)); // store value emit(stream, loadval(r2, 36)); emit(stream, loadval(r3, 1)); // store 36 in index 1 emit(stream, store(r1, r3, r2)); emit(stream, load(r4, r1, r3)); emit(stream, output(r4)); emit(stream, loadval(r5, '\n')); emit(stream, output(r5)); emit(stream, unmap(r1)); emit(stream, halt()); }
void emit_time_test(Seq_T stream) { emit(stream, loadval(r5, 'p')); int i; for (i = 0; i < 100000; i++) { emit(stream, output(r5)); } emit(stream, halt()); }
void emit_input_test(Seq_T stream) { emit(stream, input(r3)); emit(stream, output(r3)); emit(stream, loadval(r1, '\n')); emit(stream, output(r1)); emit(stream, input(r3)); emit(stream, output(r3)); emit(stream, halt()); }
static void emit_out_string(Seq_T stream, const char *s, int aux_reg) { int i, len = strlen(s); char c; for (i = 0; i < len; i++) { c = s[i]; emit(stream, loadval(aux_reg, c)); emit(stream, output(aux_reg)); } }
void emit_goto_test(Seq_T stream) { int patch_L = Seq_length(stream); emit(stream, loadval(r7, 0)); /* will be patched to 'r7 := L' */ emit(stream, loadprogram(r0, r7)); /* should goto label L */ emit_out_string(stream, "GOTO failed.\n", r1); emit(stream, halt()); /* define 'L' to be here */ add_label(stream, patch_L, Seq_length(stream)); emit_out_string(stream, "GOTO passed.\n", r1); emit(stream, halt()); }
void emit_add_test(Seq_T stream) { emit(stream, loadval(r2, 99)); emit(stream, loadval(r3, 3)); emit(stream, addition(r1, r2, r3)); emit(stream, output(r1)); emit(stream, loadval(r1, ' ')); emit(stream, output(r1)); emit(stream, loadval(r2, 31)); emit(stream, loadval(r3, 5)); emit(stream, addition(r1, r2, r3)); emit(stream, output(r1)); emit(stream, loadval(r1, '\n')); emit(stream, output(r1)); emit(stream, halt()); }
void emit_multiply_test(Seq_T stream) { emit(stream, loadval(r2, 7)); emit(stream, loadval(r3, 6)); emit(stream, multiply(r1, r2, r3)); emit(stream, output(r1)); emit(stream, loadval(r1, ' ')); emit(stream, output(r1)); emit(stream, loadval(r2, 9)); emit(stream, loadval(r3, 11)); emit(stream, multiply(r1, r2, r3)); emit(stream, output(r1)); emit(stream, loadval(r1, '\n')); emit(stream, output(r1)); emit(stream, halt()); }
void emit_divide_test(Seq_T stream) { emit(stream, loadval(r2, 99)); emit(stream, loadval(r3, 3)); emit(stream, divide(r1, r2, r3)); emit(stream, output(r1)); emit(stream, loadval(r1, ' ')); emit(stream, output(r1)); emit(stream, loadval(r2, 255)); emit(stream, loadval(r3, 5)); emit(stream, divide(r1, r2, r3)); emit(stream, output(r1)); emit(stream, loadval(r1, '\n')); emit(stream, output(r1)); emit(stream, halt()); }
void map_test(Seq_T stream) { emit(stream, loadval(r1, 72)); emit(stream, loadval(r2, 5)); emit(stream, loadval(r0, 0)); emit(stream, map(0, r3, r2)); emit(stream, map(0, r4, r2)); emit(stream, map(0, r5, r2)); emit(stream, map(0, r6, r2)); emit(stream, map(0, r7, r2)); emit(stream, store(r3, r0, r1)); //store 72 in r3(1) segment @ offset r0(0) emit(stream, load(r2, r3, r0)); //load value from segment r3(i) into r2 emit(stream, output(r2)); emit(stream, unmap(r3)); emit(stream, unmap(r4)); emit(stream, unmap(r5)); emit(stream, unmap(r6)); emit(stream, unmap(r7)); emit(stream, loadval(r1, 72)); emit(stream, loadval(r2, 5)); emit(stream, loadval(r0, 0)); emit(stream, map(0, r3, r2)); emit(stream, map(0, r4, r2)); emit(stream, map(0, r5, r2)); emit(stream, map(0, r6, r2)); emit(stream, map(0, r7, r2)); emit(stream, store(r3, r0, r1)); //store 72 in r3(1) segment @ offset r0(0) emit(stream, load(r2, r3, r0)); //load value from segment r3(i) into r2 emit(stream, output(r2)); emit(stream, unmap(r3)); emit(stream, unmap(r4)); emit(stream, unmap(r5)); emit(stream, unmap(r6)); emit(stream, unmap(r7)); emit(stream, halt()); }