What mathematical function do ASR and ROR perform?
For instance I have a two registers for storing a value of 2bytes (R5:R4)

then I use

SomeProcedure:
	mov		r20, r2

	clr		r3
	clr		r4
	clr		r5

	cpi		r20, 0
	brge	ProcLoop

	neg		r20
	com		r3

ProcLoop:
	cpi		r20, 0
	breq	ExitLoop

	add		r4, r2
	adc		r5, r3

	dec		r20
	rjmp	ProcLoop

ExitLoop:
	asr		r5
	ror		r4
	ret

;then write the result to the data memory R4:R5
rcall	SomeProcedure
st x+,r4
st x+,r5

The first part of program is to square the input value (input = r3)
I have chosen several values for R5:R4, but they do not make sense
For example (all in decimal)
choose R3=2, then result = 512 = 128*(2^2)
choose R3=3, then result = 1024 = 64*(3^2)
choose R3=4, then result = 2048 = 128*(4^2)
choose R3=5, then result = 3072 = ????

I know that in the hex value, whatever the program get after getting the square of input value into R5:R4, then the program does R5/2:R4/2 then change the position of R5 and R4 into new R4:R5 as the output .

Recommended Answers

All 2 Replies

> The first part of program is to square the input value (input = r3)
What about r2?

thank you Salem, I figured out what was wrong, the program had a small mistype that why I could not see the result make sense.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.