NO

Author Topic: using DB,Dw,... in asm block  (Read 3953 times)

Emil Halim

  • Guest
using DB,Dw,... in asm block
« on: October 22, 2004, 08:31:39 AM »
hi Pelles

can you post an example that show us hwo can we use DB,DW,DD in
asm block.

and hwo can we access it form c part.

thanks

Emil

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
using DB,Dw,... in asm block
« Reply #1 on: October 22, 2004, 12:44:05 PM »
Hello Emil,

Maybe not exactly what you are looking for, but this is one way of doing it. DB, DW, DD all emit data to the code section, so you should either put it after a ret (probably best), or use jmp xxx, to jump around the data.

Code: [Select]

__declspec(naked) unsigned long * test(int idx)
{
    __asm {
        mov eax,[esp+4]     ; idx (0-7)
        add eax,eax            ; *2
        add eax,eax            ; *4
        add eax,offset label
        ret

        align 4
label:  dd  1,2,3,4,5,6,7,8
    }
}


It's easiest to access the data from the assembly code. If you want to access data from C, I don't see that much benefits with DB, DW, DD. Might as well do something like this:

static unsigned int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8 };

( If you really need the data in the code section, you can use #pragma data_seg() )

Pelle
/Pelle

Anonymous

  • Guest
using DB,Dw,... in asm block
« Reply #2 on: October 22, 2004, 01:22:26 PM »
thanks Pelles.

this will help a lot.

Emil