What we already know:
The HLL gets translated into assembly language which gets translated into machine code.
Each HLL statement maps into 1 or MORE assembly language instructions.
For this course, there is actually one more layer that students will be given.
HLL gets translated into MAL, which gets translated into TAL, which gets translated into MIPS RISC machine code.
The assembly language contains a subset of the functionality of most high level languages --
What is required by a programming language?
About assembly languages, in general:
Many assembly languages have 3 basic (primitive) types: integer, float (real), character.
We can build other types out of these basic types. For example, boolean is really an integer with only 2 defined values. (In C, 0 is false, and 1 is true.)
Declarations in some other languages:
var variablename: type;
In MIPS assembly language:
variablename: type value
.floatif single precision floating point
value is optional -- it gives the variable an initial value
variablename is optional -- it gives a way of identifying the variable
(it labels the location of the variable)
flag: .word 0 counter: .word 0 variable3: .word # integer-sized variable, defaults to # an initial value of 0 # (in our simulator, and as implemented # by a MIPS assembler) e: .float 2.71828 uservalue: .byte # character-sized variable letter: .byte 'a' .word 0 # the variablename is not required, # but then there is no name for the # variable!
Other useful rules:
Some useful characters:
(Note that these are the same as in C!)
'\n' the newline (a line feed followed by a carriage return) '\t' horizontal tab '\\' the backslash character '\"' the double quote mark '\0' the null character (for MAL, appended to the end of a string to identify the end of the string.)
Directives are a way to give information to the assembler.
In MIPS assembly language (and lots of other ones as well), all directives start with '.' (period)
.byte .word .float .data # identifies the start of the declaration section # There can be more than 1 .data section in # a program. # There will be 1 global location where data # from all .data sections is placed. .text # identifies where instructions are # There can be more than 1 .text section in # a program. .asciiz "a string.\n" # places a string into memory # and null terminates the string. # This is a bunch of characters consecutively # allocated within memory. .ascii "new string." # places a string into memory # WITHOUT null termination.
A label is an identifier. It follows the same rules as those given for identifiers (variable names).
A label identifies a location (an address).
The variable names are labels. Labels (in MAL) should start with a letter of the alphabet ('A'-'Z', 'a'-'z'), and may be followed by other letters, digits or the underscore character ('_'). The syntax for the use of a label places the label first, and follows it with a colon.
Examples of labels that you have already used:
count: .word 0 my_string: .asciiz "Here is my string, ready to go!\n"
Each of these examples associates a human-readable set of characters with an address (assigned by the assembler).
|Copyright © Karen Miller, 2006, 2007, 2008|