New at this, trying to create an accumulator or totalizer..not sure if thats the
ID: 3719367 • Letter: N
Question
New at this, trying to create an accumulator or totalizer..not sure if thats the
right term. basically if I have a 4 bit register that equals 0000, i want to add
a four bit number to it, retain that new value...then add another number to it
rinse repeat. So...first register value is 0, then add one to it so the new value is one,
add then add two to the new value and it becomes three..etc.
Not sure how to do something like that....any help would be great..
Trying to use logism to do this...thanks!
Explanation / Answer
Hi,
Find the code below:-
MOV A, #0
MOV R2, #1
MOV R3, #10
AGAIN :
ADD A, R2
ADD R2, #1
DJNZ R3, AGAIN
MOV R5, A
Here, MOV A, #0, MOV R2,#1 and #1MOV R3, #10 are moving 0 to accumulator, 1 to R2 and 10 to R3 respectively. A is accumulator register and initially 0 is being put into it. Then we have, R2 initialized with 1, to add it to Accumulator and R3 is the number of time the iteration will take place or the number of times loop will iterate.
Then we define the loop named AGAIN where we add R2 to Accumulator and store it in Accumulator and then increment the R2 by 1.
DJNZ i.e. Decrement and Jump if register R3 not equal to 0 i.e. repeat AGAIN loop till R3 not equal 0 and decrease it by 1 in each iteration.
Finally, MOV R5, A i.e. store the result in R5.
Hope this will help you !!! Thanks!!!!:)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.