^{1}+ 3

^{2}+ 3

^{3}+ ... 3

^{n}

^{}

3

^{2}= 3 x 3
3

^{3}= 3 x 3 x 3
3

^{4}= 3 x 3 x 3 x 3
3

^{5}= 3 x 3 x 3 x 3 x 3
3

^{6 }= 3 x 3 x 3 x 3 x 3 x 3
3

Now I'm going to tell you which registers are doing what while this is all going on. R.A.M tracks the power of 3 which is how many 3's are being multiplied. Ecx is tracking the base which is 3. Ebx is tracking the SUM or total. And as for edx it is not doing anything because as I said before edx wouldn't work. As for R.A.M it takes over for edx as the power of 3.

Here is a chart I made to track everything for each iteration:

And here's the program.

.model flat, c

.stack 100h

.data

powerof3 dword 1

count dword 0

.code

doit proc

mov ecx, 3

mov ebx, 1

again:

; Raise to the next power of 3

mov eax, powerof3

mul ecx

mov powerof3,eax

inc count

; Multiplying the power of 3 and the sum

mov eax,powerof3

mul ebx

mov ebx,eax

; Raising to the next power of 3

mov eax,powerof3

mul ecx

mov powerof3,eax

inc count

; adding the sum and the power of 3

add ebx,powerof3

; Repeat if neccesary

cmp count,5

jl again

^{2 }is a short way of saying 3 x 3,3^{3}is a short way of saying 3 x 3 x 3 etc. SUM is the total of adding the 2 powers together. If you go high enough going up power by power you will get HUGE amounts of overflow so much in fact the amount in R.A.M is nothing compared to the real answer. Sometimes when you are doing a big enough problem you have to use R.A.M because edx doesn't cooperate because when you do multiplication it tells you what you didn't use. So you gotta use R.A.M instead. If you don't know what ram is you should read my earlier blogs.Now I'm going to tell you which registers are doing what while this is all going on. R.A.M tracks the power of 3 which is how many 3's are being multiplied. Ecx is tracking the base which is 3. Ebx is tracking the SUM or total. And as for edx it is not doing anything because as I said before edx wouldn't work. As for R.A.M it takes over for edx as the power of 3.

Here is a chart I made to track everything for each iteration:

As you can see I have shown you what is in R.A.M,and ebx,and I have written down what ecx,eax,and edx are doing.

And here's the program.

.model flat, c

.stack 100h

.data

powerof3 dword 1

count dword 0

.code

doit proc

mov ecx, 3

mov ebx, 1

again:

; Raise to the next power of 3

mov eax, powerof3

mul ecx

mov powerof3,eax

inc count

; Multiplying the power of 3 and the sum

mov eax,powerof3

mul ebx

mov ebx,eax

; Raising to the next power of 3

mov eax,powerof3

mul ecx

mov powerof3,eax

inc count

; adding the sum and the power of 3

add ebx,powerof3

; Repeat if neccesary

cmp count,5

jl again

## No comments:

## Post a Comment