extra register for pop?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

extra register for pop?

swupiox
I finished chapter 7 and all tests pass, but it is bugging me that I had to use a temp register for pop to store the address of base+offset.  Is that expected or is there some clever way to only use A and D that I have missed?  In the VME the temp registers don't seem to be affected by pop.

One thing I considered was writing A=A+1 each time for the number of offsets from base, but although it would work I don't think it is a good way to do it.  I am not asking for the solution (if there is one) but just a hint.  Thanks.

Reply | Threaded
Open this post in threaded view
|

Re: extra register for pop?

cadet1620
Administrator
swupiox wrote
I finished chapter 7 and all tests pass, but it is bugging me that I had to use a temp register for pop to store the address of base+offset.  Is that expected or is there some clever way to only use A and D that I have missed?  In the VME the temp registers don't seem to be affected by pop.

One thing I considered was writing A=A+1 each time for the number of offsets from base, but although it would work I don't think it is a good way to do it.  I am not asking for the solution (if there is one) but just a hint.  Thanks.
My generic "pop pointer N" uses a temp register.  It's 12 instructions long.  My code generator writes shorter code for N=0 and 1, but I didn't bother to write specific code for N>1 cases that would be shorted than 12 instructions.  A quick search through the OS .vm files showed that optimizing N=0,1 would have a good return.

Here are the counts for my game with my OS.
pop.argument.0   9
pop.argument.1   8
pop.argument.2   1
pop.argument.3   1
pop.local.0   57
pop.local.1   37
pop.local.10   2
pop.local.2   26
pop.local.3   20
pop.local.4   12
pop.local.5   5
pop.local.6   3
pop.local.7   5
pop.local.8   5
pop.local.9   2
pop.temp.0   283
pop.that.0   45
pop.this.0   9
pop.this.1   9
pop.this.2   14
pop.this.3   7
pop.this.4   1
pop.this.5   2
Looks like it might be worth looking at the A=A+1 optimization for N>1 cases...

--Mark