Lesson 02
Lesson 02
comma-separated list
whitespace
colon hashmark
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: ‘.’, ‘_’, ‘$’
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 (‘.’)
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
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)
Typical ‘counted-loop’ construct
Initialize some variables
Perform a loop-iteration
no
Done?
yes
A loop-within-a-loop
‘outer’
loop
‘inner’
loop
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