Tải bản đầy đủ (.pdf) (12 trang)

Tài liệu Lab LC3 C pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (43.5 KB, 12 trang )


MODERNIZED PROGRAM
INTRODUCTION TO COMPUTING SYSTEM COURSE
LC3 & C PROGRAMMING LAB
REQUIREMENTS
Present at lab room on time.
Create a subdirectory studentname_code in the D:/Clabs directory and save all
your files inside it.
You can create further subdirectory labn , n =1..5 is the lab index.
Try to do all questions step by step.
Show all your results to TA at the end of the lab.

LAB 0:
EDITING, COMPILING, AND SIMULATING LC3 PROGRAMS
Exercise 1
Write and simulate a program using the LC-3 Assembly language:
- Input 1 lowercase ASCII letter (between ‘a’ and ‘z’)
- Change lowercase ASCII letter to uppercase ASCII letter.
- Output them on screen.
Exercise 2
Write and simulate a program using the LC-3 Assembly language:
- Input 1 characters (between ‘A’ and ‘Z’) and 1 positive number (between 0 and
9).
- Output them on screen.
Exercise 3
Write and simulate a program using the LC-3 Assembly language:
- Input 3 bits A, B and C.
-
BCAD +=

- Output the result on screen.


Exercise 4
Write and simulate a program using the LC-3 Assembly language:
- Input 2 unsigned integers (between 0 and 9).
- Compute the summation between these numbers.
- Output the result on screen.
Exercise 5
Write and simulate a program using the LC-3 Assembly language:
- Input 2 unsigned integers (between 0 and 9).
- Multiply two positive numbers.
- Output the result on screen.
Exercise 6
Write and simulate a program using the LC-3 Assembly language:
- Input 2 unsigned integers (between 0 and 99).
- Compute the summation between these numbers.
- Output the result on screen.
Exercise 7
Write and simulate a program using the LC-3 Assembly language:
- Input 2 unsigned integers (between 0 and 99).
- Compare these numbers.
- Output the result on screen. (Ex: “The result is: 54 > 37”)
LAB 1:
EDITING, COMPILING AND RUNNING C PROGRAMS
Exercise 1
Open the sample program intro.c
in the C editor window by means of running the
executing file: TC.exe. You must do the lab in the DOS OS with the blue screen.
Explain the purpose of this C text.
Remove the closing symbol } from the C text of the program intro.c and compile it
again. Explain the result. Now restore the removed symbol and replace identifier main
with main_program. Can you compile and run the program now? At what stage do

things go wrong and why?
Restore the correct name of the main function. Modify the program so that it works in
centimeters rather than in inches. Now make it take the radius value in centimeters but
display the result in square inches. One inch is 2.54 centimeters.
Modify the program so that it can do the inverse process, area is the input and radius is
the output. You must check all cases of the input (in centimeters).
Exercise 2
Compile the program sqrt.c
. Note the error message you receive.
This links in the math library in which the sqrt function is defined. How can you link
the math library to your program? Run the program and input a few different numbers.
What happens when the input number is negative? Try to treat this situation.
Exercise 3
Compile and run the following programs. See how much of the program text you
understand and check the output result with some inputs.
define.c

overflow.c

sizes.c

anatomy.c

Explain the purpose of these programs.
LAB 2: BASIC OPERATORS AND INPUT/OUTPUT
Exercise 1
Compile and run the program floatari.c
. Modify it to get results with more decimal
digits than you get from the original version.
Modify the program prepost.c

to eliminate all operators ++ and -- while keeping the
results unchanged. What is the point of having ++ and -- in the language?
Compile and run the program relation.c
. Replace b - a == b – c with a = b
– c everywhere in the program, run it again and explain what happens.
Correct mistakes in the following programs (we call these files the bug files):

intarit1.bug.c

intarit2.bug.c
Exercise 2
Have a look at the program putchar.c
. Can you achieve the same result any easier?
Try your method and make sure that the output stays the same. Why do we need function
putchar at all?
Modify the program puts.c
so that it contains only one call to an I/O function instead
of 13 separate calls to puts. Your program should still feature the same 13 separate
strings, and its output should coincide with the output of the original program in every
detail. Now achieve the same result by calling just one I/O function and passing it just
one parameter.
Exercise 3
Compile and run the program scanf.c
. Do you understand the role of function
scanf? Can you read two integer numbers by one call to scanf? What about one
integer and one real number in one go? Check whether your method actually works.
Find out what happens when you enter a letter while scanf expects a number.
Write a program that reads and displays one integer number. Denote this number with x,
so that your program contains the statement
scanf("%i",&x);

Now replace this statement with the following one:
x = scanf("%i",&x);

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×