Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Jimmy Pham
- Miguel Aguilar
- Computer Science 240-01
- TuTh 2:30
- Sept 23, 2019
- #include <iostream>
- using namespace std;
- unsigned short a = 0, b = 0, c = 0, d = 0;
- void displaybasetwo() {
- cout << "State of register: ";
- unsigned short b = 1 << 15;
- int y = a, t;
- for (int i = 1; i <= 16; ++i) {
- t = y & b;
- if (t == 0) { cout << '0'; }
- else { cout << '1'; }
- if (i % 4 == 0) { cout << ' '; }
- y = y << 1;
- }
- }
- void displaynumprint() {
- cout << "\n\tThe number of printers connected to the computer: " << b << endl;
- }
- void displaynumdrives() {
- cout << "\n\tThe number of floppy drives connected to the computer: " << c << endl;
- }
- void displayramcapa() {
- cout << "\n\tThe amount of ram in the computer: " << d << "GB" <<endl;
- }
- int main() {
- _asm {
- mov bx, 0xCE9C; //given register in prompt
- mov a, bx;
- call displaybasetwo; // Display register state
- mov cx, bx;
- shr cx, 14; //leave last two bits which represent num printers
- mov b, cx;
- call displaynumprint;
- mov cx, bx;
- shl cx, 8; //remove bits 9-16
- shr cx, 14; //remove bits 1-6, leaving bits 7 and 8 (14 comes from 8[reverse the left shift]+6)
- mov c, cx;
- inc c;
- call displaynumdrives;
- mov ax, bx;
- shl ax, 12; //remove bits 5-16
- shr ax, 14; //remove bits 1-2, leaving bits 3 and 4 (14 comes from 12[reverse the left shift]+2)
- imul ax, 16;
- add ax, 16;
- mov d, ax;
- call displayramcapa;
- }
- return 0;
- }
- #include <iostream>
- using namespace std;
- unsigned short a = 0;
- short total = 0, c = 0;
- void displaybasetwo() {
- cout << "State of register: ";
- unsigned short b = 1 << 15;
- int y = a, t;
- for (int i = 1; i <= 16; ++i) {
- t = y & b;
- if (t == 0) { cout << '0'; }
- else { cout << '1'; }
- if (i % 4 == 0) { cout << ' '; }
- y = y << 1;
- }
- }
- void countsprinklers() {
- cout << "\n" << total << " sprinklers are ON" << endl;
- }
- void displayBits() {
- cout << c << " ";
- }
- int main() {
- _asm {
- mov bx, 0x6A2F; //given register in prompt
- mov ax, bx;
- mov a, bx;
- call displaybasetwo; // Display register state
- mov cx, 0x0001;
- mov c, 1;
- FORLOOP:
- cmp c, 16;
- je EXIT;
- AND ax, cx;
- add total, ax;
- shr bx, 1;
- mov ax, bx;
- mov cx, 0x0001;
- inc c;
- jmp FORLOOP;
- EXIT:
- call countsprinklers;
- }
- cout << "Defective sprinklers: ";
- _asm {
- mov bx, 0x6A2F; //given register in prompt
- mov ax, bx;
- mov cx, 0x1000;
- shl cx, 3;
- mov c, 16;
- FORLOOP2:
- cmp c, 1;
- je EXIT2;
- AND ax, cx;
- cmp ax, 0;
- je DISPLAYBIT;
- shl bx, 1;
- mov ax, bx;
- mov cx, 1000000000000000b;
- dec c;
- jmp FORLOOP2;
- DISPLAYBIT:
- call displayBits;
- dec c;
- shl bx, 1;
- mov ax, bx;
- mov cx, 1000000000000000b;
- jmp FORLOOP2;
- EXIT2:
- }
- return 0;
- }
- #include <iostream>
- #include <ctime>
- using namespace std;
- unsigned short a = 0, b = 0, c = 0;
- void randomizeregister() {
- b = rand() % 65535; //gives random number within ushrt_max
- b = b << 1; //left shift by one to guarantee first floor is 0
- }
- void displaybasetwo() {
- cout << "State of register: ";
- unsigned short b = 1 << 15;
- int y = a, t;
- for (int i = 1; i <= 16; ++i) {
- t = y & b;
- if (t == 0) { cout << '0'; }
- else { cout << '1'; }
- if (i % 4 == 0) { cout << ' '; }
- y = y << 1;
- }
- }
- void displaystops() {
- cout << "\nElevator will stop at floors no. ";
- }
- void displayBit() {
- cout << c << " ";
- }
- int main() {
- srand((unsigned int)time(NULL)); // Initialize randomization using time as seed
- _asm {
- call randomizeregister; // Randomize the register
- mov bx, b;
- mov a, bx;
- call displaybasetwo; // Display register state
- //DISPLAY STOPS
- call displaystops;
- mov ax, bx;
- mov c, 16;
- mov cx, 1000000000000000b; //cx = 1000 0000 0000 0000
- FORLOOP:
- cmp c, 1;
- je EXIT;
- AND ax, cx;
- cmp ax, 0;
- jne DISPLAYBIT;
- shl bx, 1;
- mov ax, bx;
- mov cx, 1000000000000000b;
- dec c;
- jmp FORLOOP;
- DISPLAYBIT:
- call displayBit;
- shl bx, 1;
- mov ax, bx;
- mov cx, 1000000000000000b;
- dec c;
- jmp FORLOOP;
- EXIT:
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement