Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

C arrays in inline asm....

MainForzeMainForze Member Posts: 36
Hi there,

I'm trying to write a ScrollUp() function in C using inline ASM. It's supposed to get the values of A000:0000 through A000:013F (thats 319, by the way) in to an array, so that it can put those values back at the bottom of the screen. I'd like it to go something like this:

void ScrollUp()
{
unsigned char ScanLine[320];

asm{
xor bx, bx
mov ax, 0xA000
mov es, ax
Loop1:
mov al, es:[bx]
mov ScanLine[bx], al
inc bx
cmp bx, 320
jne Loop1

.
. // Scroll Up code goes here
.
.
.
.
. // Put-ScanLine[]-at-bottom-of-screen code here :)
}
}

BUT..... It's not possible to reference a C array in asm this way.... So how so I do it then?????

any help would be appreciated...!

Thanks in advance,

MainForze


Comments

  • asekeraseker Member Posts: 8
    void ScrollUp()
    {
    unsigned char ScanLine[320];

    asm{
    xor bx, bx
    mov ax, 0xA000
    mov es, ax
    }
    Loop1: // Asm satırı dışında adres tanımlanır.
    asm mov al, es:[bx]

    ScanLine[_BX] = _AL; // C++'nin gzelliği...

    asm {
    inc bx
    cmp bx, 320
    jne Loop1

    .
    . // Scroll Up code goes here
    .
    .
    .
    .
    . // Put-ScanLine[]-at-bottom-of-screen code here :)
    }
    }



  • AsmGuru62AsmGuru62 Member Posts: 6,519
    I am not familiar with that, but maybe this helps:

    void func()
    {
    char strArray [128];
    char* pstr = strArray;

    _asm les di, pstr // now ES:DI points to 'strArray'
    }

    Worked for me always in DOS apps...
    Hope it helps...

    Cheers!



  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : I am not familiar with that, but maybe this helps:
    :
    : void func()
    : {
    : char strArray [128];
    : char* pstr = strArray;
    :
    : _asm les di, pstr // now ES:DI points to 'strArray'
    : }
    :
    : Worked for me always in DOS apps...
    : Hope it helps...
    :
    : Cheers!
    :
    :
    :

    ARGH!!!!!!
    Forgot to point out: if you use DS anywhere do not forget to PUSH/POP it:

    _asm push ds
    _asm lds si, pstr // DS:SI points to your array now
    // do your job here, but do not access static or global vars!_asm ...
    _asm pop ds



  • MainForzeMainForze Member Posts: 36
    Thank you guys!!! You really helped me out here!!!!!

    MainForze

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : Thank you guys!!! You really helped me out here!!!!!
    :
    : MainForze
    :

    It is all good, but I forget to add that this works for C memory model where the pointer is represented by DWORD (full segment:offset value). It will not work for SMALL and TINY models for example.


Sign In or Register to comment.