1 / 10

Let’s do a code ‘walk-through’

Let’s do a code ‘walk-through’. Here we examine the design details for a short, but not trivial, assembly language example. A good way to get us going…. It’s a short program (could fit on one page) It’s ‘self-contained’ (i.e., needs no libraries) It displays output that is helpful for CS

evanskelly
Download Presentation

Let’s do a code ‘walk-through’

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. Let’s do a code ‘walk-through’ Here we examine the design details for a short, but not trivial, assembly language example

  2. A good way to get us going… • It’s a short program (could fit on one page) • It’s ‘self-contained’ (i.e., needs no libraries) • It displays output that is helpful for CS • It illustrates important assembly principles • It implements a ‘nested loop’ algorithm

  3. Source-statement format • Each statement in an assembly language program’s source-file follows a ‘standard’ format, comprised of four distinct fields: label: opcode operand(s) # comment comma-separated list whitespace hashmark colon

  4. Labels • The ‘label’ field is allowed to be blank if the statement doesn’t need a label (i.e., if it’s not referred to by any other statements) • Where a label is needed, the programmer is responsible to making up the name: • It cannot begin with a digit-character (‘0’..’9’) • It can only contain letters and digits, or the three special characters: ‘.’, ‘_’, ‘$’

  5. Two kinds of ‘opcodes’ • The ‘opcode field’ holds a reserved word • An Intel-x86 ‘instruction’, or • A GNU-assembler ‘directive’ • This distinction will be very important! • But it’s easy to recognize the ‘directives’ because they begin with a dot-symbol (‘.’)

  6. Operands vary with the opcode • Some opcodes require no operands • Some opcodes need only one operand • Most opcodes need two operands • A few opcodes need three operands • When more than one operand is needed, the comma-symbol is used a separator

  7. Comment-field • The comments are programmer-designed • Their intent is to help other programmers understand the purpose of a statement in the overall flow of the program-algorithm • They are ignored by the assembler as far as the language-translation is concerned • But they will be displayed in an assembler listing-file (if in fact one is generated)

  8. Typical ‘counted-loop’ construct Initialize some variables Perform a loop-iteration Adjust the iteration-counter Done? no yes

  9. A loop-within-a-loop ‘outer’ loop ‘inner’ loop

  10. Demo: ‘nybbles.s’ • You can download this source-file from our class website to your local directory: $ cp /home/web/cruse/cs210/nybbles . • You can assemble it and link it, like this: $ as nybbles.s -o nybbles.o $ ld nybbles.o -o nybbles • Then you can execute it, like this: $ ./nybbles

More Related