Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need some help with code assembly for attiny 1 6 2 6 . I cant seem to do ex 2 . 1 and 2

I need some help with code assembly for attiny1626. I cant seem to do ex2.1 and 2.8
.section .init0
entry:
ldi r16,0xFF
mov r1, r16
ldi r22,0x10
ldi r16,0xCC
mov r4, r16
// DO NOT EDIT ABOVE THIS LINE //
// WARNING:
//
// Do not modify the data in the following registers unless
// specified by the exercise:
//
// R1(Ex 2.1)
// R4(Ex 2.9)
// R20(Ex 2.2)
// R22(Ex 2.6)
// Ex 2.0
//
// Write assembly code to add the numbers 53 and 34 together and
// store the result in register R0.
//
// Hint:
// Recall the "ldi" instruction loads a value into a register, and
// the "mov" instruction copies a value between registers.
ldi r16,53 ; Load 53 into r16
ldi r17,34 ; Load 34 into r17
add r16, r17 ; Add r17 to r16
mov r0, r16 ; Move the result to r0
// Write your code for Ex 2.0 above this line.
mov r16, r0
call avremu_r16out
// Ex 2.1
//
// Using the "and" instruction, clear only bits 2,3, and 7 of R1.
mov r16, r1 ; Copy the value of R1 to R16
; Use an "and" instruction to clear the desired bits in R16
andi r16,0b10001100 ; Clear bits 2,3, and 7 in R16
mov r1, r16 ; Move the result back to R1 if necessary
// Write your code for Ex 2.1 above this line.
mov r16, r1
call avremu_r16out
// Ex 2.2
//
// Using the "ori" instruction, set only bits 1,3, and 5 of R20.
ori r20,0b00101010
// Write your code for Ex 2.2 above this line.
mov r16, r20
call avremu_r16out
// Ex 2.3
//
// Using exactly one instruction, add 1 to the value of R0.
//
// Hint:
// You can find a full list of arithmetic instructions summarised
// in Table 5-2 of the AVR Instruction Set Manual.
inc r0 ; Increment the value in r0 by 1
// Write your code for Ex 2.3 above this line.
mov r16, r0
call avremu_r16out
// Ex 2.4
//
// Write assembly code to add 44 to 14685, storing the result in
// register pair R31:R30(low byte in R30).
ldi r31,0x39
ldi r30,0x5D
adiw r30,0x2C
// Write your code for Ex 2.4 above this line.
mov r16, r30
call avremu_r16out
mov r16, r31
call avremu_r16out
// Ex 2.5
//
// Follow the steps below to complete this exercise.
//
// Step 1: Encode the decimal value -4 as a two's complement, 8-bit number.
// Step 2: Write down the result of Step 1 as a hexadecimal literal.
// Step 3: Swap the two nibbles of the hexadecimal literal you wrote in Step 2.
// Step 4: Load the result of Step 3 into register R21.
ldi r21,0b11001111 ; Load the high nibble (1100) into r21
// Write your code for Ex 2.5 above this line.
mov r16, r21
call avremu_r16out
// Ex 2.6
//
// Write assembly code to subtract the value in R22 from 91 using
// the "add" instruction, storing the result in R23.
ldi r16,91 ; Load 91 into r16
sub r16, r22 ; Subtract the value in r22 from 91 and store the result in r23
mov r23, r16 ; Move the result to r23
// Write your code for Ex 2.6 above this line.
mov r16, r23
call avremu_r16out
// Ex 2.7
//
// Write assembly code to multiply the number 20 by 2 using the
//"lsl" instruction, storing the result in R2.
ldi r16,20 ; Load the value 20 into R16.
lsl r16 ; Multiply R16 by 2 using the "Logical Shift Left" instruction.
mov r2, r16 ; Copy the result from R16 to R2.
// Write your code for Ex 2.7 above this line.
mov r16, r2
call avremu_r16out
// Ex 2.8
//
// Write assembly code to divide the number -37 by 4 using the "asr"
// instruction, storing the result in R3.
ldi r16,0xDB ; Load -37 into r16(two's complement)
asr r16 ; Arithmetic shift right to divide by 4
mov r3, r16 ; Move the result to r3
// Write your code for Ex 2.8 above this line.
mov r16, r3
call avremu_r16out
// Ex 2.9
//
// Write assembly code to toggle the most significant bit, and least
// significant 4 bits of R4.
ldi r16,0x80 ; Load a mask with the most significant bit set (binary: 10000000)
eor r4, r16 ; Toggle the most significant bit of r4
ldi r16,0x0F ; Load a mask with the least significant 4 bits set (binary: 00001111)
eor r4, r16 ; Toggle the least significant 4 bits of r4
// Write your code for Ex 2.9 above this line.
mov r16, r4
call avremu_r16out
// END OF TUTORIAL02 EXERCISES //
// DO NOT EDIT BELOW THIS LINE //
ldi r16,0x22// DISP_EN (PB1)| DISP_DP (PB5)
sts 0x0420, r16// Set as outputs
sts 0x0424, r16// Drive high
break
ldi r16,0x20// DISP_DP (PB5)
ldi r17,0x00
loop:
// Delay
com r17
brne loop
inc r18
brne loop

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions

Question

What is Responsibility Accounting ?

Answered: 1 week ago