1 / 7

Simple Assembly Language Program Implementation in C++

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.

Télécharger la présentation

Simple Assembly Language Program Implementation in C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction

  2. 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

  3. 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!”

  4. 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]); } ...

  5. Avoid “many ways to skin that cat” syndrome.

  6. Syntax should imply semantics.

  7. Which program do you prefer?

More Related