70 likes | 97 Views
This C++ program implements a simple assembly language program with basic arithmetic operations and control flow statements. It also includes an example of polymorphism in object-oriented programming.
E N D
Simple Assembly Language mov #,r put constant into variable r mov a,r copy variable a to variable r add a,b,r add variable a to variable b, store result in r add a,#,r add # to variable a, store result in r sub a,b,r subtract b from a, store result in r sub a,#,r subtract # from a, store result in r mul a,b,r multiply a and b, store result in r mul a,#,r multiply a and #, store result in r br0 a,<label> goto <label> if variable a is 0 brn0 a,<label> goto <label> if variable a is NOT 0 brg0 a,<label> goto <label> if variable a is GREATER THAN 0 brl0 a,<label> goto <label> if variable a is LESS THAN 0 br <label> goto <label> print a print variable a print <string> prints a double quoted string
Re-write this program in C++ mov 10,a mov 5,b sub a,b,r br0 r, equal brg0 r, bless aless: print “a less than b” goto done equal: print “a and b are equal” goto done bless: print “b less than a” goto done done: print “goodbye!”
What does this C++ program do? class Animal { public int weight; public int color; public void talk()=0; } class Dog : Animal { public void talk() { cout << “Woof!” << endl; } } class Cat : Animal { public void talk() { cout << “Meow!” << endl; } } void poke (Animal *animal) { animal->talk(); } ... Dog spike; Cat fluffy; int size=2; Animal* array[size]; array[0] = &spike; array[1] = &fluffy; for (int i=0; i<size; i++) { poke(animal[i]); } ...