SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Jimmy Pham
  2. Miguel Aguilar
  3. Computer Science 240-01
  4. TuTh 2:30
  5. Sept 23, 2019
  6.  
  7.  
  8.  
  9. #include <iostream>
  10. using namespace std;
  11. unsigned short a = 0, b = 0, c = 0, d = 0;
  12. void displaybasetwo() {
  13.     cout << "State of register: ";
  14.     unsigned short b = 1 << 15;
  15.     int y = a, t;
  16.     for (int i = 1; i <= 16; ++i) {
  17.         t = y & b;
  18.         if (t == 0) { cout << '0'; }
  19.         else { cout << '1'; }
  20.         if (i % 4 == 0) { cout << ' '; }
  21.         y = y << 1;
  22.     }
  23. }
  24. void displaynumprint() {
  25.     cout << "\n\tThe number of printers connected to the computer: " << b << endl;
  26. }
  27. void displaynumdrives() {
  28.     cout << "\n\tThe number of floppy drives connected to the computer: " << c << endl;
  29. }
  30. void displayramcapa() {
  31.     cout << "\n\tThe amount of ram in the computer: " << d << "GB" <<endl;
  32. }
  33. int main() {
  34.     _asm {
  35.         mov bx, 0xCE9C; //given register in prompt
  36.         mov a, bx;
  37.         call displaybasetwo; // Display register state
  38.         mov cx, bx;
  39.         shr cx, 14; //leave last two bits which represent num printers
  40.         mov b, cx;
  41.         call displaynumprint;
  42.         mov cx, bx;
  43.         shl cx, 8; //remove bits 9-16
  44.         shr cx, 14; //remove bits 1-6, leaving bits 7 and 8 (14 comes from 8[reverse the left shift]+6)
  45.         mov c, cx;
  46.         inc c;
  47.         call displaynumdrives;
  48.         mov ax, bx;
  49.         shl ax, 12; //remove bits 5-16
  50.         shr ax, 14; //remove bits 1-2, leaving bits 3 and 4 (14 comes from 12[reverse the left shift]+2)
  51.         imul ax, 16;
  52.         add ax, 16;
  53.         mov d, ax;
  54.         call displayramcapa;
  55.     }
  56.     return 0;
  57. }
  58.  
  59.  
  60. #include <iostream>
  61. using namespace std;
  62. unsigned short a = 0;
  63. short total = 0, c = 0;
  64. void displaybasetwo() {
  65.     cout << "State of register: ";
  66.     unsigned short b = 1 << 15;
  67.     int y = a, t;
  68.     for (int i = 1; i <= 16; ++i) {
  69.         t = y & b;
  70.         if (t == 0) { cout << '0'; }
  71.         else { cout << '1'; }
  72.         if (i % 4 == 0) { cout << ' '; }
  73.         y = y << 1;
  74.     }
  75. }
  76. void countsprinklers() {
  77.     cout << "\n" << total << " sprinklers are ON" << endl;
  78. }
  79. void displayBits() {
  80.     cout << c << " ";
  81. }
  82. int main() {
  83.     _asm {
  84.         mov bx, 0x6A2F; //given register in prompt
  85.         mov ax, bx;
  86.         mov a, bx;
  87.         call displaybasetwo; // Display register state
  88.         mov cx, 0x0001;
  89.         mov c, 1;
  90.     FORLOOP:
  91.         cmp c, 16;
  92.         je EXIT;
  93.         AND ax, cx;
  94.         add total, ax;
  95.         shr bx, 1;
  96.         mov ax, bx;
  97.         mov cx, 0x0001;
  98.         inc c;
  99.         jmp FORLOOP;
  100.     EXIT:
  101.         call countsprinklers;
  102.     }
  103.     cout << "Defective sprinklers: ";
  104.     _asm {
  105.         mov bx, 0x6A2F; //given register in prompt
  106.         mov ax, bx;
  107.         mov cx, 0x1000;
  108.         shl cx, 3;
  109.         mov c, 16;
  110.     FORLOOP2:
  111.         cmp c, 1;
  112.         je EXIT2;
  113.         AND ax, cx;
  114.         cmp ax, 0;
  115.         je DISPLAYBIT;
  116.         shl bx, 1;
  117.         mov ax, bx;
  118.         mov cx, 1000000000000000b;
  119.         dec c;
  120.         jmp FORLOOP2;
  121.     DISPLAYBIT:
  122.         call displayBits;
  123.         dec c;
  124.         shl bx, 1;
  125.         mov ax, bx;
  126.         mov cx, 1000000000000000b;
  127.         jmp FORLOOP2;
  128.     EXIT2:
  129.  
  130.     }
  131.     return 0;
  132. }
  133.  
  134.  
  135. #include <iostream>
  136. #include <ctime>
  137. using namespace std;
  138. unsigned short a = 0, b = 0, c = 0;
  139. void randomizeregister() {
  140.     b = rand() % 65535; //gives random number within ushrt_max
  141.     b = b << 1; //left shift by one to guarantee first floor is 0
  142. }
  143. void displaybasetwo() {
  144.     cout << "State of register: ";
  145.     unsigned short b = 1 << 15;
  146.     int y = a, t;
  147.     for (int i = 1; i <= 16; ++i) {
  148.         t = y & b;
  149.         if (t == 0) { cout << '0'; }
  150.         else { cout << '1'; }
  151.         if (i % 4 == 0) { cout << ' '; }
  152.         y = y << 1;
  153.     }
  154. }
  155. void displaystops() {
  156.     cout << "\nElevator will stop at floors no. ";
  157. }
  158. void displayBit() {
  159.     cout << c << " ";
  160. }
  161. int main() {
  162.     srand((unsigned int)time(NULL)); // Initialize randomization using time as seed
  163.     _asm {
  164.         call randomizeregister; // Randomize the register
  165.         mov bx, b;
  166.         mov a, bx;
  167.         call displaybasetwo; // Display register state
  168.         //DISPLAY STOPS
  169.         call displaystops;
  170.         mov ax, bx;
  171.         mov c, 16;
  172.         mov cx, 1000000000000000b; //cx = 1000 0000 0000 0000
  173.     FORLOOP:
  174.         cmp c, 1;
  175.         je EXIT;
  176.         AND ax, cx;
  177.         cmp ax, 0;
  178.         jne DISPLAYBIT;
  179.         shl bx, 1;
  180.         mov ax, bx;
  181.         mov cx, 1000000000000000b;
  182.         dec c;
  183.         jmp FORLOOP;
  184.     DISPLAYBIT:
  185.         call displayBit;
  186.         shl bx, 1;
  187.         mov ax, bx;
  188.         mov cx, 1000000000000000b;
  189.         dec c;
  190.         jmp FORLOOP;
  191.     EXIT:
  192.  
  193.     }
  194.     return 0;
  195. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top