Attached Files:

The general idea of homework questions is that you do them yourself. Failure to do them correctly is a good indicator to your teacher that you're struggling so we do you no good by answering them for you - you hand in correct answers, he thinks "good he's got the hang of this", but in reality you haven't and by answering your questions we only succeed in creating a dependency cycle where rather than you figuring stuff out, you just post your questions here for others to answer for you.

Which is fine if you get answers, but on the day of the exam where you have no access to go4e, you're stuck because you haven't answered questions yourself before, and you fail.

However I don't think it's a problem to give you some hints, so here goes:

1. You got that correct, good. Did you work it out yourself or get the answer from someone? You only fool yourself when you cheat, because the point of these exercises is not just to give you a hard time but actually to teach you stuff. Do you think that if the best way to teach programming were "here look at this complete code sample", "here now look at this complete code sample", your teacher wouldn't already be doing it this way?

2. I believe the x86 has some "repeat" instructions that perform loop operations without you having to code up a loop. Dig through your course notes and see what you can find.

3. OK so you have 3 variables in (this is important) FOUR CONSECUTIVE BYTES. Is there something about the phrase FOUR CONSECUTIVE BYTES that suggests a possible way ahead for this? Look carefully at the "assume" bit in brackets; ask yourself the question "does this give you the answer".

4a. Well, what do you think the result is? There's no point any of us just telling you outright. Have a go and explain how you got the value you got, and it is the working that is important here because we can work out if your TECHNIQUE is correct, so for example there's no point just posting, say, "27" because if that's the wrong answer we don't know how you arrived at that.

If you have no idea how, just take the instructions one at a time. What does MOV AX,0 do (bearing in mind the stated assumption)? Next: what does ADD AX, BX do and what is the result of that? One the basis of that result, what then would ADC DX,0 do? And so on. This is called "dry running" the code and is a useful programming skill; you NEED to get this sorted out. Really you do. I've been programming since 1981 and I still dry run code in my head.

4b. Having worked out the result, now have a go at solving the problem yourself. If you get stuck, post the code and we can suggest what to do next.

2. I believe the x86 has some "repeat" instructions that perform loop operations without you having to code up a loop. Dig through your course notes and see what you can find.

3. OK so you have 3 variables in (this is important) FOUR CONSECUTIVE BYTES. Is there something about the phrase FOUR CONSECUTIVE BYTES that suggests a possible way ahead for this? Look carefully at the "assume" bit in brackets; ask yourself the question "does this give you the answer".

Click to expand...

first i'm sorry you have got the wrong impression from my post. I should have attached my dead-end draft. the thing is that i wrote it not in english and i was too lazy to translate it.

i have translated it shortly, just to show that i did try by myself and got stucked

OK, there are 2 question 2's - that's confusing.
Taking the second 2, plus 3,4 in the PDF as 3,4,5 this makes more sense...

Q4:
Yep, you could use three instructions, but the question asks for the shortest possible way.
I dropped a major hint twice, see if you can spot it.

FOUR CONSECUTIVE BYTES
FOUR CONSECUTIVE BYTES
FOUR CONSECUTIVE BYTES
FOUR CONSECUTIVE BYTES
FOUR CONSECUTIVE BYTES
FOUR CONSECUTIVE BYTES
FOUR CONSECUTIVE BYTES
FOUR CONSECUTIVE BYTES
FOUR CONSECUTIVE BYTES
FOUR CONSECUTIVE BYTES

Dropped it 10 more times for you just in case you couldn't find it.

I wonder if there are any 4 byte instructions.
I wonder if we can somehow combine -2 in one byte, +1 in 2 bytes and 5 in one byte into a single four-byte constant, cos if we can, and if there are 4-byte instructions, then maybe we can solve this with a single instruction.
I wonder if the "assume" bit in brackets has anything* to do with a possible answer.
* maybe this is the answer handed to you on a silver platter.

5.1

Adds cx-1 times the carry from bx*2
Adds the previous carry bit to DX cx times (doest change during calculation)

Some notes:
*1 Look this up in the documentation. What would happen if AX+BX>65535? Whatever the outcome, are you certain this doesn't affect the carry bit at all (as per your comment "Adds the previous carry bit ... (doesn't change during calculation)")?
*2 Also look this up in the documentation. What's the difference between ADD and ADC? If AX+BX<65536, what would the ADC instruction do? If AX+BX>65535, would the ADC instruction do anything different? I haven't put values under AX~DX for this instruction, deliberately, because you need to lookup ADC in TFM.

Once you've done that, do it again with a big starting value for BX - say 50,000. Use a calculator to keep track of BX.

Note: with experience you'll be able to dry run stuff in your head. Dry running on paper first is an essential first step, only when you've done that a few times will you be able to do it mentally, just like maths, there was a time you could only do moderately complicated maths on paper, e.g. 62*120, but I bet you could do that in your head now.

5.2. It's very interesting that the DX register was chosen. I wonder if there's a single instruction that does what the previous code chunk does? (That's why you have to get what it does correct). Perhaps the choice of the DX register is a clue. But if I tell you where to look in the docs then I give away what the first part does, and you need to work that out.

I can't ask you for more guidance but if you are able to give a hand. i'll be more that happy to receive it.

I attached
1. the original assignment, because last time the number got mixed up. now i will be sure which question your referring to.
2. my draft of answers (not asking anyone to look at it, just to show i'm trying myself)
3. an answer to your last post.

> I thought about that too. I believe you refer to reserved-word "times". That problem is that it loops only one line, and I can't make a proper instruction in one line only. Or am I missing something here?

Yes you are. Try searching the documentation link I gave you for the word "repeat". What do you find at the FIRST match?

> Q3 in PDF. For that I really don't have a clue. I have tried some things but there possible only if I assume EAX is initialized 0.any more ideas?

What you need to do here is look through each instruction in the documentation and find five that are guaranteed to leave 1 in AX. MOV AX,1 is the obvious starting point; now find four more!

> thanks. Solving that have raised up some technical questions. When I'm adding a number to a data in some memory say in address 100, will the addition direction be to the right or to the lest (meaning the adding the MSB I summed with data in memory 100,next is summed with data in memory 101… or LSB with 100, next bit with data in address 99…)

That's a very good question. What you need to do is read the documentation carefully, and/or try it out on an x86 machine. There are loads of emulators available if you haven't got an actual machine handy. But you have the right approach, and now you just need to work out whether the address to point the instruction at is 100 or 103.

> I don't get it.

For the THIRD time -- listen very carefully because I'm only going to say this once more and after that you're on your own:

TRY DRY RUNNING THE CODE.

I got you started. Now do it. Even if just to humour me, you never know, you might just be surprised at what you find.

> 5.2

We need to come back to this AFTER you have dry run the code in 5.1. Once you know what 5.1 does, you can then look for an instruction that does the same.