?
Solved

Subroutine in assembply language

Posted on 2009-04-27
70
Medium Priority
?
406 Views
Last Modified: 2012-05-06
I attached a file with all the details .
27-04-2009-12-34-44.JPG
0
Comment
Question by:hnael
  • 36
  • 34
70 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 24240744
And what's your question ?
0
 

Author Comment

by:hnael
ID: 24241016
My question If possible to answer the questions from (a) to (e) which the question is asking in simple way so that  can understand how this program is working ? pls .
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24241114
I'm afraid EE won't solve your assignments for you. What we can do however, is guide you, and answer specific questions.

So, if you tell us what you tried, where you are stuck, etc., we'll be able to assist you.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:hnael
ID: 24241252
thats fair enough , I will send the answer I managed to solve and see what you think ? is that acceptable , I am going mad with this assembly , its really hard to understand , at least thats how I see it , ok one question pls can you explain what the stack and what the stack pointer is other than a place where the main program remeber to go to when it run the call instruction.thank you .
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24241468
>> is that acceptable

Definitely. I'll have a look at what you posted, and give you my comments.


>> ok one question pls can you explain what the stack and what the stack pointer is other

The stack is a region in memory where all local variables, function arguments, call return addresses etc. are saved.

For each function call, a stack frame is set up and added to the top of the current stack. That stack frame contains among other things the return address (where the execution should continue once the function ends), the local function variables, as well as saved registers (in case their value has to be placed back when the function ends).

If, at any time, you walk through the stack from bottom to top, you'll find the stack frames for all current nested function calls. You could see the stack as the current state of the execution.

The stack pointer simply points to the current top of the stack (ie. where the push and pop operations are done).
0
 

Author Comment

by:hnael
ID: 24241574
thks for the explanation , will stay in touch as soon as I mange to solve the question (if I can) , also pls be patient as these things take lots of thinking and time consuming as well .
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24241954
No problem. Don't hesitate to ask for (specific) help if you're stuck somewhere, or are unsure about something. I'm not allowed to solve the assignment for you, but I can give helpful tips and hints, as well as answer specific questions ;)
0
 

Author Comment

by:hnael
ID: 24242066
I am really grateful , I just can not get my head round it at the moment , I invest lots of hours with the simulator I got to understand the stack but still unable to grasp what it exactly do and unless I do I can not move one step ahead I feel depress ..at the moment , write If I attach apic for some activitis I captured with the simulator and pose question on that will that be ok .(its activities not assignment or thing like that ).?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24242474
>> I got to understand the stack but still unable to grasp what it exactly do and unless I do I can not move one step ahead

The image you posted is not for a question directly related to the stack, so even if you don't fully understand what the stack is and how it works, that shouldn't prevent you from answering the questions there.


Do you know the concept of a stack (LIFO) data structure ?
0
 

Author Comment

by:hnael
ID: 24243340
I do remember that what put in first retrieved last and vice versa I think ?  Am I correct?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24243373
Yes, compare it to a stack of papers on your desk. You add new papers on top of the stack, making the stack grow, and you take the top-most paper off of the stack, making the stack shrink. LIFO = last-in-first-out.

The stack in this case is exactly the same : it grows in one direction (increasing in size whenever a function is called or local variables are allocated, or ...), and then shrinks again (when returning from a function, etc.)
0
 

Author Comment

by:hnael
ID: 24243472
waw I love you for this explanation now I understand much better the horrible stack thingee . you r really good in this I have to say , but do you really use the assembly in real world ?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24243583
>> but do you really use the assembly in real world ?

Sure, for certain parts of certain projects.

The most important thing is however, that you gain a better understanding of how a computer works by learning assembly, and that's something you can use in all domains of computer science.
0
 

Author Comment

by:hnael
ID: 24243685
cool , I am learning great deal about the processor now and I do understand lots of things but its some how complicated and the connection it seems as if u r in a dark tunnel , but I will never give up to understanding it , eg. we know thats inforamtion does not stop b/n main memory and processor so if I ask where is the first instruction starting who initiate it first ?what your answer will be , by the way this is not at all exam questions or anything like that , just question from my head .
0
 

Author Comment

by:hnael
ID: 24243705
Also sorry forget to ask , is there abook or website that can help me with this pls that would be great , I got some note but hard to understand sometime.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24243820
>> but I will never give up to understanding it

That's good :)


>> so if I ask where is the first instruction starting who initiate it first ?what your answer will be

The operating system that runs on the computer takes care of starting and managing processes. A process has an entry point, so when the operating system starts a process, it starts execution at that entry point (main for example). From then on, the instructions that are called depend on the flow of control  (comparisons, sumps, loops, etc.).


In the case of the code you posted, I can't tell you who will call it - it's just a piece of code that could be called when needed.
0
 

Author Comment

by:hnael
ID: 24243916
ahh ok ,I am begining to understand it more and more now thank you , you r beeing very helpful , but I  am not going to leave alone haaa because I am going to bombard you with questions if thats okay with you , I am more intrested in understanding to be honest nothing more . so will keep in touch if any issue arise and sure you deserve all the pointa no doubt about that , I am just leaving the question open so that I can save it to my knowledge base also I want to answer this question (my self ) but need some help to check if I am on the right track.cheers mate you r being great help .
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24244097
No problem. Take your time.
0
 

Author Comment

by:hnael
ID: 24257884
Hello there , its me again with answers so pls let e know what you think ?
(a). the register rB is used as loop counter .
(b).the loop will be executed 64 time in hex whihc is 100 in denary .
(c) still can not figure it out .
(d). add immediate r1 0000 is used to test whats in r1 weather its -ve , +ve or zero .
(e). the subroutine is a peice of code (program) withen a main program that needs to be executed n numbers of time .
thats what I could come up with but could not find the gihest and lowest value in this program so pls I appreciate any help .thks in advance
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24258190
>>(a). the register rB is used as loop counter .

Correct.


>> (b).the loop will be executed 64 time in hex whihc is 100 in denary .

I assume that denary is the same as decimal (ie. base 10) ? If so, then that looks ok.


>> (c) still can not figure it out .

I'll give you a hint : 0500, which is loaded into rE at the start, is a memory address.


>> (d). add immediate r1 0000 is used to test whats in r1 weather its -ve , +ve or zero .

Indeed. We're not interested in the immediate impact (adding 0 doesn't change the value), but in the side effects of the instruction.


>> (e). the subroutine is a peice of code (program) withen a main program that needs to be executed n numbers of time .

You need to explain what it actually does ... For example "it sums an array of integers" or something like that (this is just an example, not actually what this code does).
0
 

Author Comment

by:hnael
ID: 24258298
right , regarding denary means decimal yes but we have been tought to use denary otherwise the computer geeks gets upset haaa...
so ,I presume that the adress 0500 is the lowest address in data memory and the higest is 0564 because this is the last value rE has got when rB got to 0000 in the simulater, is that correct ?
if yes I will be left only with what this subroutine does as u mentioned .....I followed the instruction step by step but all I can tel for now there is a loop going on for 100 times it increases rE by one , decrease the loop counter by one , it checkes whats in R1 (0,+.-) when rB reach the value zero it jumps and store 0600 in rA if value is not zero then it goes back fff7 which I think its -9 ,what do you think ?
0
 

Author Comment

by:hnael
ID: 24258333
pls if I did not reply quick for ur comments this is because I have dr.appointment in half an hour time , nothing serious just not feeling well ....but sure as soon as I get reply I will keep in touch so patience ..patience ..thank you very much ...what mechanism best to use to know what the program is doing ? I understand is to run it and see what i does but when I did that nothing much happened ,all I could see increase in rE , DECREASE IN rB , and zero flag  is ticked when it got to zero and it jump back fff7 so .....
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24258344
>> regarding denary means decimal yes but we have been tought to use denary otherwise the computer geeks gets upset haaa...

Heh. Well I've never heard of the term denary ;)


>> I presume that the adress 0500 is the lowest address in data memory and the higest is 0564 because this is the last value rE has got when rB got to 0000 in the simulater, is that correct ?

0500 is the lowest indeed. The load register-indirect instruction reads the value at the current memory address.

However, 0564 is not the highest ... In the last iteration of the loop, what will be the address ? In the first, it's 0500, in the second 0501, etc. And for the 100th iteration ?


>> all I can tel for now there is a loop going on for 100 times it increases rE by one , decrease the loop counter by one

Right.


>> it checkes whats in R1 (0,+.-)

And what's in r1 at that moment ?


>> when rB reach the value zero it jumps

Ok.


>> and store 0600 in rA

It's the other way around ... Think memory address again ;)


>> if value is not zero then it goes back fff7 which I think its -9 ,what do you think ?

Right. And to which instruction would that jump bring you ?
0
 

Author Comment

by:hnael
ID: 24258404
I see so the higest must be 0500 in hex +100 which is 0600 , regarding where it jump back I have to run it again and see to which instruction it goes back , no wonder people are scared to read assembly language because its such apain sorry .
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24258421
>> I see so the higest must be 0500 in hex +100 which is 0600

No. The loop only iterates 100 times (64 in hex), so in the last iteration, it will have incremented the address 0500 only 99 times ...
0
 

Author Comment

by:hnael
ID: 24259068
oh yeh , usually its n-1 where n is the no of addresses - 1 to get the total so it must be 0599 thank you ,you r brilliant , how u understand it so much , I envay you for that excellant ,can you give me more clue of what the subroutine does pls .
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24259095
>> so it must be 0599

Not quite. Remember that 0500 was in hexadecimal, and 99 in decimal ? You can't just add them like that ...
0
 

Author Comment

by:hnael
ID: 24259132
oh my God , i am so stupid it must be 0500 + 0063 that is 0563 it must be correct this time ?
pls tel me correct .
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24259161
>> is 0563 it must be correct this time ?

Yes :) 0563 is the memory address of the last processed item.


>> can you give me more clue of what the subroutine does pls .

Well, the load register-indirect instruction reads the item at the current memory address, and places it in r1.
What happens to r1 after that ?
0
 

Author Comment

by:hnael
ID: 24259278
the instruction says load register -indirect via rE r1 so my understanding is it copies the contents of the location in data memory that corrospond to rE and put it in r1 so the contnts of rE means the contents of 0500 address  (which I do not know) and copy it in r1 !!!! its a puzzle to me how will I know the contents or rE ?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24259303
>> the instruction says load register -indirect via rE r1 so my understanding is it copies the contents of the location in data memory that corrospond to rE and put it in r1 so the contnts of rE means the contents of 0500 address  (which I do not know) and copy it in r1 !!!!

That's what I said, yes ;)


>> its a puzzle to me how will I know the contents or rE ?

rE contains the memory addresses that start at 0500 and are incremented on each iteration, remember ?
The data at those memory addresses is irrelevant to understanding what happens in the code. Knowing that it takes an item from the given memory address, and places it in r1 is sufficient to continue.

So, now that r1 contains a value read from memory, what happens to r1 after that ?
0
 

Author Comment

by:hnael
ID: 24259340
what happen to r1 is the next instruction which is add immediate r1 0000 thats is add nothing to it (thats is what we said earliar to test the value or r1 )?
0
 

Author Comment

by:hnael
ID: 24259350
or maybe you mean r1 will have the contents of rE whihc is 0500 so that will be r1 = 0500
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24259374
>> what happen to r1 is the next instruction which is add immediate r1 0000 thats is add nothing to it (thats is what we said earliar to test the value or r1 )?

Go on ...
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24259382
>> or maybe you mean r1 will have the contents of rE whihc is 0500 so that will be r1 = 0500

No, r1 contains the value at address 0500 - it doesn't contain the address 0500 (in the first iteration of the loop).
0
 

Author Comment

by:hnael
ID: 24259452
so when add 0000 to r1 it does the test that is jump if negative relative 0001 so if the result in r1 negative then jump one step otherwise jump relative 0001 which means jump another time to get to the instruction subtract immediate rB 0001 (decrement the loop by one) once the loop reach to zero value that is rB =0000 JUMP ONCE  to get to the store direct rA 0600 (i.e copy the contents of rA the location with address 0600 otherwise go back fff7 .
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24259533
>> so if the result in r1 negative then jump one step

Where to ? Which instruction ?


>> otherwise jump relative 0001

Where to ? Which instruction ?
0
 

Author Comment

by:hnael
ID: 24265154
Hello again , ok if result is in r1 -ve then jump one instruction to add immediate rA 0001 otherwise  jump relative will get execute and jump one step to add immediate rE 0001 . I have to say I run the program 5 times and all its doing is incrementing rE by one every time and when loop get to zero it copy the content of rA into the location where the address is 0600 . so can I say the purpose is to incrementing rE by one .?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24265332
>> -ve then jump one instruction to add immediate rA 0001 otherwise  jump relative will get execute and jump one step to add immediate rE 0001 .

Right.


>> I have to say I run the program 5 times and all its doing is incrementing rE by one every time

It's doing something else too, isn't it ? You just mentioned it above ...


>> so can I say the purpose is to incrementing rE by one .?

No. Do you remember what rE holds ? What rE is used for ?
0
 

Author Comment

by:hnael
ID: 24267259
rE is holding the value 0500 and I think its used for the" sum for now"  right or wrong ?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24267682
>> rE is holding the value 0500 and I think its used for the" sum for now"  right or wrong ?

If you remember from previous discussion, rE holds a memory address. Incrementing it means that it now points to the next item.
0
 

Author Comment

by:hnael
ID: 24267941
so could I say the purpose of this subroutine is to show the next item or adding numbers ?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24267967
>> so could I say the purpose of this subroutine is to show the next item or adding numbers ?

It isn't "showing" anything.
It isn't adding any numbers (except for the increments).

So, no, that's not the purpose of the function ;)


Refer back to my earlier post http:#24265332, namely the second comment I made there ...
0
 

Author Comment

by:hnael
ID: 24268968
right I looked into it , I got a question that got a table with memory mapped addresses like say 0f05 it means a buzzer etc, but the addresses I got say 0500 is not any where in the table I got that indicate what it does .so any thought on that pls .
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24269044
>> but the addresses I got say 0500 is not any where in the table I got that indicate what it does .so any thought on that pls .

0500 is just a memory address ... It doesn't do anything special ... It's just a location in memory where some data can be found.
It doesn't matter which data either. All that matters is what the code does with that data ... We already figured out that there's a loop that loops over the first 100 items starting from that address. Now, what does it do with each of those 100 items ?
0
 

Author Comment

by:hnael
ID: 24270204
each time the loop occure it repeat it again and again till 100 times done ..........what else it can be , this is really crazy .
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24273220
>> each time the loop occure it repeat it again and again till 100 times done

It repeats what ?

Again, allow me to refer to my second comment in my earlier post http:#24265332. There is a decrement used for the loop counter, an increment used for going to the next item in memory, and one more increment. the latter one is the interesting one ... What does it do ?
0
 

Author Comment

by:hnael
ID: 24273240
if you look at the file i sent , the only thing happen there is under zero flag you got a tick , that s to say at this stage in the program result is zero ,just once you execuate the nest step the zero flag is empted , so the whole purpose to teat if the rE Iis zero or not -ve and if zero it keeps doing the loop till it become -ve then it jumps out side the loop ? what do u think ?
ee.JPG
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24273277
No, that's not what's happening. Focus on the 3 lines starting with the "jump if negative". If the value read from memory is negative, what happens ?
0
 

Author Comment

by:hnael
ID: 24273316
if te value read is -ve it jump one step and execute the instruction that is increase rA by one also increase rE by one and then subtract rB by one ......
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24273326
>> and execute the instruction that is increase rA by one

ok.

And if it's not negative ?
0
 

Author Comment

by:hnael
ID: 24273358
it will execute jump relative 0001 that is to jump one step and add rA BY one
0
 

Author Comment

by:hnael
ID: 24273368
sorry I meant rE by one not rA
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24273378
>> it will execute jump relative 0001 that is to jump one step and add rA BY one

Are you sure ? Where does the jump relative jump to ?
Or put differently : if it just goes to the next instruction, what's the point of the jump ?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24273384
>> sorry I meant rE by one not rA

Ah, ok.

So, there's different behavior when the value is negative, than when it's positive. So, can you explain what the function does now ?
0
 

Author Comment

by:hnael
ID: 24273460
well , I can try , testing the value weather its +ve , -ve or zero? I hope this correct my brain is dead from it , I spnt so much time on it .
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24273469
Ok, different approach : what will rA contain at the end of the loop ?
0
 

Author Comment

by:hnael
ID: 24273505
rA did not change it staed zero !!
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24273519
>> rA did not change it staed zero !!

Just look at the code ... Ignore your tool.

What will rA contain ?

I'm not looking for a specific value - just a description of the value.
0
 

Author Comment

by:hnael
ID: 24273571
rA will contain the final value . right when loop is finished
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 2000 total points
ID: 24273592
>> rA will contain the final value . right when loop is finished

Come on, just think about it. It's right in front of you ... if the value read from memory is negative, rA is incremented, if it's not, then it's not incremented ... So, what will rA contain in the end ?

I can't give you any better hints than that ... Just think about it.
0
 

Author Comment

by:hnael
ID: 24273624
okay mate , thank you very much I will accept the answer because you really done great job .pls I may trouble you with more questions ,not assighment haaa ,have a great evening , I am closing it ,I am off for a coffee it might open my mind for an answer haa ,thks
0
 

Author Closing Comment

by:hnael
ID: 31574881
I have to say such a great help from infinity08
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24273709
So, did you find the solution ? Feel free to post your thoughts here ...
0
 

Author Comment

by:hnael
ID: 24274046
I would say the function of this loop is a decesion making about the value being +ve , -ve or zero
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24274055
There's not just one value. There are 100 values ...
0
 

Author Comment

by:hnael
ID: 24274080
you mean I should say values not value , but is it correct though ?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24274105
No. There is a loop that does something for each of those 100 values.

What does it do ? (we've already discussed that at length)
What will the value in rA be at the end ?
0
 

Author Comment

by:hnael
ID: 24280341
Hi, this is driving me mad. Is function turning something on and off?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24281127
No.

Maybe it might be useful to re-read this whole thread. It's full of very clear hints.

Ignore the application you use. Just look at the code. Make notes about what it does in pseudo code, so you can easily follow what's happening.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the below post we have mentioned the best hosting type for startups. Also, check out some of the superlative web hosting companies that are proposing affordable web hosting solutions to host your startup website.
Last month Marc Laliberte, WatchGuard’s Senior Threat Analyst, contributed reviewed the three major email authentication anti-phishing technology standards: SPF, DKIM, and DMARC. Learn more in part 2 of the series originally posted in Cyber Defense …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question