#include "registers.h"
using namespace std;
const int m = 100;
const int b = 2000;
const int one_register = 99;
const int temp_mux = 98;
const int minus_one_register = 97;
const int temp_min = 96;
// puts the opposite of x in t in 2's complement
void opposite(int t, int x){
append_not(t, x);
append_add(t, t, one_register);
}
//compares integers at registers x and y and outputs a whole register, 1 if x <= y, x and y are not written to
void compare(int t, int x, int y){
opposite(t, x);
append_add(t, t, y);
// 1 if x > y
append_right(t, t, b-1);
//puts the output on the whole register and nots it, 1 if x <= y
append_add(t, t, minus_one_register);
}
//mux, uses temp_mux, c should be full of 1's or 0's, x, y, and c are not written to
void mux(int t, int x, int y, int c){
append_and(t, x, c);
append_not(temp_mux, c);
append_and(temp_mux, temp_mux, y);
append_or(t, t, temp_mux);
}
// creates a mask with 1's in between l and r, 0 otherwise
vector<bool> mask1(int l, int r){
vector<bool> res = vector<bool>(b);
for(int i = 0; i < b; i++){
if(l <= i && i < r) res[i] = 1;
}
return res;
}
void extract(int t, int x, int l, int r){
append_store(t, mask1(l, r));
append_and(t, t, x);
}
// i is start intdex, w is width
void extract_shift(int t, int x, int i, int w){
append_left(t, x, b-w-i);
append_right(t, t, b-w);
}
void min(int t, int x, int y){
compare(temp_min, x, y);
mux(t, x, y, temp_min);
}
void construct_instructions(int s, int n, int k, int q) {
append_store(one_register, mask1(0, 1));
append_store(minus_one_register, mask1(0, b));
append_print(0);
if(s == 0){
const int min_register = 1;
const int extract_register = 2;
// max_value in min_register
append_store(min_register, mask1(0, k));
for(int i = 0; i < n; i++){
int l = i*k;
int w = k;
extract_shift(extract_register, 0, l, k);
append_print(extract_register);
min(min_register, min_register, extract_register);
//append_print(register);
append_print(min_register);
}
append_move(0, min_register);
}
append_print(0);
return;
}
Compilation message
registers.cpp: In function 'void construct_instructions(int, int, int, int)':
registers.cpp:82:8: warning: unused variable 'w' [-Wunused-variable]
82 | int w = k;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
284 KB |
Wrong answer detected in grader |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
288 KB |
Output is correct |
2 |
Correct |
1 ms |
412 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Wrong answer detected in grader |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Incorrect sorting |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Incorrect sorting |
2 |
Halted |
0 ms |
0 KB |
- |