flat assembler
Message board for the users of flat assembler.

 Index > Main > Converting code from C: "omg i need more registers!&quo
Author
Teehee

Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 26 Feb 2011, 18:17
when im trying to convert a code, or implement a big routine i always get confused when there is no more registers to use. Using push/pop make the code to seem so slow (hehe). What do you do to solve this issue?

THe code i'm trying to convert is:

Code:
```void line_fast(int x1, int y1, int x2, int y2, byte color)
{
int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py;

dx=x2-x1;      /* the horizontal distance of the line */
dy=y2-y1;      /* the vertical distance of the line */
dxabs=abs(dx);
dyabs=abs(dy);
sdx=sgn(dx);
sdy=sgn(dy);
x=dyabs>>1;
y=dxabs>>1;
px=x1;
py=y1;

VGA[(py<<8)+(py<<6)+px]=color;

if (dxabs>=dyabs) /* the line is more horizontal than vertical */
{
for(i=0;i<dxabs;i++)
{
y+=dyabs;
if (y>=dxabs)
{
y-=dxabs;
py+=sdy;
}
px+=sdx;
plot_pixel(px,py,color);
}
}
else /* the line is more vertical than horizontal */
{
for(i=0;i<dyabs;i++)
{
x+=dxabs;
if (x>=dyabs)
{
x-=dyabs;
px+=sdx;
}
py+=sdy;
plot_pixel(px,py,color);
}
}
}    ```

ref

_________________
26 Feb 2011, 18:17
b1528932

Joined: 21 May 2010
Posts: 287
b1528932 26 Feb 2011, 18:26
Create swap space as local variable for each variable you gona swap.
Use normal registers, if you need to nest something else, write register to swap and load it witrh new value.

Its the most efficient and readable way. Use virtual keyword so you wont have to remember all bp + XX.
26 Feb 2011, 18:26
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum