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

cises E5.1 Write a subroutine that can create a time delay that is a multiple of

ID: 2290970 • Letter: C

Question

cises E5.1 Write a subroutine that can create a time delay that is a multiple of 1 ms. The multiple is passed in register rl6, assuming that the CPU clock is E5.2 Write a subroutine that can create a time delay that passed in r16, assuming that the CPU clock is 16 MHz E5.3 Write a subroutine that can divide a 16-bit signed integer into another 16-bit signed int- eger. The dividend and divisor are passed in registers r16-r17 and r18-119, respectively. The quotient and remainder are returned in r24-125 and r22-123, respectively. E5.4 Write a subroutine that can divide a 32-bit unsigned integer into another 32-bit unsigned inteoer The dividend is passed in registers r16-r19, and the divisor is passed in the stack. The 16 MHz. is a multiple of 10 ms. The multiple is 10

Explanation / Answer

Answer :- The count value will be-

n = 16*10*1000000/1000 = 16000 = 400*400

The subroutine can be written as-

Delay_10ms : Subroutine name

ldi r15, 0x190 ;load 400 in r15

loop1 : ;label name loop1

ldi r14, 0x190 ;load 400 in r14

loop2 : ;label name loop2 starts here

dec r14 ;decrease value in r14 by one

brne loop2 ;jump if not zero goto label loop2

dec r15

brne loop1 ;if not zero goto loop1

dec r16

brne Delay_10ms ; If r16 is not zero then goto start

ret ;return from subroutine