11/2/04
A couple of the TAs have shown the students in their
discussion sections a shortcut regarding use of the ascii code to move the
cursor to a new line.
There is no question that what they have shown their students will be
useful later on -- as indeed most things that do some of the work for you
are useful.
It is called productivity enhancement, and is great AFTER you are sure
you understand what is going on underneath. BUT, before you are sure you
understand, invoking this kind of magic can get in the way of
comprehension, and do you a disservice in the long run.
So, to put everyone on the same level playing field, I will explain the
construct, and then strongly suggest you do not use it -- although if you
do use it, the work will be easier but the comprehension perhaps less
secure.
So, moving along ...
You all know that to get the monitor electronics to move the cursor to
a new line, you need to put the ascii code for linefeed (x0A) into the
DDR. Then the electronics takes over, and voila! The cursor moves to the
left column of the next line. A simple way to accomplish this (which we
covered in class today, Monday):
Suppose you wanted to write to the screen:
You need a line feed after the "u" in "you."
I would expect you to do this in four steps:
followed by the routine we did in class today (Monday) in which we
first loaded the starting address of the string (The Eyes of Texas are
upon you) into a Base Register and then wrote the string to the screen.
Then another linefeed using
followed again by the same routine we did in class today, only this
time with LEA loading the address of the string (All the live long day).
Two of the TAs showed their discussion sections how to do the whole job
with one string:
A good Assembler would place the ascii code for each letter into the
next corresponding location in the object file being assembled. When the
assembler came to the character "\" it would combine the "\" with the "n"
to form what we call a special character, in this case the ascii code for
linefeed, and insert x000A into the next correspoding location.
Thus if the address of ALL was x3050, for example, the assembled
program would contain the code fragment:
I strongly prefer that you not do it this way THIS semester, since it
gets in the way of your total comprehension. The Assembler is recognizing
the two character code "\n" as a special charater meaning "linefeed" and
inserts the correct ascii code (x0A) into the string to cause a linefeed
to occur.
Certainly in the future you will use the short cut, having the
assembler put the linefeed ascii code into the string because as shown
above, it reduces the four fragments of code to one, indeed saving work.
But right now we are all about total understanding, and short cuts often
get in the way.
Good luck,
Yale Patt LD R0, LINEFEED
TRAP x21
...
...
LINEFEED .FILL x000A
The Eyes of Texas are upon you
All the live long day
(1) LD R0, LINEFEED
TRAP x21
(2) LEA R1, FIRST
...
...
FIRST .STRINGZ "The Eyes of Texas are upon you"
(3) LD R0, LINEFEED
TRAP x21
(4) LEA R1, SECOND
...
...
SECOND .STRINGZ "All the live long day"
ALL .STRINGZ "\nThe Eyes of Texas are upon you\nAll the
live long day"
x3050: 000A
x3051: 0054
x3052: 0068
x3053: 0065
x3054: 0020
x3055: 0045
x3056: 0079
x3057: 0045
x3058: 0073
x3059: 0020
x305A: 006F
... ...
x306C: 0079
x306D: 006F
x306E: 0075
x306F: 000A
x3070: 0041
x3071: 006C
x3072: 006C
x3073: 0020
x3074: 0074
... ...