Number switching (very simple inline ASM)

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Tvspelsfreak
Chaos Rift Junior
Chaos Rift Junior
Posts: 272
Joined: Wed Sep 29, 2004 5:53 pm
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: C/C++
Location: Umeå, Sweden
Contact:

Number switching (very simple inline ASM)

Post by Tvspelsfreak »

As requested by GV, I'll post a very simple ASM example of switching 2 numbers.

Code: Select all

#include <stdio.h>

void main(){
    int a = 10;
    int b = 20;

    printf("Before:\t%d,%d\n",a,b);

    __asm{
        mov eax,a
        mov ebx,b
        mov a,ebx
        mov b,eax
    }

    printf("After:\t%d,%d\n",a,b);
}
Last edited by Tvspelsfreak on Tue Jan 25, 2005 7:56 pm, edited 1 time in total.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

Btw, it's moving a to register eax and b to register ebx. Then it's putting what's in ebx in a and what's in eax in b.

Thanks for explaining that Tvspelsfreak. XD
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Yeah I diddle daddled in ASM in my time. But it was for TI 83 plus. Hmm. It looks easy to incorparate. Maybe I can use it to speed up some repetive code! An asm particle engine would be friggen sweet.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

Dear god, I pray that you aren't talking about for Dreamcast.

You do realize that x86 ASM is NOT going to work on DC. ASM is not portable so whatever platform you code that particle engine for will stay on that platform.

It's SH4 asm for the DC.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

NAH DUH Gyrovobis! I'm sad you would think that I am that nieve.
Last edited by JS Lemming on Wed Jan 26, 2005 8:16 am, edited 1 time in total.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

I was just making sure.

Maybe you are naive!

:guffaw:
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

No i think YOU are the nuaieve one. :lol:
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Post Reply