Autor Beitrag
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Di 18.03.08 18:48 
Ich habe ein Programm, dessen ASM code ich mir angeguckt habe
ich will eine Struktur daraus in einem anderen Programm anzeigen

gibts es für folgenden code eine andere Delphi entsprechung?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
      feld:=Byte(tmp) and $7F;
...
      asm
        MOV EAX,tmp
        SAR EAX,7
        MOV feld,EAX
      end;
      feld:=feld and $7F;
Sirke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 208
Erhaltene Danke: 2



BeitragVerfasst: Di 18.03.08 23:07 
Ich würde das ganze so schreiben:
ausblenden Delphi-Quelltext
1:
feld := (tmp div 128and $7F;					
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Di 18.03.08 23:17 
Da Byte ohnehin vorzeichenlos ist, könnte man dann nicht einfach feld := (tmp shr 7and $7F schreiben? Oder übersehe ich etwas?

AXMD
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 19.03.08 00:36 
Ich vermute ja... 10 Sekunden Google: "SAR is similar to SHR, but SAR preserves the most significant bit."
Also entweder so lassen, oder noch ein wenig rum-ODERn...

Wobei ich auch keine wirkliche Ahnung von ASM auf x86 habe...

EDIT: den gegoogleten Artikel gelesen, jetzt weiß ich, dass user profile iconSirke Recht hatte... Es ist wirklich einfach DIV, das MSB wird da gehalten, damit das Vorzeichen nicht kaputt geht.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mi 19.03.08 00:43 
Fragt sich nur, warum das MSB erhalten werden soll, wenn es in der letzten Zeile durch die $7F-Maske ohnehin auf 0 gesetzt wird :?

AXMD
Sirke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 208
Erhaltene Danke: 2



BeitragVerfasst: Mi 19.03.08 09:42 
Wenn tmp vom Typ Byte ist und dadurch das 8. Bit das MSB ist, dann kommt noch dazu, dass durch das Verschieben um 7 Bits die ersten 7 Bits "0" werden. Folglich sollte nach dem Maskieren immer $00 herauskommen!
ausblenden Quelltext
1:
2:
3:
4:
5:
tmp = 11111111
SAR 7 10000000  // Die 7 "1" fallen ja weg und werden durch "0" ersetzt!
AND   01111111
      --------
      00000000

Oder irre ich mich ... :?
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Mi 19.03.08 10:25 
Hallo,

falscher Fehler ;-)
Du schiebst links SHL oder SAL sind da gleich.
Hier wird aber nach rechts geschoben
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
tmp = 10000000
SAR 7 11111111  // Alles wird zu eins
AND   01111111 
      -------- 
      01111111

Wenn byte(tmp) >127 dann ist das Ergebnis anschließend 127, sonst 0.

Gruß Horst
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mi 19.03.08 12:28 
moment
tmp und feld sind beide Cardinals (also 4Byte)
Das erste ist der erste Teil
ausblenden Delphi-Quelltext
1:
feld:=Byte(tmp) and $7F					

Gibts es dafür eine entsprechung? den ich glaube nicht, dass jmd tatsächlich mit nem AND befehl gecodet hat...

Das 2. Ist davon unabhängig
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
 asm
        MOV EAX,tmp
        SAR EAX,7
        MOV feld,EAX
      end;
      feld:=feld and $7F;

hier werden die kompletten 4Byte verwendet
Auch hier glaube ich nicht, dass das jmd so gemacht hat
feld ist am ende ein index in nem 0-basierten array bis (glaube) 65 (+-2)

der erste befehl gibt mir den ersten index, der 2. befehl den 2. index zurück

hoffe das hilft
Sirke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 208
Erhaltene Danke: 2



BeitragVerfasst: Mi 19.03.08 12:40 
user profile iconFlamefire hat folgendes geschrieben:
hier werden die kompletten 4Byte verwendet
Auch hier glaube ich nicht, dass das jmd so gemacht hat
feld ist am ende ein index in nem 0-basierten array bis (glaube) 65 (+-2)
Wenn du gesagt hättest, ein 0-basierten Array bis 127, dann wäre es klar ;-)

So wie ich das sehe stehen in der Variable tmp in den ersten beiden Bytes die Informationen. In den ersten 7 Bit die ersten Informationen und in den zweiten 7 Bit, also die Bits 8 bis 14, die zweiten!

Folglich kann man das so schreiben:
ausblenden Delphi-Quelltext
1:
2:
index1 := tmp and $7F// Abfrage der ersten 7 Bit
index2 := (tmp shr 7and $7F// Abfrage der zweiten 7 Bit


So würde ich das kürzen, bin mir aber nicht sicher ob ich da richtig liege! ;-)
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mi 19.03.08 13:12 
hm...aber i-wie kanns das nicht sein
wer würde sowas programmieren?
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Mi 19.03.08 13:34 
Hallo,

da wollte einer kryptisch sein.
Bei 6 Bit breiten Indizes hätte man ja 5 in 32 Bit unterbringen können , aber so?

Gruß