Stack and code on 8086

Hi

Assume:

- return address on the stack is one 16 bit word value;

- the numbers are all in decimal (small 8086 model)

- instruction pointer register, IP, currently equals 4000

- Stack pointer register, SP, currently equals 2004

Below is the code ad assembly. What would be the values after execution ax=?, bx=?, bp=?, ip=?, sp=?

Stack_Address Value at this stack location

2012 0100 2010 0200 2008 0300 2006 0400 2004 0500 2002 0600 2000 0700

The following code is to be executed from the current IP up to and including the ret instruction. Note: for simplicity we assume that each instruction takes 2 bytes, which is not necessarily the case for the

8086.

Code Address Instruction

3096 mov ax, 1 3098 pop ax 4000 pop bx 4002 pop bp 4004 ret
Reply to
2005
Loading thread data ...

On 26 Nov 2006 20:51:11 -0800, "2005" wrote in comp.arch.embedded:

What possible justification do you think there is for posting this to comp.dsp, since the 8086 is NOT a DSP and the code does no digital signal processing?

In fact, it is not really relevant to comp.arch.embedded, either. There is nothing particularly "embedded" about it.

If you had to post this (a homework assignment?) to a newsgroup at all, the moderated group news:comp.lang.asm.x86 would be appropriate.

But how lame can you be? If you translate the values from decimal to hex (and the Windows calculator applet can do that), you can enter them into the Windows debug program and actually single step the code to see exactly what is in the registers at the end.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
Reply to
Jack Klein

It may be a generational thing. I had desktop systems with 8080 or 6502. Now a dedicated embedded system may have a 80386 or higher processor. And DSP chips are "known" to be trivial small dedicated thingys ;>

Reply to
Richard Owlett

I agree with the previous posters. This should not be posted in the DSP newsgroup or even the embedded newsgroup. There are other groups more suited to this, search.

This is a fairly simple sequence. In any case you know your IP = 4000 and you SP = 2004. You also have your instructions and the contents of the stack Now the trick here to remember is that on the 8086 there is a decrement before a PUSH and an increment after POP. Most microprocessors do the exact same when it comes to manipulating stacks. The only processor I have come across that doesn't is the HC11 (and possibly the others in the series, but never coded those in assembly).

Since you say the IP is at 4000, the above 2 instructions are obviously not executed.

This instruction reads the 16-bit value at SP (which is 2004) in this case and transfers it to BX. After that, it adds 2 to the SP (it becomes 2006). After this instruction BX = 0500

This instruction does the same as above, but takes the value at 2006 and places it in BP. SP then becomes 2008. BP = 0400

Now the operation of this instruction is different depending on the memory model. Since you have already stated that the program is in small memory model. I will assume that the RET is a NEAR return (in that the stack segment register isnt popped, just the IP). So after this near return (a return that does not change the SS register).

IP = 0300 SP = 2010

So after all this is done, simply compile the results.

AX = ???? BX = 0500 BP = 0400 IP = 0300 SP = 2010

-Isaac

Reply to
Isaac Bosompem

...

...

We try not to do homework for those who haven't at least tried to do it themselves. 2005 (a distant relative of 7of9?) hasn't a clue how to start. just giving him answers won't help.

jerry

--
Engineering is the art of making what you want from things you can get.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Reply to
Jerry Avins

On Mon, 27 Nov 2006 12:28:08 -0600, Richard Owlett wrote in comp.arch.embedded:

Did you look at the code he posted?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
Reply to
Jack Klein

The statement "in decimal" should have been warning enough.. LOL

Reply to
thedoc

I never stop finding it hilarious how people carefully point out that it was wrong to post such question in here, yet they continue to give a detailed answer.

Even worse in this case, a question so absurd that it can not be more obvious that it is homework --- but you go ahead and spell out all the details of his homework, so that he doesn't even have to bother to try to understand; just take what you wrote and submit it as his solution, for full marks...

Nice!!!

Carlos

--

Reply to
Carlos Moreno

...

So, he got this homework done by someone else, will get a degree with fuckall knowledge, and will be designing your mad house heater. Rejoice, though, it could yet be your car's steering and brakes.

Reply to
Judges 13:18

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.