bases dword 2,3,6,9,4

exponents dword 7,5,3,2,3

termindex dword 0

P.S don't forget to put count and total in.

Now I'm going to talk about a new word............consecutive. Consecutive means things come right after each other. You notice that in bases and exponents there are numbers just all together in a line? Well how consecutive go's in with this is that the 1st number is in the 1st 4 bytes and the next number is in the next 4 bytes so on so on. Her'es my program that uses memory to get rid of the redundancy and simplify the process.

.model flat, c

.stack 100h

.data

count dword 0

total dword 0

bases dword 2,3,6,9,4

exponents dword 7,5,3,2,3

termIndex dword 0

.code

doit proc

restart:

mov eax,4

mul termIndex

mov ebx,eax

mov ecx,bases[ebx]

mov ebx,exponents[ebx]

call raiseToThePower

add total,eax

inc termIndex

cmp termIndex,5

jl restart

ret

doit endp

raiseToThePower proc

mov count,0

mov eax,1

again:

mul ecx

inc count

cmp count,ebx

jl again

ret

raiseToThePower endp

end

Now I'm going to explain how this program is running through. Well the first few lines are what I'm going to talk about first (because they're the FIRST few lines),you see there's mov eax,4 then mul termindex,and what that's doing is there are 4 bytes in between the different numbers so there there needs to be a 4 in termindex at 1st nothing happens because termindex is a 0 and the first 2 numbers are right there but you see how there's an inc termindex at the end of the doit procedure? Well that means that termindex will be a 1 so when we come around to the beginning of the loop it does that again and walla! We skip 4 bytes to the next number.

So you see how the numbers go down in a row? The top 5 numbers are the bases and the next 5 are the exponents. And you see how there are 3 sets of 0's (bytes) before the next number? Well the number counts as 1 so all together that makes 4 bytes.

Now I'm going to talk about something called byteswapping. What byteswapping is is the way memory show's number's. It shows the numbers backward's. The reason for that is because of the way memory uses big endian and little endian. When you use big endian you store the most significant byte in the smallest address. When you use little endian it's the other way around you store the LEAST significant value in the smallest address.

If you want to learn more go to this address: http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Data/endian.html

Have you ever heard of an alias? It's like a fake name,example: You know how Dr.Seuss puts the name Theo lesieg on his books? That's an alias. I bet your wondering what does any of this have to do with what we're doing? Well I'll answer that question. You know these names that we're using for R.A.M such as termindex and count? They're aliases for ram addresses. But you know how bases and exponents have several numbers? The first number is the only one with an exact alias so to get to the other numbers you need to termindex into them.

When will you start making videos? I am enjoying this!

ReplyDeleteA Fan,

-Abdulmajid Alnouri