Student Information First Name Last Name School of Computer Science Faculty of Engineering and Computer Science Student ID Number Lab Cover Page Please complete all fields: Course Name: _____________________________________________________ Course Number: _______________ Section Number: ___________________ Lab Date and Time: _________________________________________________ Teaching Assistant to whom you are submitting First Name: ______________________ Last Name: ______________________ Lab Number: _____ Mark Assigned: __________ Notes This (complete) lab exercise should be printed and stapled before coming to lab. All questions requiring a written answer should be answered by writing in the spaces provided in this lab document, and the document should be submitted for marking. Remember to keep this document for study purposes. Also, you will need the signed version of this document if a re-grade or grade correction is requested. 1 Bit-Level Operations and Introduction to Stack Objectives The purpose of this lab is twofold: (1) to look at bit-level operations that process individual bits of a byte, word, or long-word, and (2) to take a first look at how runtime stacks are implemented on the 68000. Upon completion of this lab students will be able to: • Use the basic shift instructions to perform fast bit-level tasks, and • Explain why processors typically support separate stacks for user and system processes. During this lab you will make use of the following 68000 assembly-language programs: • L7_1.x68 • L7_2.x68 To be written by you To be written by you Equipment: In this lab you can either develop the L7_1.x68 on the 68KMB or on the Easy68K emulator. If you chose to use the Easy68K, please note that (1) no official class support is provided for this tool, and (2) you must still demonstrate your code running correctly on the 68KMB. With regards to the latter, please remember that the TRAP instructions on the Easy 68K are implemented differently than on the 68KMB. Also, the 68KMB only has 8K words of RAM starting at hexadecimal address $8000. The second program, L7_2.x68, must be developed on the 68KMB. Part A: Programming Exercise The “Russian Peasant” method of multiplication computes the product of two unsigned numbers by doubling/halving of the factors. The algorithm is described through the example of multiplying 30 x 25. First, put the factors in two columns. On each iteration double the value in column 1 and divide the value in column 2 by 2. The process terminates when the quotient reaches 1. The product is formed by adding the terms in column 1 whose corresponding term in column 2 is odd. Column1 30 60 120 240 480 Column2 25 Add 30 12 6 3 Add 240 1 Add 480 The product of 30 x 25 = 30 + 240 + 480 = 750. 2 (Apparently, real Russian peasants may have tracked their doublings with bowls of pebbles instead of columns of numbers. The ancient Egyptians also invented a similar process thousands of years earlier, and computers are still using related methods today.) Your task is to write a program that implements the Russian Peasant algorithm to perform unsigned multiplication. Assume the two factors (numbers to be multiplied) are 16-bit values stored in data registers D0 and D1, respectively. When implementing your algorithm do not use the 68000’s multiplication or division instructions. Rather, use the (faster) shift instructions when performing multiplication and division by 2. Save your program in H:\2030\L7\L7_1.x68. [10 marks] Part B: Hardware Stacks Review your class notes, handouts on stacks and tracing, and the appropriate stack-related instructions found in Chapter 3 of your textbook before proceeding. To gain a better understanding of the 68000’s two runtime stacks, create the following program (L7_2.x68) and assemble it. RESULT START GENMUL ORG DC.L $9000 0 ORG ANDI.W LEA JSR TRAP $9500 #%1101111111111111,SR $8100,A7 GENMUL #14 MOVE.L MOVE.L MULS MOVE.L MOVE.L RTS END D0,-(A7) D1,D0 D2,D0 D0,RESULT (A7)+,D0 START Figure 1: Program that uses the 68KMB’s user stack (L7_2.x68). Read the previous program carefully, and understand what it does. Then answer the following questions pertaining to the program. 3 1. What does the first instruction do? ANDI.W #%1101111111111111,SR [1 mark] Answer: Before running the program on the 68KMB you should press the reset button to ensure that the board is in supervisor mode (i.e., the S-bit = 1). 2. Execute the program according to the instructions that follow: a) Load D0, D1, and D2 with $12345678, $9ABCDEF0, and $0FEDCBA9, respectively. b) Execute the program up to (but not including) the JSR instruction. What are the contents of the US register? What is this value referring to? [1 mark] Answer: c) Execute the JSR instruction with a trace command. What instruction is to be executed next? What does it do? [1 mark] Answer: d) What are the contents of A7, US, SS immediately after the JSR instruction executes? Why is A7 equal to SS? [1 mark] Answer: e) What do the contents of these registers signify? [1 mark] Answer: f) Execute the next instruction. What are the contents of US and why? [1 mark] Answer: g) Display the contents of the 8 bytes at the top of the user stack. What do these bytes represent? [1 mark] Answer: 4 h) Display the contents of the 8 bytes at the top of the system stack. What do these bytes represent? [1 mark] Answer: i) Execute the next three instructions. What result is in D0? [1 mark] Answer: j) Execute the next instruction. What gets loaded in D0 and what is the value contained in the US register? [1 mark] Answer: k) Run the program to completion with a GO command. What are the contents of the D0, D1, D2, and US registers afterwards? [1 mark] Answer: l) What value gets stored at RESULT? [1 mark] Answer: Having completed this lab you should have a basic understanding of the operation of shift instructions and how they can be used, as well as a basic understanding of the two runtime stacks (user and system) employed by the computer. Next time, we will see how the C programming language uses these stacks to implement function calls. 5
© Copyright 2026 Paperzz