Lab Proposal
Lab Proposal
Table of Contents
1 Administrivia ............................................................................................................... 2
2 Hardware Resources.................................................................................................... 2
3. Branch Instructions 2 ................................................................................................... 3
1.2 Deliverable
You are required to submit a report including;
1. Source codes with “proper comments” in the beginning
of next lab.
2 Hardware Resources
No hardware implementation or resources are required for this lab.
3. Branch Instructions:
Branch instructions can be divided into two groups.
1. Conditional Branches
2. Unconditional Branches (Jumps)
Syntax
CP Rd, Rs Operands: 0 ≤ d ≤ 31, 0 ≤ r ≤ 31
(Operation: Rd-Rs)
Syntax
CP Rd, K Operands: 16 ≤ d ≤ 31, 0 ≤ K ≤ 255
(Operation: Rd-K)
CP Example CPI Example
cp r4,r19 ; Compare r4 with r19 cpi r19,3 ; Compare r19 with 3
brne noteq ; Branch if r4 <> r19 brne error ; Branch if r19<>3
... ...
noteq: nop ; Branch destination (do error: nop ; Branch destination (do nothing)
nothing)
sum → R16
while (sum < 10) Loop :
{
sum = sum + 1; SUBI R16, −1
} CPI R16, 10
BRLT Loop
; rest of the program
3.4.3. If-Else if-Else
else
{
a = 30;
}
4. Memory Instructions:
The AVR Instructions allows direct access to other locations in the data memory.
4.1. LDS instruction (LoaD direct from data Space)
LDS Rd, K
Task 1:
Write a simple program that takes user input on PinB and output the user data
on PortA.
Task 2:
Using the following table as a guide, write an assembly program that asks the user to enter
an integer test score between 0 and 100. The program should display the appropriate letter
grade:
Task 3:
Write a program that takes input from user on PinB and display the output on PortA
depending on the data input by the user.
1. The default value on PortA is 0.
2. If user inputs a positive value then the value must be incremented on PortA. The value
displayed on PortA will be 1, 2, 3, 4, …
3. If user inputs a negative value then must be decremented on PortA. The value
displayed on PortA will be 255, 254, 253, …
4. Move to Step 2.
Task 4:
Write a program to compute the factorial of number 5 using multiply instruction.
Task 5:
Implement the following arithmetic instructions in assembly:
|32*(5-8)+4-9|
1. Store all the numbers on the following memory locations.
Number Memory Location
32 0x250
5 0x251
8 0x252
4 0x253
9 0x254
2. Evaluate the expression using only two registers R16 and R17. Display the results in
register R16.
3. Check if the result is negative then take the absolute value of result. (Using 2’s
complement method).
(Hint: Use COM Rd instruction to take 1’s complement of the number)