Presentation is loading. Please wait.

Presentation is loading. Please wait.

Let’s do a code ‘walk-through’ Here we examine the design details for a short, but not trivial, assembly language example.

Similar presentations


Presentation on theme: "Let’s do a code ‘walk-through’ Here we examine the design details for a short, but not trivial, assembly language example."— 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 colon whitespace hashmark comma-separated list

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? yes no

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


Download ppt "Let’s do a code ‘walk-through’ Here we examine the design details for a short, but not trivial, assembly language example."

Similar presentations


Ads by Google