Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

May I ask what kind of programing language is used in the following questions? 1

ID: 668853 • Letter: M

Question

May I ask what kind of programing language is used in the following questions?

1. Write an instruction sequence to copy the contents of program memory at 0x2010 to data memory at 0x1030.

Solution:

ldi ZH, 0x20 ldi ZH, high(0x2010)

ldi ZL, 0x10 ldi ZL, low(0x2010)

lpm r0, Z

sts 0x1030,r0

2. You are given the following instruction sequence, what operations are performed?

ldi YH,0x20

ldi YL,0

ldi r16,10

ld r0,Y

sub r0,r16

st Y,r0

ldd r0,Y+5

sub r0,r16

std Y+5,r0

ldd r0,Y+10

sub r0,r16

std Y+10,r0 ; store back to 0x200A (not 0x2010)

Solution:

This instruction sequence subtracts 10 from data memory locations at 0x2000, 0x2005, and 0x200A, respectively.

3. There is a 16-bit number stored at data memory location 0x2000~0x2001. The upper byte is stored at 0x2001 whereas the lower byte is stored at 0x2000. Write an instruction sequence to subtract 20 from this number and stored the difference back to 0x2000~0x2001.

Solution:

lds r24, 0x2000

lds r25, 0x2001

sbiw r25:r24, 20

sts 0x2000, r24

sts 0x2001, r25

4. Write an instruction sequence to subtract the 16-bit number stored at program memory 0x1000~0x1001 from the 16-bit number stored at data memory 0x1000~0x1001. Save the difference at data memory at 0x3000~0x3001. The more significant byte of the number is stored at higher address.

Solution:

ldi ZH, 0x10 ; set Z to point to 0x1000

ldi ZL, 0 ; in program memory

lds r0,0x1000

lds r1,0x1001

lpm r2,Z+

lpm r3,Z

sub r0, r2 ; subtract lower byte

sbc r1, r3 ; subtract upper byte with carry

sts 0x3000,r0 ; save the lower byte of difference

sts 0x3001,r1 ; save the higher byte of difference

Explanation / Answer

1 .The language used here is the assembly language. Infact the first programming language developed.It is also known as low level language/machine level language.

Ldi -> load immediate (which means loading the particular register into the memory)

ZH and ZL are used to initialize the z pointer. And the values in the braces represent the hex address

Sts is used to copy a value to a memory location to define the address.

Lpm is used to to read the fuse and lock bit values.

Hence, the command,

sts 0x1030,r0 means, the content of the register 1 is copied to the SRAM location.

SRAM memories are not directly accessible.

2. LDI YH à load immediate YH and YL are used to initialize the Y pointer.

7

6

5

4

3

2

1

0

The above program is used to subtract a particular number(10) in the registers (0x2000, 0x2005, and 0x200A, respectively.

3. lds r24, 0x2000 means

4.ldi à load immediate register, 0x10, to the pointer ZH (high), and ZL(low) 0

7

6

5

4

3

2

1

0