Autor Beitrag
Jacko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Mo 15.08.05 16:23 
Hallo,
ich bekomme in mein Programm SmallInt-Werte aus einer anderen Applikation. Leider sind das Obere und Untere Byte vertauscht.
Wie tausche ich diese Bytes :?:

Danke im Voraus.
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mo 15.08.05 16:30 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function xchangeBytesSmallint(x:smallint):smallint;
asm
   mov cl, al
   mov al, ah
   mov ah, cl
end;

procedure TForm1.Button4Click(Sender: TObject);
var i: smallint;
begin
   i:=$7700;
   i:=xchangeBytesSmallint(i);
   showmessage(inttostr(i));
end;

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
Allesquarks
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 510

Win XP Prof
Delphi 7 E
BeitragVerfasst: Mo 15.08.05 16:30 
Könntest die Zahl um acht Bit links oder rechts schieben (natürlich nur wenn sie unsigned ist)
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Mo 15.08.05 16:33 
user profile iconJacko hat folgendes geschrieben:
Hallo,
ich bekomme in mein Programm SmallInt-Werte aus einer anderen Applikation. Leider sind das Obere und Untere Byte vertauscht.
Wie tausche ich diese Bytes :?:

Danke im Voraus.


Die Windows-Funktion ntohs in der Unit WinSock macht das.

Stefan
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Mo 15.08.05 16:37 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
function change(bla: smallint): smallint;
asm
  ror ax, 8
end;

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
Jacko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Mo 15.08.05 17:11 
uall@ogc hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
function change(bla: smallint): smallint;  
asm  
  ror ax, 8  
end;


Bei diesem Beispiel gibt er mir 28724 raus, wenn ich 0(=bla) übergebe ???
warum ?

Moderiert von user profile iconraziel: Quote- und Delphi-Tags hinzugefügt.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Mo 15.08.05 17:15 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
function change(zahl: smallint): smallint;
asm
  ror ax, 8
end;

procedure TForm1.FormCreate(Sender: TObject);
var bla: smallint;
begin
  bla := 0;
  bla := change(bla);
  form1.caption := inttostr(bla);
end;


liefert bei mir einwandfreie ergebnisse oO

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
Jacko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Di 16.08.05 12:29 
Danke,
musste die Funktion ein wenig umstellen, da das Register 'D' und nicht 'A' die werte übernommen hat. 'A' gibt sie wieder zurück. (wieso? keine Ahnung).

function TFormMain.change(zahl: smallint): smallint;
asm
ror dx, 8
mov ax,dx
end;