52 CHAPTER 4. PROGRAMS
pseudo language, I will use a C like syntax
1
. The program we want to write should
be similar to the following C program (since HC11 is essentially an 8-bit micro,
all variables will be unsigned chars to keep things simple).
#include <stdio.h>
unsigned char v1, v2, v3, v4; unsigned char
total; main() {
v1 = 11;
v2 = 0x2F; /* In C prefix 0x denotes HEX */
v3 = ’A’;
v4 = 044; /* In C prefix 0 denotes octal */
total = v1+v2+v3+v4;
printf("%02X", (unsigned) total);
return 0;
}
Compile and run the above program using any C compiler. The output of your
program should be 9F. Now assemble the following HC11 program, and run it to
verify that you get the same answer:
;Name: etc
;
; This program adds 4 numbers and prints the answer.
;
outlhlf equ $ffb2
outrhlf equ $ffb5
org $2000
main
; v1 = 11;
ldaa #11
staa v1
;v2 = 0x2f;
ldaa #$2f
staa v2
;v3 = ’A’;
ldaa #’A’
staa v3
1
This reverses history! C language was invented to avoid writing assembly code!
Komentáře k této Příručce