Introduction Simple Assembly Language mov add sub mul
Introduction
Simple Assembly Language mov add sub mul br 0 brn 0 brg 0 brl 0 br print #, r a, b, r a, #, r a, <label> <label> a <string> put constant into variable r copy variable a to variable r add variable a to variable b, store result in r add # to variable a, store result in r subtract b from a, store result in r subtract # from a, store result in r multiply a and b, store result in r multiply a and #, store result in r goto <label> if variable a is 0 goto <label> if variable a is NOT 0 goto <label> if variable a is GREATER THAN 0 goto <label> if variable a is LESS THAN 0 goto <label> print variable a prints a double quoted string
Re-write this program in C++ mov 10, a mov 5, b sub a, b, r br 0 r, equal brg 0 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: print “goodbye!”
What does this C++ program do? class Animal { public int weight; public int color; public void talk()=0; void poke (Animal *animal) { animal->talk(); }. . . } class Dog : Animal { public void talk() { cout << “Woof!” << endl; } } class Cat : Animal { public void talk() { cout << “Meow!” << endl; } } 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]); }. . .
Avoid “many ways to skin that cat” syndrome.
Syntax should imply semantics.
Which program do you prefer?
- Slides: 7