Download presentation
Presentation is loading. Please wait.
2
1 Lab Session-IV CSIT-120 Spring 2001 Lab 3 Revision and Exercises Rev: Precedence Rules Lab Exercise 4-A Machine Language Programming The “Micro” Machine The “Micro” Simulator Lab 4 Continued
3
Rev: Increment Operator In Experiment 3.2, we have seen the use of the unary increment operator ==> number++; i++ Similarly we have a unary decrement operator ==> number--, i-- Instead of number=number-1;
4
Rev: ASCII and UNICODE The alphabets and digits are represented by integer values and this mapping is called a code ASCII code was originally 7 bits (128 values) Values from 00 to 1F were reserved for special non-printable control characters
5
Rev: ASCII and UNICODE For example, trying to print ASCII code 7 will ring a bell on the computer Example: cout<< “\7” To print spaces cout<<“\t” Up from 20 are the uppercase, lowercase letters and digits alongwith punctuation marks
6
Rev: ASCII and UNICODE ASCII was not sufficient as more symbols were needed ASCII was revised to be “Latin-1”, an 8-bit code that can have 256 symbols Latin-1 can cover some European languages Computers are being used all over the world A unified coding system was needed
7
6 Rev: ASCII and UNICODE A consortium developed a standard code called UNICODE. This code has 16 bits, thus 65,536 code points are possible World languages have 200,000 symbols so all cannot be accommodated Values from 0 to 255 map to Latin-1 or ASCII so changes are not felt in English
8
7 Rev: ASCII and UNICODE UNICODE allocates code points to languages in an “official” way Number of code points given is more than the letters in each language to accommodate different forms of each letter Adding new words in English e.g. applets does not require new code points but adding new words in Japanese requires new points
9
8 Rev: Uncover the ASCII code Experiment 3.5 Why do we include ? What is toascii? What is toupper? What is tolower? (HINT: Use these functions in your program to find out)
10
9 Rev: Simple Encryption Techniques Once you are able to process a text string, you can convert the characters to their ASCII values The ASCII values are numeric. You can modify these values so that no one can understand what is in the string Exercise 3-C Take a character from the user, add 8 to it and print it. (DEMO)
11
10 Rev: Mixing Arithmetic Operations When we try to perform several arithmetic operations in one expression, the expression becomes quite complex For example, consider the following Q = (A+B*C)(A+B/C) Q = ((A+B)*C)((A+B)/C)??? OR Q = (A+(B*C))(A+(B/C))???
12
11 Rev: Using Precedence Rules We can use the precedence rules to get an expression evaluated as per our needs Following are the precedence rules in C++ for arithmetic operations Highest Priority is given to () (parenthesis) Multiplication (*) and Division (/) take precedence over addition (+) and subtraction (-) Assignment (=) is done at the end We should use parenthesis to make the expression clear
13
12 Lab Exercise 4-A (Demo Required) Develop a program that asks the user to input the daily snowfall totals (in inches) for the last week of February in Chautaqua county. Your program then calculates and displays the average snowfall per day during the week.(BONUS FLAG: All calculations are done in one single statement)
14
13 Machine Language Programming All programs written in C++, Java or any other user-level language are translated to the machine language after compilation Look at an example that shows how a C++ program line will be converted to the machine language
15
14 C++ Program My_var = this_data+next_data Compilation and Linking 0001010100111111//Load R5 from Memory 0001010000111110//Load R4 from Memory 0110011001010100//Add R4,R5 & store result in R6 0011011000111101//Store R6 into Memory The Compilation of Programs
16
15 Machine Language Programs A compiled and linked program is a series of machine language instructions and data Each processor has its own set of machine language instructions Can programs compiled for Pentium II run on Alpha workstation?
17
16 The “Micro” Machine The Micro Machine has >256 Memory cells, each cell can hold 1 byte >Memory addresses range 00-FF (two digits) >16 General Purpose Registers >Register addresses range 0-F (one digit) >Program Counter and Instruction Register >12 Machine Language Instructions (1-C)
18
17 The “Micro” Simulator The “Micro” Simulator is a C++ Program Download this program by visiting “The Micro” link in the labs webpage of the course Click on “micro” to download or cut & paste this program and save as a C++ file Double click on this file to run Visual C++ Compile and run the program
19
18 The Micro Simulator The full screen display shows the contents of the memory from cell 00 to cell FF It also shows contents of registers R0 through R15 PC and IR contents are visible too The machine has several single-letter commands (4-A): Experiment 4.1 (PC incr?)
20
19 The Instructions of “Micro”
21
20 Lab-4 Continued The Micro Machine and its Simulator An example program Exercises The JUMP instruction and its usage Experiment 4.4
22
21 Micro and its Simulator What is the memory size in Micro? How many instructions are there? How can we start executing a program in Micro? What is the difference between S and G commands?
23
22 How to Program the Micro Let us walk through an example to learn how to program the Micro EXAMPLE: Write a program in Micro to add numbers stored in R1,R2 and R3 together and leave the result in R4 This program will have two parts. The initialization part will store the values in registers and then the program will perform the desired operation
24
23 Example INITIALIZATION //Move 5 into R1, (2RXY ==> 2105) //Move 8 into R2 (2RXY ==> 2208) //Move 7 into R3 (2RXY ==>2307) ACTUAL ADDITION //Add R1 and R2 and store the result at temporary location R5 (5RST ==>5512) //Add R5 and R3 and store the result in R4 (5RST ==> 5453) //Stop the program (HALT C000)
25
24 Example Program in Hex code 2105 2208 2307 5512 5453 C000
26
25 How to load the program? You cannot run your program until it is loaded in Micro’s memory Divide the memory into two equal blocks. First block should be reserved for data and second block for programs. Since the memory is 256 bytes (numbered from 0 to 255) exactly byte 0 to byte 127 are to be reserved for data
27
26 How to load the program? Byte 128 onwards can be used for loading the programs Byte 128 has the binary address 1000 0000 It can be expressed in Hex as 80 Type M and give starting address as 80 When entering your program, only two digits can be stored in each memory location
28
27 How to run the program? Before running the program, you have to set the Program counter to point to the first instruction in the program Select P and enter 80 Run the program all at once by typing G or one step at a time by typing S Do both one by one (First S then G)
29
28 The Power to Simulate The Micro Simulator can run programs designed by you too Lab Exercise 4-B Design a program that adds numbers 1 through 5 together and leaves the result in register R9. (DEMO REQUIRED) (DATA SHOULD BE IN MEMORY OR REGISTERS) (4-C) Experiment 4.2
30
29 JUMP Instruction JUMP instruction is provided to facilitate the implementation of loops and branches Its format is B RXY (JUMP RXY) It means “jump to location XY if R=R0 Unconditional jump if R0 compared to itself Experiment 4.4
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.