54 CHAPTER 4. PROGRAMS
char v;
char total;
main() {
v = 0;
total = 0;
v = v+1;
total = total + v;
v = v+1;
total = total + v;
v = v+1;
total = total + v;
v = v+1;
total = total + v;
v = v+1;
total = total + v;
printf("%02X", (unsigned) total);
return 0;
}
2. Modify the program so that the initialization v = 0 is replaced by a call to
getchar(). Run your C program and try different inputs at the keyboard.
Make corresponding changes to the assembly language program and verify
your results.
3. Modify the assembly language program so that you use a counting loop to
loop 5 times over the basic code.
4. Modify the previous version (using a loop) where the number of times around
the loop is in an 8-bit variable called count. Your program should initialize
the variable to 5 so that the loop is executed 5 times.
5. A convenient way to get a value between 0 and 9 from the user is to use the
instruction sequence
jsr inchar
Kommentare zu diesen Handbüchern