EE234_hw02_Sol_24S

.docx

School

Western Washington University *

*We aren’t endorsed by this school

Course

234

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

docx

Pages

3

Uploaded by zerogaming0723

Report
EE234 Homework 2 Due : 02/02/2024 (Thursday) Save your answer in word format and using the file name EE234_HW2_LastName_FirstName 1. Write an instruction sequence to subtract the 16-bit value stored at program memory 0x1050~0x1051 from the sum of two 16-bit values stored at program memory 0x1060~0x1061 and 0x1070~0x1071. Store the result at data memory 0x2000~0x2001. Solution: ldi ZL,0x60 ldi ZH, 0x10 lpm r0, Z+ lpm r1, Z ldi ZL, 0x70 ldi ZH, 0x10 lpm r2, Z+ lpm r3, Z add r0, r2 adc r1, r3 ldi ZL, 0x50 ldi ZH, 0x10 lpm r4, Z+ lpm r5, Z sub r0, r4 sbc r1, r5 sts 0x2000, r0 sts 0x2001, r1 2. Write an instruction sequence to multiply the 16-bit unsigned value stored at program memory 0x1050~0x1051 and the 16-bit value stored in r5~r6 register pair and store the product in data memory from 0x2020~0x2023. Call the subroutine mul16U to perform the multiplication. Solution: ldi ZL, 0x50 ldi ZH, 0x10 lpm r16, Z+ lpm r17, Z mov r18, r5 mov r19, r6 call mul16U sts 0x2020, r22
sts 0x2021, r23 sts 0x2022, r24 sts 0x2023, 0xr25 3. Write a program to read every element from an array in program memory (with the label sarr ), set bit 7, clear bit 6, and set bit 2, and then store the result in data memory (starting from 0x2000). The array elements are 8-bit. The array has 30 elements. Solution: .include <atxmega128A1Udef.inc> .equ sbMask = 0x84 .equ cbMask = 0x40 .equ NN = 30 .def lpCnt = r19 .dseg .org 0x2000 .byte 30 .cseg .org 0x00 jmp start .org 0xFA start: ldi ZL, low(sarr << 1) ldi ZH, high(sarr << 1) ldi XL, 0 ldi XH, 0x20 ldi lpCnt, NN clr cnt loop: lpm r16, Z+ sbr r16, sbMask cbr r16, cbMask st X+, r16 dec lpCnt brne loop here: jmp here sarr: .db 0x11, 0x12, 0x13, 0x14, 0x15, ox16, 0x17, 0x18, 0x19, 0x20 .db 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30 .db 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help