Let - PowerPoint PPT Presentation

About This Presentation
Title:

Let

Description:

Let's do a code walk-through' Here we examine the design details for a short, ... But it's easy to recognize the directives' because they begin with a dot-symbol ... – PowerPoint PPT presentation

Number of Views:390
Avg rating:3.0/5.0
Slides: 11
Provided by: CRU7
Learn more at: https://www.cs.usfca.edu
Category:
Tags: adot

less

Transcript and Presenter's Notes

Title: Let


1
Lets 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
  • Its a short program (could fit on one page)
  • Its 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 programs
    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 doesnt need a label (i.e., if its 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 its 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
Write a Comment
User Comments (0)
About PowerShow.com