ホームに戻る
 データを渡す

;
;   アセンブラ
;

segment .code USE32

a:
  db      0x01, 0x23
  dw      0x4567
  dd      0x89abcdef

global _mmx

_mmx:
  push    ebp
  mov     ebp, esp
  mov     edx, [ebp+8]

  movq    mm0, [a]
  movq    [edx], mm0

  emms

  leave
  ret 
__end__mmx


/*
*   C言語
*/

#include <stdio.h>

extern void mmx(char *p);

int main()
{
  unsigned char p[8] = {0, 0, 0, 0, 0, 0, 0, 0};

  mmx(p);

  printf("%02x\n", p[0]);
  printf("%x\n", p[1]);
  printf("%x\n", *(short *)&p[2]);
  printf("%x\n", *(int *)&p[4]);

  return 0;
}


このプログラムについて

ポインタを渡して値を埋める。
データの移動に movq を用いている。

実行結果

01
23
4567
89abcdef

1バイト値、2バイト値、4バイト値をそれぞれ拾っている。
アクセス幅を変えていないので結果がエンディアンの影響を受けない。

inserted by FC2 system