[go: up one dir, main page]

0% found this document useful (0 votes)
168 views9 pages

Computer Architecture Course: IT089IU International University - VNU HCM Date: March 2021 Dr. Le Hai Duong & Dr. Ly Tu Nga Time: 6 hours Trần Minh Duy ITITIU18230

This document provides instructions for a laboratory session involving exercises in MIPS assembly language programming. The exercises include: 1) Writing programs to convert integers to hexadecimal format of varying bit sizes. 2) Writing programs to calculate Fibonacci numbers using iterative loops, functions, and recursion. 3) Analyzing sample code that uses a timer and interrupts on the MSP430 microcontroller to blink an LED. The code is evaluated based on its use of registers, functions, and flow. A comparison is also made between the sample MSP430 code and code from a previous lab that did not use timers or interrupts.

Uploaded by

Duy Tran Minh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
168 views9 pages

Computer Architecture Course: IT089IU International University - VNU HCM Date: March 2021 Dr. Le Hai Duong & Dr. Ly Tu Nga Time: 6 hours Trần Minh Duy ITITIU18230

This document provides instructions for a laboratory session involving exercises in MIPS assembly language programming. The exercises include: 1) Writing programs to convert integers to hexadecimal format of varying bit sizes. 2) Writing programs to calculate Fibonacci numbers using iterative loops, functions, and recursion. 3) Analyzing sample code that uses a timer and interrupts on the MSP430 microcontroller to blink an LED. The code is evaluated based on its use of registers, functions, and flow. A comparison is also made between the sample MSP430 code and code from a previous lab that did not use timers or interrupts.

Uploaded by

Duy Tran Minh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Computer Architecture Course: IT089IU

International University – VNU HCM Date: March 2021


Dr. Le Hai Duong & Dr. Ly Tu Nga Time: 6 hours

Trần Minh Duy


ITITIU18230

Laboratory Session 4
I. Procedure (70pts)

1. Exercise 1: Int2Hex Converter. (45pts)


Write a program that
1.1 Read in ONE unsigned integer in the range 0 to 15. Print out that number in
hexadecimal. For example, given the input 13, print out 0xD. (lab4_1_1.s)

1.2 Modify the previous assembly, create a procedure printHex(int num). This
procedure takes in a number and print it out in hexadecimal. (lab4_1_2.s)
1.3 Modify the previous assembly so that it can print out hexadecimal of any 32-bit
integer input. For example, read in number 546263, print out 0x855D7.
(lab4_1_3.s)

2. Exercise 2: Fibonacci number (25 pts)


The Fibonacci series is defined as:
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...
Each term in the series is the sum of the preceding two terms. So, for example, the
term 13 is the sum of the terms 5 and 8.

2.1 Write the program as a counting loop that terminates when the first 100 terms of
the series have been computed. Use a register for the current term and a register
for the previous term. Each execution of the loop computes a new current term
and then copies the old current term to the previous term register. Print out the
series. (Use no function) (lab4_2_1.s)

2.2 Rewrite the program using function


void fibonacci(int numOfTerms); // this is C prototype

This function print out the Fibonacci series with one input is the number of terms
numOfTerms. (lab4_2_2.s)

2.3 Rewrite the program using recursion. The fib function should compute the nth
term as such: (lab4_2_3.s)

int fib (int N) {


if N > 1
return fib(N – 1) + fib(N – 2);
else
return 1;
}

II. MSP430 (30pts)


Given a sample code to control LED under Timer and interrupt in MSP430 as follows
No Sample codes Comments/Results/Functions
.
1. #include <msp430.h>
2
3 void Configure_Clock(void); Configure clock for system
4 void Configure_Timer(void); Configure timer for system
5 void Configure_IO(void); Configure Input Output for
6 system
7 void main(void) {
8 WDTCTL = WDTPW | WDTHOLD;
9 Configure_Clock(); // Stop watchdog timer
10 Configure_IO();
11 Configure_Timer();
12
13 _BIS_SR(GIE);
14 while(1) //enter global interrupt
15 {
16 _no_operation();
17 }
18 }
19 #pragma vector=TIMER0_A1_VECTOR
20 __interrupt void Timer_A_1(void) // Timer A0 interrupt service
21 { routine Overflow
22 switch(TA0IV)
23 {
24 case 2: break;
25 case 4: break; // CCR1 not used
26 case 10: P1OUT ^=BIT0; //CCR2 not used
27 break;
28 }
29 }
30
31 void Configure_Clock(void)
32 {
33 if (CALBC1_1MHZ==0xFf)
34 { //Clock is 1MHz
35 while (1);
36 }
37 DCOCTL=0;
38 BCSCTL1=CALBC1_1MHZ;
39 DCOCTL=CALDCO_1MHZ;
40
41 BCSCTL2 |=SELM_0;
42 }
43
44 void Configure_Timer(void)
45 {
46 TA0CCR0 =50000;
47 TA0CTL |=TASSEL_2+MC_1+TAIE; // assign the counter of Timer
48 } // assign up mode for Timer
49
50 void Configure_IO(void){
51 P1DIR |= BIT0+BIT6;
52 P1OUT &= ~(BIT0+BIT6);
53 } // turn off all leds

*Evaluation memory allocation:

*Observe the register of Timer0_A3 in Core registers:


Before After Functions
TA0CTL
TA0CCTL0
TA0CCTL1
TA0CCTL2
TA0R
According to the Table above, the objective to Timer 0 is:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
*Observe the register of Interrupt Flag in Core registers:
Before After Functions
P1IFG
P2IFG
According to the Table above, the objective to Interrupt is:
______________________________________________________________________________
______________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________

MIPS of sample code:


No C code MIPS code
.
1.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

According to the Table above, please draw the flow chart via Computer Architecture to call these
functions: Configure_Timer, Configure_IO, Timer_A_1, Configure_Clock
______________________________________________________________________________
______________________________________________________________________________
_____________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Please, compare this sample code without using Timer and Interrupt (Sample code of Lab
1)

Reference:
1. https://en.wikibooks.org/wiki/MIPS_Assembly/Pseudoinstructions
2. https://courses.missouristate.edu/KenVollmar/MARS/Help/SyscallHelp.html
3. https://www.assemblylanguagetuts.com/mips-assembly-programming-
tutorials/#MIPS_Data_Types
4. https://en.wikibooks.org/wiki/MIPS_Assembly/Arithmetic_Instructions
5. https://gab.wallawalla.edu/~curt.nelson/cptr280/lecture/mips%20arithmetic
%20instructions.pdf

You might also like